use a _context object instead of a __moduleName argument
This commit is contained in:
parent
40714d004c
commit
be2d85d688
@ -2,7 +2,7 @@ import hoistVariables from "babel-helper-hoist-variables";
|
||||
import template from "babel-template";
|
||||
|
||||
let buildTemplate = template(`
|
||||
System.register(MODULE_NAME, [SOURCES], function (EXPORT_IDENTIFIER, __moduleName) {
|
||||
System.register(MODULE_NAME, [SOURCES], function (EXPORT_IDENTIFIER, CONTEXT_IDENTIFIER) {
|
||||
BEFORE_BODY;
|
||||
return {
|
||||
setters: [SETTERS],
|
||||
@ -52,9 +52,19 @@ export default function ({ types: t }) {
|
||||
inherits: require("babel-plugin-transform-strict-mode"),
|
||||
|
||||
visitor: {
|
||||
ReferencedIdentifier(path, state) {
|
||||
if (path.node.name == "__moduleName" && !path.scope.hasBinding("__moduleName")) {
|
||||
path.replaceWith(t.memberExpression(state.contextIdent, t.identifier("id")));
|
||||
}
|
||||
},
|
||||
|
||||
Program: {
|
||||
exit(path) {
|
||||
enter(path, state) {
|
||||
state.contextIdent = path.scope.generateUidIdentifier("context");
|
||||
},
|
||||
exit(path, state) {
|
||||
let exportIdent = path.scope.generateUidIdentifier("export");
|
||||
let contextIdent = state.contextIdent;
|
||||
|
||||
let exportNames = Object.create(null);
|
||||
let modules = Object.create(null);
|
||||
@ -241,7 +251,8 @@ export default function ({ types: t }) {
|
||||
SETTERS: setters,
|
||||
SOURCES: sources,
|
||||
BODY: path.node.body,
|
||||
EXPORT_IDENTIFIER: exportIdent
|
||||
EXPORT_IDENTIFIER: exportIdent,
|
||||
CONTEXT_IDENTIFIER: contextIdent
|
||||
})
|
||||
];
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
System.register([], function (_export, __moduleName) {
|
||||
System.register([], function (_export, _context) {
|
||||
_export("default", function () {});
|
||||
|
||||
_export("default", class {});
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
System.register(["foo"], function (_export, __moduleName) {
|
||||
System.register(["foo"], function (_export, _context) {
|
||||
return {
|
||||
setters: [function (_foo) {
|
||||
var _exportObj = {};
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
System.register([], function (_export, __moduleName) {
|
||||
System.register([], function (_export, _context) {
|
||||
return {
|
||||
setters: [],
|
||||
execute: function () {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
System.register([], function (_export, __moduleName) {
|
||||
System.register([], function (_export, _context) {
|
||||
return {
|
||||
setters: [],
|
||||
execute: function () {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
System.register("my custom module name", [], function (_export, __moduleName) {
|
||||
System.register("my custom module name", [], function (_export, _context) {
|
||||
return {
|
||||
setters: [],
|
||||
execute: function () {}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
System.register(["./evens"], function (_export, __moduleName) {
|
||||
System.register(["./evens"], function (_export, _context) {
|
||||
var isEven, p, a, i, j, isOdd;
|
||||
return {
|
||||
setters: [function (_evens) {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
System.register(["foo"], function (_export, __moduleName) {
|
||||
System.register(["foo"], function (_export, _context) {
|
||||
var foo, foo2;
|
||||
return {
|
||||
setters: [function (_foo) {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
System.register(["foo"], function (_export, __moduleName) {
|
||||
System.register(["foo"], function (_export, _context) {
|
||||
var foo;
|
||||
return {
|
||||
setters: [function (_foo) {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
System.register(["foo"], function (_export, __moduleName) {
|
||||
System.register(["foo"], function (_export, _context) {
|
||||
var foo, xyz;
|
||||
return {
|
||||
setters: [function (_foo) {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
System.register(["foo"], function (_export, __moduleName) {
|
||||
System.register(["foo"], function (_export, _context) {
|
||||
var bar, bar2, baz, baz2, baz3, xyz;
|
||||
return {
|
||||
setters: [function (_foo) {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
System.register(["foo", "foo-bar", "./directory/foo-bar"], function (_export, __moduleName) {
|
||||
System.register(["foo", "foo-bar", "./directory/foo-bar"], function (_export, _context) {
|
||||
return {
|
||||
setters: [function (_foo) {}, function (_fooBar) {}, function (_directoryFooBar) {}],
|
||||
execute: function () {}
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
"use strict";
|
||||
|
||||
System.register([], function (_export, __moduleName) {
|
||||
System.register([], function (_export, _context) {
|
||||
var name;
|
||||
return {
|
||||
setters: [],
|
||||
execute: function () {
|
||||
_export("name", name = __moduleName);
|
||||
_export("name", name = _context.id);
|
||||
|
||||
_export("name", name);
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
System.register(["foo", "foo-bar", "./directory/foo-bar"], function (_export, __moduleName) {
|
||||
System.register(["foo", "foo-bar", "./directory/foo-bar"], function (_export, _context) {
|
||||
var foo, foo2, bar, bar2, test2;
|
||||
return {
|
||||
setters: [function (_foo) {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
System.register([], function (_export, __moduleName) {
|
||||
System.register([], function (_export, _context) {
|
||||
var test, a, b, d;
|
||||
return {
|
||||
setters: [],
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user