Skip to content

Commit

Permalink
🌳: consider if statement blocks as separate scopes
Browse files Browse the repository at this point in the history
Previously we would consider if/else blocks to be of the same scope as the aprent, leading to incorrect transformations in case of let and const statements.
  • Loading branch information
merryman committed Feb 6, 2025
1 parent af79a91 commit 7cb388d
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 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,22 @@ class ScopeVisitor extends Visitor {
return node;
}

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

node.test = visitor.accept(node.test, scope, path.concat(['test']));

const consequentScope = this.newScope(node, scope);
node.consequent = visitor.accept(node.consequent, consequentScope, path.concat(['consequent']));

if (node.alternate) {
const alternateScope = this.newScope(node, scope);
node.alternate = visitor.accept(node.alternate, alternateScope, path.concat(['alternate']));
}

return node;
}

visitLabeledStatement (node, scope, path) {
const visitor = this;
// ignore label
Expand Down

0 comments on commit 7cb388d

Please sign in to comment.