stop assigning to global in generated helpers code
This commit is contained in:
@@ -6,18 +6,28 @@ import t from "./types";
|
||||
export default function (whitelist) {
|
||||
var namespace = t.identifier("babelHelpers");
|
||||
|
||||
var body = [];
|
||||
var container = t.functionExpression(null, [t.identifier("global")], t.blockStatement(body));
|
||||
var tree = t.program([t.expressionStatement(t.callExpression(container, [util.template("self-global")]))]);
|
||||
|
||||
var body = [];
|
||||
body.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(
|
||||
namespace,
|
||||
t.assignmentExpression("=", t.memberExpression(t.identifier("global"), namespace), t.objectExpression([]))
|
||||
)
|
||||
t.variableDeclarator(namespace, t.identifier("global"))
|
||||
]));
|
||||
|
||||
buildHelpers(body, namespace, whitelist);
|
||||
|
||||
var globalHelpersDeclar = t.variableDeclaration("var", [
|
||||
t.variableDeclarator(
|
||||
namespace,
|
||||
t.objectExpression({})
|
||||
)
|
||||
]);
|
||||
var container = util.template("umd-commonjs-strict", {
|
||||
AMD_ARGUMENTS: t.arrayExpression([t.literal("exports")]),
|
||||
COMMON_ARGUMENTS: t.identifier("exports"),
|
||||
BROWSER_ARGUMENTS: t.identifier("root"),
|
||||
UMD_ROOT: namespace,
|
||||
FACTORY_PARAMETERS: t.identifier("global"),
|
||||
FACTORY_BODY: body
|
||||
});
|
||||
var tree = t.program([globalHelpersDeclar, container]);
|
||||
|
||||
return generator(tree).code;
|
||||
};
|
||||
|
||||
11
src/babel/transformation/templates/umd-commonjs-strict.js
Normal file
11
src/babel/transformation/templates/umd-commonjs-strict.js
Normal file
@@ -0,0 +1,11 @@
|
||||
(function (root, factory) {
|
||||
if (typeof define === "function" && define.amd) {
|
||||
define(AMD_ARGUMENTS, factory);
|
||||
} else if (typeof exports === 'object') {
|
||||
factory(COMMON_ARGUMENTS);
|
||||
} else {
|
||||
factory(BROWSER_ARGUMENTS);
|
||||
}
|
||||
})(UMD_ROOT, function (FACTORY_PARAMETERS) {
|
||||
FACTORY_BODY
|
||||
});
|
||||
Reference in New Issue
Block a user