Skip to content

Commit 2072d78

Browse files
authored
Merge pull request #17 from dbo/GH-16
BREAKING CHANGE: GH-16: Update to babel 7, adapting tests, deps
2 parents 3a15417 + afdca2c commit 2072d78

File tree

9 files changed

+8903
-72
lines changed

9 files changed

+8903
-72
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cache:
55
notifications:
66
email: false
77
node_js:
8-
- '9'
8+
- '10'
99
- '8'
1010
after_success:
1111
- npm run travis-deploy-once "npm run semantic-release"

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,18 @@ $ npm install babel-plugin-transform-n4js-systemjs-commonjs --save-dev
1414
Using a `.babelrc`:
1515
```
1616
{
17-
"plugins": ["transform-n4js-systemjs-commonjs"]
17+
"plugins": ["babel-plugin-transform-n4js-systemjs-commonjs"]
1818
}
1919
```
2020

2121
or via CLI:
2222
```bash
23-
$ babel --plugins transform-n4js-systemjs-commonjs ...
23+
$ babel --plugins babel-plugin-transform-n4js-systemjs-commonjs ...
2424
```
2525

2626
Plugin Options:
2727
- `verbose: [string]` switches on verbose logging of the used module IDs
2828
- `stripPackageID_re: [string|Regexp]` regex to rewrite/strip parts of the package ID by convention
29-
- `noSourceMap: [boolean]` whether the N4JS source-map reference should be dropped; defaults to `true`
3029

3130
## License
3231

index.js

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -91,52 +91,39 @@ module.exports = ({types: t}) => {
9191
let program = path.node,
9292
opts = state.opts || {},
9393
verbose = opts.verbose,
94-
stripPackageID_re = opts.stripPackageID_re,
95-
noSourceMap = opts.noSourceMap;
94+
stripPackageID_re = opts.stripPackageID_re;
9695

97-
if (typeof noSourceMap === "undefined") {
98-
noSourceMap = true;
99-
}
10096
if (stripPackageID_re && !(stripPackageID_re instanceof RegExp)) {
10197
stripPackageID_re = new RegExp(stripPackageID_re);
10298
}
10399

104100
if (n4jsModulePatternMatcher(program)) {
105101
try {
106-
let fnExpr = program.body[0].expression;
102+
const fnExpr = program.body[0].expression;
107103

108104
// reduce ternary footer:
109-
let consequent = fnExpr.arguments[0].consequent;
105+
const consequent = fnExpr.arguments[0].consequent;
110106
consequent.callee.object.arguments = [t.stringLiteral("n4js-node")];
111107
//consequent.arguments[0] = t.nullLiteral();
112108
consequent.callee.property = t.identifier("staticSystem");
113109
fnExpr.arguments = [consequent.callee];
114110

115-
let sysRegExpr = fnExpr.callee.body.body[0].expression;
116-
let sysregDeps = sysRegExpr.arguments[0];
111+
const sysRegExpr = fnExpr.callee.body.body[0].expression;
112+
const sysregDeps = sysRegExpr.arguments[0];
117113
sysregDeps.elements = sysregDeps.elements.map(d => t.callExpression(t.identifier("require"), [buildDep(d, stripPackageID_re)]));
118114

119-
let dynregCallback = sysRegExpr.arguments[2];
115+
const dynregCallback = sysRegExpr.arguments[2];
120116
if (dynregCallback) { // registerDynamic
121117
// Get require symbol out of the way
122118
dynregCallback.params[0] = t.identifier("__require");
123119
}
124120

125121
sysRegExpr.arguments.push(t.identifier("module"));
126-
let filename = state.file.opts.filename;
122+
const filename = state.file.opts.filename;
127123
if (filename !== "unknown") {
128124
sysRegExpr.arguments.push(t.stringLiteral(getModuleIdOf(filename, verbose)));
129125
}
130126

131-
if (noSourceMap) {
132-
let comments = path.container.comments;
133-
comments.forEach(c => {
134-
if (c.value.startsWith("# sourceMappingURL=")) {
135-
c.value = `--${c.value}--`;
136-
}
137-
});
138-
}
139-
140127
// replace all System._nodeRequire calls
141128
path.traverse(_nodeRequireVisitor);
142129

0 commit comments

Comments
 (0)