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

Commit 4d89536

Browse files
committed
skip adding es module if already existing
1 parent 4b3a4c4 commit 4d89536

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

src/index.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ export default function ({ types: t }) {
3434

3535
return {
3636
visitor: {
37+
StringLiteral (path) {
38+
if (path.node.value === '__esModule')
39+
this.hasEsModule = true;
40+
},
41+
MemberExpression (path) {
42+
if (path.node.property.name === '__esModule')
43+
this.hasEsModule = true;
44+
},
3745
Program: {
3846
enter({ scope }) {
3947
// "import" existing global variables values as `var foo = $__global["foo"];`
@@ -86,7 +94,7 @@ export default function ({ types: t }) {
8694

8795
const systemGlobal = t.identifier(opts.systemGlobal || "System");
8896

89-
const factory = (opts.esModule ? buildFactoryEs : buildFactory)({
97+
const factory = (opts.esModule && !this.hasEsModule ? buildFactoryEs : buildFactory)({
9098
SYSTEM_GLOBAL: systemGlobal,
9199
EXPORT_NAME: exportName,
92100
GLOBALS: globals || t.nullLiteral(),

test/fixtures/es-module-has/actual.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
var foo = function bar() {
2+
};
3+
4+
Object.defineProperty(foo, '__esModule', {
5+
value: true
6+
});
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
var foo = $__global['foo'];
6+
var foo = function bar() {};
7+
8+
Object.defineProperty(foo, '__esModule', {
9+
value: true
10+
});
11+
$__global['foo'] = foo;
12+
})(this);
13+
14+
return _retrieveGlobal();
15+
});
+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)