Skip to content

Commit

Permalink
fix(espower): store scopes in a stack to push/pop them in a consisten…
Browse files Browse the repository at this point in the history
  • Loading branch information
twada committed Feb 19, 2017
1 parent f0b2db8 commit 5e9373f
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/instrumentor.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ Instrumentor.prototype.createVisitor = function (ast) {
var storage = {};
var skipping = false;
var scopeManager = escope.analyze(ast);
var currentScope = scopeManager.acquire(ast);
var globalScope = currentScope;
var globalScope = scopeManager.acquire(ast);
var scopeStack = [];
scopeStack.push(globalScope);
var transformation = new Transformation();
var visitor = {
enter: function (currentNode, parentNode) {
if (/Function/.test(currentNode.type)) {
currentScope = scopeManager.acquire(currentNode);
scopeStack.push(scopeManager.acquire(currentNode));
}
var controller = this;
var path = controller.path();
Expand All @@ -56,7 +57,8 @@ Instrumentor.prototype.createVisitor = function (ast) {
storage: storage,
transformation: transformation,
globalScope: globalScope,
currentScope: currentScope
scopeManager: scopeManager,
currentScope: scopeStack[scopeStack.length - 1]
}, that.options));
assertionVisitor.enter(controller);
return undefined;
Expand Down Expand Up @@ -98,7 +100,7 @@ Instrumentor.prototype.createVisitor = function (ast) {
return resultTree;
} finally {
if (/Function/.test(currentNode.type)) {
currentScope = currentScope.upper;
scopeStack.pop();
}
}
}
Expand Down

0 comments on commit 5e9373f

Please sign in to comment.