Skip to content

Commit

Permalink
fixed files form Closure #49
Browse files Browse the repository at this point in the history
  • Loading branch information
tdurieux committed Mar 7, 2017
1 parent 7dfd530 commit 253fdb3
Showing 1 changed file with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,6 @@ public void enterScope(NodeTraversal t) {
renamer = nameStack.peek().forChildScope();
}

if (declarationRoot.getType() == Token.FUNCTION) {
for (Node c = declarationRoot.getFirstChild().getNext().getFirstChild(); c != null; c = c.getNext()) {
String name = c.getString();
renamer.addDeclaredName(name);
}
Node functionBody = declarationRoot.getLastChild();
findDeclaredNames(functionBody, null, renamer);
} else
if (declarationRoot.getType() != Token.FUNCTION) {
// Add the block declarations
findDeclaredNames(declarationRoot, null, renamer);
Expand Down Expand Up @@ -127,11 +119,22 @@ public boolean shouldTraverse(NodeTraversal t, Node n, Node parent) {
renamer.addDeclaredName(name);
}

nameStack.push(renamer);
}
break;

case Token.LP: {
Renamer renamer = nameStack.peek().forChildScope();

// Add the function parameters
for (Node c = n.getFirstChild(); c != null; c = c.getNext()) {
String name = c.getString();
renamer.addDeclaredName(name);
}

// Add the function body declarations
Node functionBody = n.getNext();
findDeclaredNames(functionBody, null, renamer);

nameStack.push(renamer);
}
Expand Down Expand Up @@ -170,13 +173,16 @@ public void visit(NodeTraversal t, Node n, Node parent) {

case Token.FUNCTION:
// Remove the function body scope
nameStack.pop();
// Remove function recursive name (if any).
nameStack.pop();
break;

case Token.LP:
// Note: The parameters and function body variables live in the
// same scope, we introduce the scope when in the "shouldTraverse"
// visit of LP, but remove it when when we exit the function above.
break;

case Token.CATCH:
// Remove catch except name from the stack of names.
Expand Down

0 comments on commit 253fdb3

Please sign in to comment.