diff --git a/src/Bundle.js b/src/Bundle.js index c902b49..a2d11ee 100644 --- a/src/Bundle.js +++ b/src/Bundle.js @@ -429,7 +429,7 @@ export default class Bundle { const bundleSourcemapChain = []; code = transformBundle( code, this.plugins, bundleSourcemapChain, options ) - .replace( new RegExp( `^\\/\\/#\\s+${SOURCEMAPPING_URL}=.+\\n?`, 'gm' ), '' ); + .replace( new RegExp( `^\\/\\/# +${SOURCEMAPPING_URL}=.+\\n?`, 'gm' ), '' ); if ( options.sourceMap ) { timeStart( 'sourceMap' ); diff --git a/src/Module.js b/src/Module.js index 563d110..0ddde37 100644 --- a/src/Module.js +++ b/src/Module.js @@ -72,7 +72,7 @@ export default class Module { }); // remove existing sourceMappingURL comments - const pattern = new RegExp( `^\\/\\/#\\s+${SOURCEMAPPING_URL}=.+\\n?`, 'gm' ); + const pattern = new RegExp( `^\\/\\/# +${SOURCEMAPPING_URL}=.+\\n?`, 'gm' ); let match; while ( match = pattern.exec( code ) ) { this.magicString.remove( match.index, match.index + match[0].length ); diff --git a/test/function/sourcemapping-url-multiline/_config.js b/test/function/sourcemapping-url-multiline/_config.js new file mode 100644 index 0000000..466ea61 --- /dev/null +++ b/test/function/sourcemapping-url-multiline/_config.js @@ -0,0 +1,3 @@ +module.exports = { + description: 'does not mistakenly recognise sourceMappingURL comment with newline' +}; diff --git a/test/function/sourcemapping-url-multiline/main.js b/test/function/sourcemapping-url-multiline/main.js new file mode 100644 index 0000000..b9f63b2 --- /dev/null +++ b/test/function/sourcemapping-url-multiline/main.js @@ -0,0 +1,6 @@ +var sourceMappingURL; + +//# +sourceMappingURL='something'; + +assert.equal( sourceMappingURL, 'something' );