Skip to content

Commit

Permalink
refactor(ast): enter node before scope (#4347)
Browse files Browse the repository at this point in the history
close: #4276
  • Loading branch information
Dunqing committed Jul 18, 2024
1 parent 59aea73 commit 58f6ec2
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions crates/oxc_semantic/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -827,12 +827,12 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {

fn visit_for_statement(&mut self, stmt: &ForStatement<'a>) {
let kind = AstKind::ForStatement(self.alloc(stmt));
self.enter_node(kind);
let is_lexical_declaration =
stmt.init.as_ref().is_some_and(ForStatementInit::is_lexical_declaration);
if is_lexical_declaration {
self.enter_scope(ScopeFlags::empty(), &stmt.scope_id);
}
self.enter_node(kind);
if let Some(init) = &stmt.init {
self.visit_for_statement_init(init);
}
Expand Down Expand Up @@ -890,19 +890,19 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
});
/* cfg */

self.leave_node(kind);
if is_lexical_declaration {
self.leave_scope();
}
self.leave_node(kind);
}

fn visit_for_in_statement(&mut self, stmt: &ForInStatement<'a>) {
let kind = AstKind::ForInStatement(self.alloc(stmt));
self.enter_node(kind);
let is_lexical_declaration = stmt.left.is_lexical_declaration();
if is_lexical_declaration {
self.enter_scope(ScopeFlags::empty(), &stmt.scope_id);
}
self.enter_node(kind);

self.visit_for_statement_left(&stmt.left);

Expand Down Expand Up @@ -954,19 +954,19 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
});
/* cfg */

self.leave_node(kind);
if is_lexical_declaration {
self.leave_scope();
}
self.leave_node(kind);
}

fn visit_for_of_statement(&mut self, stmt: &ForOfStatement<'a>) {
let kind = AstKind::ForOfStatement(self.alloc(stmt));
self.enter_node(kind);
let is_lexical_declaration = stmt.left.is_lexical_declaration();
if is_lexical_declaration {
self.enter_scope(ScopeFlags::empty(), &stmt.scope_id);
}
self.enter_node(kind);

self.visit_for_statement_left(&stmt.left);

Expand Down Expand Up @@ -1017,10 +1017,10 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
});
/* cfg */

self.leave_node(kind);
if is_lexical_declaration {
self.leave_scope();
}
self.leave_node(kind);
}

fn visit_if_statement(&mut self, stmt: &IfStatement<'a>) {
Expand Down

0 comments on commit 58f6ec2

Please sign in to comment.