Browse Source

only remove valid sourcemapping URL comments (fixes #1132)

gh-1132
Rich-Harris 8 years ago
parent
commit
ccc7ad7352
  1. 2
      src/Bundle.js
  2. 2
      src/Module.js
  3. 3
      test/function/sourcemapping-url-comment/_config.js
  4. 3
      test/function/sourcemapping-url-comment/main.js

2
src/Bundle.js

@ -420,7 +420,7 @@ export default class Bundle {
const bundleSourcemapChain = [];
code = transformBundle( code, this.plugins, bundleSourcemapChain, options )
.replace( new RegExp( `\\/\\/#\\s+${SOURCEMAPPING_URL}=.+\\n?`, 'g' ), '' );
.replace( new RegExp( `^\\/\\/#\\s+${SOURCEMAPPING_URL}=.+\\n?`, 'gm' ), '' );
if ( options.sourceMap ) {
timeStart( 'sourceMap' );

2
src/Module.js

@ -72,7 +72,7 @@ export default class Module {
});
// remove existing sourceMappingURL comments
const pattern = new RegExp( `\\/\\/#\\s+${SOURCEMAPPING_URL}=.+\\n?`, 'g' );
const pattern = new RegExp( `^\\/\\/#\\s+${SOURCEMAPPING_URL}=.+\\n?`, 'gm' );
let match;
while ( match = pattern.exec( code ) ) {
this.magicString.remove( match.index, match.index + match[0].length );

3
test/function/sourcemapping-url-comment/_config.js

@ -0,0 +1,3 @@
module.exports = {
description: 'only removes valid sourcemapping URL comments (#1132)'
};

3
test/function/sourcemapping-url-comment/main.js

@ -0,0 +1,3 @@
////# sourceMappingURL=foo
var val = 42;
assert.equal( val, 42 );
Loading…
Cancel
Save