Make buildExportAll generate pure ES5 code.
The untransformed `let` keyword causes problems for older parsers. I understand using `let` instead of `var` ensures each getter function has its own binding for the KEY variable, but the same can be accomplished (with less code) using a `.forEach` callback function, and this way there's no need to worry about generating a unique name for the `key` variable.
This commit is contained in:
@@ -32,16 +32,15 @@ let buildExportsAssignment = template(`
|
||||
`);
|
||||
|
||||
let buildExportAll = template(`
|
||||
for (let KEY in OBJECT) {
|
||||
if (KEY === "default") continue;
|
||||
|
||||
Object.defineProperty(exports, KEY, {
|
||||
Object.keys(OBJECT).forEach(function (key) {
|
||||
if (key === "default") return;
|
||||
Object.defineProperty(exports, key, {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return OBJECT[KEY];
|
||||
return OBJECT[key];
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
`);
|
||||
|
||||
const THIS_BREAK_KEYS = ["FunctionExpression", "FunctionDeclaration", "ClassProperty", "ClassMethod", "ObjectMethod"];
|
||||
@@ -335,7 +334,6 @@ export default function () {
|
||||
}
|
||||
} else if (path.isExportAllDeclaration()) {
|
||||
topNodes.push(buildExportAll({
|
||||
KEY: path.scope.generateUidIdentifier("key"),
|
||||
OBJECT: addRequire(path.node.source.value, path.node._blockHoist)
|
||||
}));
|
||||
path.remove();
|
||||
|
||||
Reference in New Issue
Block a user