Skip to content

Commit

Permalink
refactor: stop using scope.upper to avoid potential unmatch on leavin…
Browse files Browse the repository at this point in the history
…g node

refs #36
  • Loading branch information
twada committed May 20, 2017
1 parent a10876d commit ce58d1f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
11 changes: 6 additions & 5 deletions lib/assertion-visitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,7 @@ AssertionVisitor.prototype.verifyNotInstrumented = function (currentNode) {
};

AssertionVisitor.prototype.createNewRecorder = function (controller) {
var currentScope = this.options.currentScope;
var currentBlock = findBlockedScope(currentScope).block;
var currentBlock = findBlockedScope(this.options.scopeStack).block;
var scopeBlockEspath = findEspathOfAncestorNode(currentBlock, controller);
var recorderConstructorName = this.getRecorderConstructorName(controller);
var recorderVariableName = this.options.transformation.generateUniqueName('rec');
Expand Down Expand Up @@ -345,9 +344,11 @@ function newNodeWithLocationCopyOf (original) {
};
}

function findBlockedScope (scope) {
if (isArrowFunctionWithConciseBody(scope.block)) {
return findBlockedScope(scope.upper);
function findBlockedScope (scopeStack) {
var lastIndex = scopeStack.length - 1;
var scope = scopeStack[lastIndex];
if (!scope.block || isArrowFunctionWithConciseBody(scope.block)) {
return findBlockedScope(scopeStack.slice(0, lastIndex));
}
return scope;
}
Expand Down
3 changes: 1 addition & 2 deletions lib/instrumentor.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ Instrumentor.prototype.createVisitor = function (ast) {
storage: storage,
transformation: transformation,
globalScope: globalScope,
scopeManager: scopeManager,
currentScope: scopeStack[scopeStack.length - 1]
scopeStack: scopeStack
}, that.options));
assertionVisitor.enter(controller);
return undefined;
Expand Down

0 comments on commit ce58d1f

Please sign in to comment.