Whitelist constructors aliasable to core-js

Expand the list of identifiers for which we substitute `_core.<Something>`
for `<Something>`.  Also an alternative fix for #421.
This commit is contained in:
Aluísio Augusto Silva Gonçalves
2015-01-12 12:29:37 -02:00
parent ea627ed57c
commit afd5376c8d
6 changed files with 25 additions and 15 deletions

View File

@@ -8,6 +8,16 @@ var coreHas = function (node) {
return node.name !== "_" && _.has(core, node.name);
};
var ALIASABLE_CONSTRUCTORS = [
"Symbol",
"Promise",
"Map",
"WeakMap",
"Set",
"WeakSet",
"Dict",
];
exports.optional = true;
exports.ast = {
@@ -31,8 +41,8 @@ exports.ast = {
this.skip();
return t.prependToMemberExpression(node, file._coreId);
}
} else if (t.isIdentifier(node) && !t.isMemberExpression(parent) && t.isReferenced(node, parent) && node.name === "Symbol") {
// new Symbol -> new _core.Symbol
} else if (t.isIdentifier(node) && !t.isMemberExpression(parent) && t.isReferenced(node, parent) && _.contains(ALIASABLE_CONSTRUCTORS, node.name)) {
// Symbol() -> _core.Symbol(); new Promise -> new _core.Promise
return t.memberExpression(file._coreId, node);
} else if (t.isCallExpression(node)) {
// arr[Symbol.iterator]() -> _core.$for.getIterator(arr)