Skip to content
This repository was archived by the owner on Oct 9, 2020. It is now read-only.

Commit f924b3b

Browse files
committed
es module support
1 parent 13f8b04 commit f924b3b

File tree

5 files changed

+44
-1
lines changed

5 files changed

+44
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ require("babel-core").transform("code", {
7171
},
7272
moduleName: "foo",
7373
systemGlobal: "SystemJS",
74+
esModule: true
7475
}]
7576
]
7677
});

src/index.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ export default function ({ types: t }) {
1616
})
1717
`);
1818

19+
const buildFactoryEs = template(`
20+
(function ($__require, $__exports, $__module) {
21+
var _retrieveGlobal = SYSTEM_GLOBAL.registry.get("@@global-helpers").prepareGlobal($__module.id, EXPORT_NAME, GLOBALS);
22+
(BODY)(this)
23+
var $__moduleValue = _retrieveGlobal();
24+
Object.defineProperty($__moduleValue, '__esModule', {
25+
value: true
26+
});
27+
return $__moduleValue;
28+
})
29+
`);
30+
1931
const buildGlobal = template(`
2032
$__global[NAME] = VALUE;
2133
`);
@@ -74,7 +86,7 @@ export default function ({ types: t }) {
7486

7587
const systemGlobal = t.identifier(opts.systemGlobal || "System");
7688

77-
const factory = buildFactory({
89+
const factory = (opts.esModule ? buildFactoryEs : buildFactory)({
7890
SYSTEM_GLOBAL: systemGlobal,
7991
EXPORT_NAME: exportName,
8092
GLOBALS: globals || t.nullLiteral(),

test/fixtures/es-module/actual.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
var foo = function bar() {
2+
};
3+
4+
function baz() {
5+
return "qux";
6+
}

test/fixtures/es-module/expected.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
System.registerDynamic([], false, function ($__require, $__exports, $__module) {
2+
var _retrieveGlobal = System.registry.get("@@global-helpers").prepareGlobal($__module.id, null, null);
3+
4+
(function ($__global) {
5+
$__global["baz"] = baz;
6+
var foo = $__global["foo"];
7+
var foo = function bar() {};
8+
9+
function baz() {
10+
return "qux";
11+
}
12+
$__global["foo"] = foo;
13+
})(this);
14+
15+
var $__moduleValue = _retrieveGlobal();
16+
17+
Object.defineProperty($__moduleValue, '__esModule', {
18+
value: true
19+
});
20+
return $__moduleValue;
21+
});

test/fixtures/es-module/options.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
esModule: true
3+
};

0 commit comments

Comments
 (0)