@@ -740,4 +740,46 @@ describe('stripSourceMappingURLComments', () => {
740740 expect ( content ) . not . toContain ( 'sourceMappingURL' ) ;
741741 }
742742 } ) ;
743+
744+ it ( 'does not modify minified files with a sourceMappingURL marker inside a string literal' , async ( ) => {
745+ const filePath = path . join ( tmpDir , 'chunks' , 'minified.js' ) ;
746+ const originalContent = `const worker = 'self.onmessage = () => {};\\n//# sourceMappingURL=worker.js.map\\n'; use(worker);` ;
747+ await fs . promises . writeFile ( filePath , originalContent ) ;
748+
749+ await stripSourceMappingURLComments ( tmpDir ) ;
750+
751+ const content = await fs . promises . readFile ( filePath , 'utf-8' ) ;
752+ expect ( content ) . toBe ( originalContent ) ;
753+ } ) ;
754+
755+ it ( 'does not modify files ending with a template literal containing a sourceMappingURL marker' , async ( ) => {
756+ const filePath = path . join ( tmpDir , 'chunks' , 'template.js' ) ;
757+ const originalContent = 'const s = `line1\n//# sourceMappingURL=worker.js.map`;' ;
758+ await fs . promises . writeFile ( filePath , originalContent ) ;
759+
760+ await stripSourceMappingURLComments ( tmpDir ) ;
761+
762+ const content = await fs . promises . readFile ( filePath , 'utf-8' ) ;
763+ expect ( content ) . toBe ( originalContent ) ;
764+ } ) ;
765+
766+ it ( 'strips sourceMappingURL comment from files consisting only of the comment' , async ( ) => {
767+ const filePath = path . join ( tmpDir , 'chunks' , 'comment-only.js' ) ;
768+ await fs . promises . writeFile ( filePath , '//# sourceMappingURL=comment-only.js.map' ) ;
769+
770+ await stripSourceMappingURLComments ( tmpDir ) ;
771+
772+ const content = await fs . promises . readFile ( filePath , 'utf-8' ) ;
773+ expect ( content ) . toBe ( '' ) ;
774+ } ) ;
775+
776+ it ( 'strips sourceMappingURL comment with a data: URI' , async ( ) => {
777+ const filePath = path . join ( tmpDir , 'chunks' , 'inline.js' ) ;
778+ await fs . promises . writeFile ( filePath , 'var a = 1;\n//# sourceMappingURL=data:application/json;base64,eyJ2IjozfQ==' ) ;
779+
780+ await stripSourceMappingURLComments ( tmpDir ) ;
781+
782+ const content = await fs . promises . readFile ( filePath , 'utf-8' ) ;
783+ expect ( content ) . toBe ( 'var a = 1;' ) ;
784+ } ) ;
743785} ) ;
0 commit comments