From 9164f80487ab17165371ddc7b6224250530f82f8 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Sun, 2 Aug 2015 12:46:42 -0400 Subject: [PATCH] remove pre-existing sourcemap comments --- src/Module.js | 7 +++++++ .../removes-existing-sourcemap-comments/_config.js | 3 +++ .../_expected/amd.js | 9 +++++++++ .../_expected/cjs.js | 7 +++++++ .../_expected/es6.js | 5 +++++ .../_expected/iife.js | 9 +++++++++ .../_expected/umd.js | 13 +++++++++++++ .../form/removes-existing-sourcemap-comments/foo.js | 5 +++++ .../removes-existing-sourcemap-comments/main.js | 5 +++++ 9 files changed, 63 insertions(+) create mode 100644 test/form/removes-existing-sourcemap-comments/_config.js create mode 100644 test/form/removes-existing-sourcemap-comments/_expected/amd.js create mode 100644 test/form/removes-existing-sourcemap-comments/_expected/cjs.js create mode 100644 test/form/removes-existing-sourcemap-comments/_expected/es6.js create mode 100644 test/form/removes-existing-sourcemap-comments/_expected/iife.js create mode 100644 test/form/removes-existing-sourcemap-comments/_expected/umd.js create mode 100644 test/form/removes-existing-sourcemap-comments/foo.js create mode 100644 test/form/removes-existing-sourcemap-comments/main.js diff --git a/src/Module.js b/src/Module.js index 3cf9b8a..70c2ccb 100644 --- a/src/Module.js +++ b/src/Module.js @@ -41,6 +41,13 @@ export default class Module { filename: id }); + // remove existing sourceMappingURL comments + const pattern = /\/\/#\s+sourceMappingURL=.+\n?/g; + let match; + while ( match = pattern.exec( source ) ) { + this.magicString.remove( match.index, match.index + match[0].length ); + } + this.suggestedNames = blank(); this.comments = []; diff --git a/test/form/removes-existing-sourcemap-comments/_config.js b/test/form/removes-existing-sourcemap-comments/_config.js new file mode 100644 index 0000000..e1b917a --- /dev/null +++ b/test/form/removes-existing-sourcemap-comments/_config.js @@ -0,0 +1,3 @@ +module.exports = { + description: 'removes existing sourcemap comments' +}; diff --git a/test/form/removes-existing-sourcemap-comments/_expected/amd.js b/test/form/removes-existing-sourcemap-comments/_expected/amd.js new file mode 100644 index 0000000..e614344 --- /dev/null +++ b/test/form/removes-existing-sourcemap-comments/_expected/amd.js @@ -0,0 +1,9 @@ +define(function () { 'use strict'; + + function foo () { + return 42; + } + + console.log( foo() ); + +}); diff --git a/test/form/removes-existing-sourcemap-comments/_expected/cjs.js b/test/form/removes-existing-sourcemap-comments/_expected/cjs.js new file mode 100644 index 0000000..d7a8df2 --- /dev/null +++ b/test/form/removes-existing-sourcemap-comments/_expected/cjs.js @@ -0,0 +1,7 @@ +'use strict'; + +function foo () { + return 42; +} + +console.log( foo() ); diff --git a/test/form/removes-existing-sourcemap-comments/_expected/es6.js b/test/form/removes-existing-sourcemap-comments/_expected/es6.js new file mode 100644 index 0000000..c458828 --- /dev/null +++ b/test/form/removes-existing-sourcemap-comments/_expected/es6.js @@ -0,0 +1,5 @@ +function foo () { + return 42; +} + +console.log( foo() ); diff --git a/test/form/removes-existing-sourcemap-comments/_expected/iife.js b/test/form/removes-existing-sourcemap-comments/_expected/iife.js new file mode 100644 index 0000000..07a64a4 --- /dev/null +++ b/test/form/removes-existing-sourcemap-comments/_expected/iife.js @@ -0,0 +1,9 @@ +(function () { 'use strict'; + + function foo () { + return 42; + } + + console.log( foo() ); + +})(); diff --git a/test/form/removes-existing-sourcemap-comments/_expected/umd.js b/test/form/removes-existing-sourcemap-comments/_expected/umd.js new file mode 100644 index 0000000..79f644c --- /dev/null +++ b/test/form/removes-existing-sourcemap-comments/_expected/umd.js @@ -0,0 +1,13 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory() : + typeof define === 'function' && define.amd ? define(factory) : + factory(); +}(this, function () { 'use strict'; + + function foo () { + return 42; + } + + console.log( foo() ); + +})); diff --git a/test/form/removes-existing-sourcemap-comments/foo.js b/test/form/removes-existing-sourcemap-comments/foo.js new file mode 100644 index 0000000..74fda08 --- /dev/null +++ b/test/form/removes-existing-sourcemap-comments/foo.js @@ -0,0 +1,5 @@ +export default function () { + return 42; +} + +//# sourceMappingURL=foo.js.map diff --git a/test/form/removes-existing-sourcemap-comments/main.js b/test/form/removes-existing-sourcemap-comments/main.js new file mode 100644 index 0000000..3c48af8 --- /dev/null +++ b/test/form/removes-existing-sourcemap-comments/main.js @@ -0,0 +1,5 @@ +import foo from './foo'; + +console.log( foo() ); + +//# sourceMappingURL=main.js.map