Skip to content

Commit

Permalink
refactor(ast): scope is created only if CatchClause has param (#4346)
Browse files Browse the repository at this point in the history
close: #4345
  • Loading branch information
Dunqing committed Jul 18, 2024
1 parent f8565ae commit 59aea73
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion crates/oxc_ast/src/ast/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1300,7 +1300,7 @@ pub struct TryStatement<'a> {
}

#[visited_node]
#[scope(flags(ScopeFlags::CatchClause))]
#[scope(flags(ScopeFlags::CatchClause), if(self.param.is_some()))]
#[derive(Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[cfg_attr(feature = "serialize", serde(tag = "type"))]
Expand Down
9 changes: 7 additions & 2 deletions crates/oxc_ast/src/generated/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3701,12 +3701,17 @@ pub mod walk {
pub fn walk_catch_clause<'a, V: Visit<'a>>(visitor: &mut V, it: &CatchClause<'a>) {
let kind = AstKind::CatchClause(visitor.alloc(it));
visitor.enter_node(kind);
visitor.enter_scope(ScopeFlags::CatchClause, &it.scope_id);
let scope_events_cond = it.param.is_some();
if scope_events_cond {
visitor.enter_scope(ScopeFlags::CatchClause, &it.scope_id);
}
if let Some(param) = &it.param {
visitor.visit_catch_parameter(param);
}
visitor.visit_block_statement(&it.body);
visitor.leave_scope();
if scope_events_cond {
visitor.leave_scope();
}
visitor.leave_node(kind);
}

Expand Down
9 changes: 7 additions & 2 deletions crates/oxc_ast/src/generated/visit_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3913,12 +3913,17 @@ pub mod walk_mut {
pub fn walk_catch_clause<'a, V: VisitMut<'a>>(visitor: &mut V, it: &mut CatchClause<'a>) {
let kind = AstType::CatchClause;
visitor.enter_node(kind);
visitor.enter_scope(ScopeFlags::CatchClause, &it.scope_id);
let scope_events_cond = it.param.is_some();
if scope_events_cond {
visitor.enter_scope(ScopeFlags::CatchClause, &it.scope_id);
}
if let Some(param) = &mut it.param {
visitor.visit_catch_parameter(param);
}
visitor.visit_block_statement(&mut it.body);
visitor.leave_scope();
if scope_events_cond {
visitor.leave_scope();
}
visitor.leave_node(kind);
}

Expand Down

0 comments on commit 59aea73

Please sign in to comment.