diff --git a/lib/6to5/traverse/scope.js b/lib/6to5/traverse/scope.js index f749a5a88a..104511fbda 100644 --- a/lib/6to5/traverse/scope.js +++ b/lib/6to5/traverse/scope.js @@ -299,11 +299,21 @@ Scope.prototype.push = function (opts) { */ Scope.prototype.add = function (node) { + var scope = this.getFunctionParent(); + scope._add(node, scope.references); +}; + +/** + * Walk up the scope tree until we hit either a Function or reach the + * very top at hit Program. + */ + +Scope.prototype.getFunctionParent = function () { var scope = this; while (scope.parent && !t.isFunction(scope.block)) { scope = scope.parent; } - scope._add(node, scope.references); + return scope; }; /**