Modules systemjs system global name, use strict wrapping (#3482)
* modules systemjs system global name, use strict wrapping * document systemGlobal option in readme
This commit is contained in:
@@ -12,10 +12,21 @@ $ npm install babel-plugin-transform-es2015-modules-systemjs
|
||||
|
||||
**.babelrc**
|
||||
|
||||
```json
|
||||
```javascript
|
||||
// without options
|
||||
{
|
||||
"plugins": ["transform-es2015-modules-systemjs"]
|
||||
}
|
||||
|
||||
// with options
|
||||
{
|
||||
"plugins": [
|
||||
["transform-es2015-modules-systemjs", {
|
||||
// outputs SystemJS.register(...)
|
||||
"systemGlobal": "SystemJS"
|
||||
}]
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### Via CLI
|
||||
|
||||
@@ -8,8 +8,7 @@
|
||||
"dependencies": {
|
||||
"babel-template": "^6.8.0",
|
||||
"babel-helper-hoist-variables": "^6.8.0",
|
||||
"babel-runtime": "^6.0.0",
|
||||
"babel-plugin-transform-strict-mode": "^6.8.0"
|
||||
"babel-runtime": "^6.0.0"
|
||||
},
|
||||
"keywords": [
|
||||
"babel-plugin"
|
||||
|
||||
@@ -4,7 +4,8 @@ import hoistVariables from "babel-helper-hoist-variables";
|
||||
import template from "babel-template";
|
||||
|
||||
let buildTemplate = template(`
|
||||
System.register(MODULE_NAME, [SOURCES], function (EXPORT_IDENTIFIER, CONTEXT_IDENTIFIER) {
|
||||
SYSTEM_REGISTER(MODULE_NAME, [SOURCES], function (EXPORT_IDENTIFIER, CONTEXT_IDENTIFIER) {
|
||||
"use strict";
|
||||
BEFORE_BODY;
|
||||
return {
|
||||
setters: [SETTERS],
|
||||
@@ -51,8 +52,6 @@ export default function ({ types: t }) {
|
||||
};
|
||||
|
||||
return {
|
||||
inherits: require("babel-plugin-transform-strict-mode"),
|
||||
|
||||
visitor: {
|
||||
ReferencedIdentifier(path, state) {
|
||||
if (path.node.name == "__moduleName" && !path.scope.hasBinding("__moduleName")) {
|
||||
@@ -248,6 +247,7 @@ export default function ({ types: t }) {
|
||||
|
||||
path.node.body = [
|
||||
buildTemplate({
|
||||
SYSTEM_REGISTER: t.memberExpression(t.identifier(state.opts.systemGlobal || "System"), t.identifier("register")),
|
||||
BEFORE_BODY: beforeBody,
|
||||
MODULE_NAME: moduleName,
|
||||
SETTERS: setters,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
System.register([], function (_export, _context) {
|
||||
"use strict";
|
||||
|
||||
_export("default", function () {});
|
||||
|
||||
_export("default", class {});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
System.register(["foo"], function (_export, _context) {
|
||||
"use strict";
|
||||
|
||||
return {
|
||||
setters: [function (_foo) {
|
||||
var _exportObj = {};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
System.register([], function (_export, _context) {
|
||||
"use strict";
|
||||
|
||||
return {
|
||||
setters: [],
|
||||
execute: function () {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
System.register([], function (_export, _context) {
|
||||
"use strict";
|
||||
|
||||
return {
|
||||
setters: [],
|
||||
execute: function () {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
System.register("my custom module name", [], function (_export, _context) {
|
||||
"use strict";
|
||||
|
||||
return {
|
||||
setters: [],
|
||||
execute: function () {}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
System.register(["./evens"], function (_export, _context) {
|
||||
"use strict";
|
||||
|
||||
var isEven, p, a, i, j, isOdd;
|
||||
return {
|
||||
setters: [function (_evens) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
System.register(["foo"], function (_export, _context) {
|
||||
"use strict";
|
||||
|
||||
var foo, foo2;
|
||||
return {
|
||||
setters: [function (_foo) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
System.register(["foo"], function (_export, _context) {
|
||||
"use strict";
|
||||
|
||||
var foo;
|
||||
return {
|
||||
setters: [function (_foo) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
System.register(["foo"], function (_export, _context) {
|
||||
"use strict";
|
||||
|
||||
var foo, xyz;
|
||||
return {
|
||||
setters: [function (_foo) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
System.register(["foo"], function (_export, _context) {
|
||||
"use strict";
|
||||
|
||||
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, _context) {
|
||||
"use strict";
|
||||
|
||||
return {
|
||||
setters: [function (_foo) {}, function (_fooBar) {}, function (_directoryFooBar) {}],
|
||||
execute: function () {}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
System.register([], function (_export, _context) {
|
||||
"use strict";
|
||||
|
||||
var name;
|
||||
return {
|
||||
setters: [],
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
System.register(["foo", "foo-bar", "./directory/foo-bar"], function (_export, _context) {
|
||||
"use strict";
|
||||
|
||||
var foo, foo2, bar, bar2, test2;
|
||||
return {
|
||||
setters: [function (_foo) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
System.register([], function (_export, _context) {
|
||||
"use strict";
|
||||
|
||||
var test, a, b, d;
|
||||
return {
|
||||
setters: [],
|
||||
|
||||
Reference in New Issue
Block a user