diff --git a/lib/6to5/transformation/transformers/es6/block-scoping.js b/lib/6to5/transformation/transformers/es6/block-scoping.js index ebcd994a99..ea6d245aab 100644 --- a/lib/6to5/transformation/transformers/es6/block-scoping.js +++ b/lib/6to5/transformation/transformers/es6/block-scoping.js @@ -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` diff --git a/lib/6to5/traverse/global-keys.json b/lib/6to5/traverse/global-keys.json new file mode 100644 index 0000000000..f616905fbd --- /dev/null +++ b/lib/6to5/traverse/global-keys.json @@ -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" +] diff --git a/lib/6to5/traverse/scope.js b/lib/6to5/traverse/scope.js index 104511fbda..927c71f0e9 100644 --- a/lib/6to5/traverse/scope.js +++ b/lib/6to5/traverse/scope.js @@ -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 { diff --git a/package.json b/package.json index 686f16b957..203d362b55 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,6 @@ "esutils": "1.1.6", "esvalid": "1.1.0", "fs-readdir-recursive": "0.1.0", - "jshint": "2.5.11", "lodash": "2.4.1", "output-file-sync": "^1.1.0", "private": "0.1.6", @@ -57,6 +56,7 @@ "chai": "1.10.0", "istanbul": "0.3.5", "jscs": "^1.10.0", + "jshint": "2.5.11", "jshint-stylish": "1.0.0", "matcha": "0.6.0", "mocha": "2.1.0",