switch to a custom list of global keys and use object helper
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
var traverse = require("../../../traverse");
|
||||
var object = require("../../../helpers/object");
|
||||
var util = require("../../../util");
|
||||
var t = require("../../../types");
|
||||
var _ = require("lodash");
|
||||
@@ -12,9 +13,10 @@ var isLet = function (node, parent) {
|
||||
|
||||
// https://github.com/6to5/6to5/issues/255
|
||||
if (!t.isFor(parent) || t.isFor(parent) && parent.left !== node) {
|
||||
_.each(node.declarations, function (declar) {
|
||||
for (var i = 0; i < node.declarations.length; i++) {
|
||||
var declar = node.declarations[i];
|
||||
declar.init = declar.init || t.identifier("undefined");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
node._let = true;
|
||||
@@ -82,9 +84,9 @@ function LetScoping(loopParent, block, parent, scope, file) {
|
||||
this.block = block;
|
||||
this.file = file;
|
||||
|
||||
this.outsideLetReferences = util.object();
|
||||
this.outsideLetReferences = object();
|
||||
this.hasLetReferences = false;
|
||||
this.letReferences = block._letReferences = util.object();
|
||||
this.letReferences = block._letReferences = object();
|
||||
this.body = [];
|
||||
}
|
||||
|
||||
@@ -150,7 +152,7 @@ LetScoping.prototype.remap = function () {
|
||||
// we have to check if any of our let variables collide with
|
||||
// those in upper scopes and then if they do, generate a uid
|
||||
// for them and replace all references with it
|
||||
var remaps = util.object();
|
||||
var remaps = object();
|
||||
|
||||
for (var key in letRefs) {
|
||||
// just an Identifier node we collected in `getLetReferences`
|
||||
|
||||
62
lib/6to5/traverse/global-keys.json
Normal file
62
lib/6to5/traverse/global-keys.json
Normal file
@@ -0,0 +1,62 @@
|
||||
[
|
||||
"Set",
|
||||
"Map",
|
||||
"WeakMap",
|
||||
"WeakSet",
|
||||
"Proxy",
|
||||
"Promise",
|
||||
"Reflect",
|
||||
"Symbol",
|
||||
"System",
|
||||
"__filename",
|
||||
"__dirname",
|
||||
"GLOBAL",
|
||||
"global",
|
||||
"module",
|
||||
"require",
|
||||
"Buffer",
|
||||
"console",
|
||||
"exports",
|
||||
"process",
|
||||
"setTimeout",
|
||||
"clearTimeout",
|
||||
"setInterval",
|
||||
"clearInterval",
|
||||
"setImmediate",
|
||||
"clearImmediate",
|
||||
"Array",
|
||||
"Boolean",
|
||||
"Date",
|
||||
"decodeURI",
|
||||
"decodeURIComponent",
|
||||
"encodeURI",
|
||||
"encodeURIComponent",
|
||||
"Error",
|
||||
"eval",
|
||||
"EvalError",
|
||||
"Function",
|
||||
"hasOwnProperty",
|
||||
"isFinite",
|
||||
"isNaN",
|
||||
"JSON",
|
||||
"Map",
|
||||
"Math",
|
||||
"Number",
|
||||
"Object",
|
||||
"Proxy",
|
||||
"Promise",
|
||||
"parseInt",
|
||||
"parseFloat",
|
||||
"RangeError",
|
||||
"ReferenceError",
|
||||
"RegExp",
|
||||
"Set",
|
||||
"String",
|
||||
"SyntaxError",
|
||||
"TypeError",
|
||||
"URIError",
|
||||
"WeakMap",
|
||||
"WeakSet",
|
||||
"arguments",
|
||||
"NaN"
|
||||
]
|
||||
@@ -3,6 +3,7 @@
|
||||
module.exports = Scope;
|
||||
|
||||
var traverse = require("./index");
|
||||
var object = require("../helpers/object");
|
||||
var t = require("../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
@@ -28,14 +29,7 @@ function Scope(block, parent, file) {
|
||||
this.declarationKinds = info.declarationKinds;
|
||||
}
|
||||
|
||||
var vars = require("jshint/src/vars");
|
||||
|
||||
Scope.defaultDeclarations = _.flatten([
|
||||
vars.newEcmaIdentifiers,
|
||||
vars.node,
|
||||
vars.ecmaIdentifiers,
|
||||
vars.reservedVars
|
||||
].map(_.keys));
|
||||
Scope.defaultDeclarations = require("./global-keys");
|
||||
|
||||
Scope.prototype._add = function (node, references, throwOnDuplicate) {
|
||||
if (!node) return;
|
||||
@@ -190,8 +184,8 @@ Scope.prototype.getInfo = function () {
|
||||
if (block._scopeInfo) return block._scopeInfo;
|
||||
|
||||
var info = block._scopeInfo = {};
|
||||
var references = info.references = {};
|
||||
var declarations = info.declarations = {};
|
||||
var references = info.references = object();
|
||||
var declarations = info.declarations = object();
|
||||
var declarationKinds = info.declarationKinds = {};
|
||||
|
||||
var add = function (node, reference, throwOnDuplicate) {
|
||||
@@ -199,7 +193,7 @@ Scope.prototype.getInfo = function () {
|
||||
|
||||
if (!reference) {
|
||||
self._add(node, declarations, throwOnDuplicate);
|
||||
self._add(node, declarationKinds[node.kind] = declarationKinds[node.kind] || {});
|
||||
self._add(node, declarationKinds[node.kind] = declarationKinds[node.kind] || object());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -323,7 +317,7 @@ Scope.prototype.getFunctionParent = function () {
|
||||
*/
|
||||
|
||||
Scope.prototype.getAllOfKind = function (kind) {
|
||||
var ids = {};
|
||||
var ids = object();
|
||||
|
||||
var scope = this;
|
||||
do {
|
||||
|
||||
Reference in New Issue
Block a user