Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change removal of sourcemap comment (#3987)
* Change removal of sourcemap comment Do the removal without relying on the module parsing the code. This way even if a plugin uses the `parse` method in the PluginContext the comments are removed. * Add test: plugin-parse-ast-remove-sourcemapping * Remove dead code * Remove unused proprty `comments` from Module * Remove sourceMappingURL Comment only on top-level * Fix linting error * Add test plugin-parse-ast-receives-comments * Rewrite findSourceMappingURLComments Better readability and hopefully more performant Co-authored-by: Yannay Livneh <you@example.com> Co-authored-by: Lukas Taegert-Atkinson <lukastaegert@users.noreply.github.com>
- Loading branch information
1 parent
d053e0d
commit 3cf6574
Showing
6 changed files
with
88 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
test/function/samples/plugin-parse-ast-receives-comments/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const assert = require('assert'); | ||
|
||
const comments = []; | ||
|
||
module.exports = { | ||
description: 'plugin parse ast receives comments', | ||
options: { | ||
plugins:[{ | ||
transform(code, _id) { | ||
const ast = this.parse(code, { | ||
onComment(...args) { | ||
comments.push(args); | ||
}, | ||
}); | ||
return {ast, code, map: null}; | ||
}, | ||
}], | ||
}, | ||
after() { | ||
assert.ok(comments.length > 0); | ||
}, | ||
}; |
4 changes: 4 additions & 0 deletions
4
test/function/samples/plugin-parse-ast-receives-comments/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/* this is a comment */ | ||
export function main() { | ||
// this is also a comment | ||
} |
16 changes: 16 additions & 0 deletions
16
test/function/samples/plugin-parse-ast-remove-sourcemapping/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const assert = require('assert'); | ||
|
||
module.exports = { | ||
description: 'remove source mapping comment even if code is parsed by PluginContext.parse method', | ||
options: { | ||
plugins:[{ | ||
transform(code, _id) { | ||
const ast = this.parse(code); | ||
return {ast, code, map: null}; | ||
}, | ||
}], | ||
}, | ||
code(code) { | ||
assert.ok(code.search(/sourceMappingURL/) === -1); | ||
} | ||
}; |
11 changes: 11 additions & 0 deletions
11
test/function/samples/plugin-parse-ast-remove-sourcemapping/main.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.