Skip to content

Commit

Permalink
🌳: consider for loops as separate scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
merryman committed Feb 6, 2025
1 parent 7cb388d commit 565638b
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lively.ast/lib/mozilla-ast-visitors.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,36 @@ class ScopeVisitor extends Visitor {
return node;
}

visitForStatement (node, scope, path) {
const visitor = this;
// init is of types VariableDeclaration, Expression
if (node.init) {
node.init = visitor.accept(node.init, scope, path.concat(['init']));
}
// test is of types Expression
if (node.test) {
node.test = visitor.accept(node.test, scope, path.concat(['test']));
}
// update is of types Expression
if (node.update) {
node.update = visitor.accept(node.update, scope, path.concat(['update']));
}
// body is of types Statement
node.body = visitor.accept(node.body, this.newScope(node, scope), path.concat(['body']));
return node;
}

visitForInStatement (node, scope, path) {
const visitor = this;
// left is of types VariableDeclaration, Pattern
node.left = visitor.accept(node.left, scope, path.concat(['left']));
// right is of types Expression
node.right = visitor.accept(node.right, scope, path.concat(['right']));
// body is of types Statement
node.body = visitor.accept(node.body, this.newScope(node, scope), path.concat(['body']));
return node;
}

visitIfStatement (node, scope, path) {
const visitor = this;

Expand Down

0 comments on commit 565638b

Please sign in to comment.