diff --git a/lib/6to5/traverse/scope.js b/lib/6to5/traverse/scope.js index 662f908d1a..950fe6508c 100644 --- a/lib/6to5/traverse/scope.js +++ b/lib/6to5/traverse/scope.js @@ -45,7 +45,7 @@ Scope.prototype._add = function (node, references, throwOnDuplicate) { var id = ids[key]; if (throwOnDuplicate && references[key]) { - throw this.file.errorWithNode(id, "Duplicate declaration"); + throw this.file.errorWithNode(id, "Duplicate declaration", TypeError); } references[key] = id; @@ -169,12 +169,11 @@ var functionVariableVisitor = { var blockVariableVisitor = { enter: function (node, parent, scope, context, add) { - if (t.isScope(node)) { - return context.skip(); - } - if (t.isBlockScoped(node)) { add(node, false, true); + context.stop(); + } else if (t.isScope(node)) { + context.skip(); } } }; @@ -277,13 +276,18 @@ Scope.prototype.push = function (opts) { }; /** - * Description + * Walk up the scope tree until we hit a `Function` and then + * push our `node` to it's references. * * @param {Object} node */ Scope.prototype.add = function (node) { - this._add(node, this.references); + var scope = this; + while (scope.parent && !t.isFunction(scope.block)) { + scope = scope.parent; + } + scope._add(node, scope.references); }; /**