Browse Source

Merge pull request #1165 from rollup/gh-988

prevent false positives for sourcemapping url comments with newlines
gh-1008
Rich Harris 8 years ago
committed by GitHub
parent
commit
f2742e477c
  1. 2
      src/Bundle.js
  2. 2
      src/Module.js
  3. 3
      test/function/sourcemapping-url-multiline/_config.js
  4. 6
      test/function/sourcemapping-url-multiline/main.js

2
src/Bundle.js

@ -429,7 +429,7 @@ export default class Bundle {
const bundleSourcemapChain = []; const bundleSourcemapChain = [];
code = transformBundle( code, this.plugins, bundleSourcemapChain, options ) 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 ) { if ( options.sourceMap ) {
timeStart( 'sourceMap' ); timeStart( 'sourceMap' );

2
src/Module.js

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

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

@ -0,0 +1,3 @@
module.exports = {
description: 'does not mistakenly recognise sourceMappingURL comment with newline'
};

6
test/function/sourcemapping-url-multiline/main.js

@ -0,0 +1,6 @@
var sourceMappingURL;
//#
sourceMappingURL='something';
assert.equal( sourceMappingURL, 'something' );
Loading…
Cancel
Save