diff --git a/lib/6to5/traverse/index.js b/lib/6to5/traverse/index.js index b8ef5ce920..5e56d891c4 100644 --- a/lib/6to5/traverse/index.js +++ b/lib/6to5/traverse/index.js @@ -55,7 +55,7 @@ function traverse(parent, callbacks, opts) { // var opts2 = { scope: opts.scope, blacklist: opts.blacklist }; - if (t.isScope(node)) opts2.scope = new Scope(opts.scope, node); + if (t.isScope(node)) opts2.scope = new Scope(node, opts.scope); // enter if (callbacks.enter) { @@ -89,9 +89,10 @@ function traverse(parent, callbacks, opts) { traverse.removeProperties = function (tree) { var clear = function (node) { + delete node._scopeReferences; delete node.extendedRange; - delete node._scopeIds; delete node._parent; + delete node._scope; delete node.tokens; delete node.range; delete node.start; diff --git a/lib/6to5/traverse/scope.js b/lib/6to5/traverse/scope.js index 5851011487..3945900182 100644 --- a/lib/6to5/traverse/scope.js +++ b/lib/6to5/traverse/scope.js @@ -10,11 +10,15 @@ var FOR_KEYS = ["left", "init"]; * This searches the current "scope" and collects all references/declarations * within. * - * @param {Scope} [parent] * @param {Node} block + * @param {Scope} [parent] */ -function Scope(parent, block) { +function Scope(block, parent) { + if (!parent && block._parent) { + parent = block._parent._scope; + } + this.parent = parent; this.block = block; @@ -23,10 +27,10 @@ function Scope(parent, block) { Scope.prototype.getReferences = function () { var block = this.block; - if (block._scope) return block._scope; + if (block._scopeReferences) return block._scopeReferences; var self = this; - var references = block._scope = {}; + var references = block._scopeReferences = {}; var add = function (node) { self.add(node, references);