add Scope::getFunctionParent method

This commit is contained in:
Sebastian McKenzie
2015-01-22 17:20:29 +11:00
parent 2e0a185db6
commit 9bfe6e7aac

View File

@@ -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;
};
/**