Browse Source

add back @btd fix for #1104

gh-786
Rich-Harris 8 years ago
parent
commit
a502f30365
  1. 4
      src/Bundle.js
  2. 13
      src/Module.js
  3. 2
      src/rollup.js
  4. 4
      src/utils/sourceMappingURL.js
  5. 4
      test/form/removes-existing-sourcemap-comments/_expected/amd.js
  6. 4
      test/form/removes-existing-sourcemap-comments/_expected/iife.js
  7. 4
      test/form/removes-existing-sourcemap-comments/_expected/umd.js

4
src/Bundle.js

@ -15,7 +15,6 @@ import { mapSequence } from './utils/promise.js';
import transform from './utils/transform.js';
import transformBundle from './utils/transformBundle.js';
import collapseSourcemaps from './utils/collapseSourcemaps.js';
import SOURCEMAPPING_URL from './utils/sourceMappingURL.js';
import callIfFunction from './utils/callIfFunction.js';
import { dirname, isRelative, isAbsolute, normalize, relative, resolve } from './utils/path.js';
import BundleScope from './ast/scopes/BundleScope.js';
@ -428,8 +427,7 @@ export default class Bundle {
let map = null;
const bundleSourcemapChain = [];
code = transformBundle( code, this.plugins, bundleSourcemapChain, options )
.replace( new RegExp( `^\\/\\/# +${SOURCEMAPPING_URL}=.+\\n?`, 'gm' ), '' );
code = transformBundle( code, this.plugins, bundleSourcemapChain, options );
if ( options.sourceMap ) {
timeStart( 'sourceMap' );

13
src/Module.js

@ -5,7 +5,7 @@ import { assign, blank, deepClone, keys } from './utils/object.js';
import { basename, extname } from './utils/path.js';
import getLocation from './utils/getLocation.js';
import makeLegalIdentifier from './utils/makeLegalIdentifier.js';
import SOURCEMAPPING_URL from './utils/sourceMappingURL.js';
import { SOURCEMAPPING_URL_RE } from './utils/sourceMappingURL.js';
import error from './utils/error.js';
import relativeId from './utils/relativeId.js';
import { SyntheticNamespaceDeclaration } from './Declaration.js';
@ -72,11 +72,14 @@ export default class Module {
});
// remove existing sourceMappingURL comments
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 );
this.comments = this.comments.filter(comment => {
//only one line comment can contain source maps
const isSourceMapComment = !comment.block && SOURCEMAPPING_URL_RE.test(comment.text);
if (isSourceMapComment) {
this.magicString.remove(comment.start, comment.end );
}
return !isSourceMapComment;
});
this.declarations = blank();
this.type = 'Module'; // TODO only necessary so that Scope knows this should be treated as a function scope... messy

2
src/rollup.js

@ -4,7 +4,7 @@ import { writeFile } from './utils/fs.js';
import { assign, keys } from './utils/object.js';
import { mapSequence } from './utils/promise.js';
import validateKeys from './utils/validateKeys.js';
import SOURCEMAPPING_URL from './utils/sourceMappingURL.js';
import { SOURCEMAPPING_URL } from './utils/sourceMappingURL.js';
import Bundle from './Bundle.js';
export const VERSION = '<@VERSION@>';

4
src/utils/sourceMappingURL.js

@ -3,4 +3,6 @@
let SOURCEMAPPING_URL = 'sourceMa';
SOURCEMAPPING_URL += 'ppingURL';
export default SOURCEMAPPING_URL;
const SOURCEMAPPING_URL_RE = new RegExp( `^#\\s+${SOURCEMAPPING_URL}=.+\\n?` );
export { SOURCEMAPPING_URL, SOURCEMAPPING_URL_RE };

4
test/form/removes-existing-sourcemap-comments/_expected/amd.js

@ -5,8 +5,8 @@ define(function () { 'use strict';
};
var str = `
//# sourceMappingURL=main.js.map
`;
//# sourceMappingURL=main.js.map
`;
console.log( foo(str) );

4
test/form/removes-existing-sourcemap-comments/_expected/iife.js

@ -6,8 +6,8 @@
};
var str = `
//# sourceMappingURL=main.js.map
`;
//# sourceMappingURL=main.js.map
`;
console.log( foo(str) );

4
test/form/removes-existing-sourcemap-comments/_expected/umd.js

@ -9,8 +9,8 @@
};
var str = `
//# sourceMappingURL=main.js.map
`;
//# sourceMappingURL=main.js.map
`;
console.log( foo(str) );

Loading…
Cancel
Save