diff --git a/lib/6to5/scope.js b/lib/6to5/scope.js index 8954f7eb0f..8cbcbf8cda 100644 --- a/lib/6to5/scope.js +++ b/lib/6to5/scope.js @@ -6,12 +6,15 @@ var _ = require("lodash"); function Scope(parent, block) { this.parent = parent; + this.ids = block._scopeIds = block._scopeIds || Scope.getIds(block); +} +Scope.getIds = function (block) { var ids = []; if (t.isBlockStatement(block)) { _.each(block.body, function (node) { - if (t.isVariableDeclaration(node)) { + if (t.isVariableDeclaration(node) && node.kind !== "var") { ids = ids.concat(t.getIds(node)); } }); @@ -19,7 +22,7 @@ function Scope(parent, block) { if (t.isProgram(block) || t.isFunction(block)) { traverse(block, function (node) { - if (t.isVariableDeclaration(node)) { + if (t.isVariableDeclaration(node) && node.kind === "var") { ids = ids.concat(t.getIds(node)); } else if (t.isFunction(node)) { return false; @@ -33,12 +36,12 @@ function Scope(parent, block) { }); } - this.ids = ids; -} + return ids; +}; -Scope.prototype.has = function (id) { +Scope.prototype.has = function (id, noParent) { if (!id) return false; if (_.contains(this.ids, id)) return true; - if (this.parent) return this.parent.has(id); + if (noParent !== false && this.parent) return this.parent.has(id); return false; };