Skip to content

Commit

Permalink
only remove valid sourcemapping URL comments (fixes #1132)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Dec 21, 2016
1 parent b3b1098 commit ccc7ad7
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand Down
2 changes: 1 addition & 1 deletion src/Module.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
3 changes: 3 additions & 0 deletions test/function/sourcemapping-url-comment/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
description: 'only removes valid sourcemapping URL comments (#1132)'
};
3 changes: 3 additions & 0 deletions test/function/sourcemapping-url-comment/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
////# sourceMappingURL=foo
var val = 42;
assert.equal( val, 42 );

0 comments on commit ccc7ad7

Please sign in to comment.