From 9bfe6e7aac3833e2ebdcd207adb9d1f137402745 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Thu, 22 Jan 2015 17:20:29 +1100 Subject: [PATCH] add Scope::getFunctionParent method --- lib/6to5/traverse/scope.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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; }; /**