refactor(ast): scope is created only if CatchClause has param (#4346)

close: #4345
This commit is contained in:
Dunqing 2024-07-18 19:14:34 +00:00
parent f8565ae3cd
commit 59aea73daf
3 changed files with 15 additions and 5 deletions

View file

@ -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"))]

View file

@ -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);
}

View file

@ -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);
}