Skip to content

Commit

Permalink
feat: plugin option noSourceMap for N4JS source-map reference
Browse files Browse the repository at this point in the history
  • Loading branch information
dbo committed Nov 25, 2016
1 parent 814106c commit 0f89936
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ $ babel --plugins transform-n4js-systemjs-commonjs ...
Plugin Options:
- `verbose: [string]` switches on verbose logging of the used module IDs
- `stripPackageID_re: [string|Regexp]` regex to rewrite/strip parts of the package ID by convention
- `noSourceMap: [boolean]` whether the N4JS source-map reference should be dropped; defaults to `true`

## License

Expand Down
20 changes: 13 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,12 @@ module.exports = ({types: t}) => {
let program = path.node,
opts = state.opts || {},
verbose = opts.verbose,
stripPackageID_re = opts.stripPackageID_re;
stripPackageID_re = opts.stripPackageID_re,
noSourceMap = opts.noSourceMap;

if (typeof noSourceMap === "undefined") {
noSourceMap = true;
}
if (stripPackageID_re && !(stripPackageID_re instanceof RegExp)) {
stripPackageID_re = new RegExp(stripPackageID_re);
}
Expand Down Expand Up @@ -124,12 +128,14 @@ module.exports = ({types: t}) => {
sysRegExpr.arguments.push(t.stringLiteral(getModuleIdOf(filename, verbose)));
}

let comments = path.container.comments;
comments.forEach(c => {
if (c.value.startsWith("# sourceMappingURL=")) {
c.value = `--${c.value}--`;
}
});
if (noSourceMap) {
let comments = path.container.comments;
comments.forEach(c => {
if (c.value.startsWith("# sourceMappingURL=")) {
c.value = `--${c.value}--`;
}
});
}

// replace all System._nodeRequire calls
path.traverse(_nodeRequireVisitor);
Expand Down

0 comments on commit 0f89936

Please sign in to comment.