-
-
Notifications
You must be signed in to change notification settings - Fork 778
Closed
Labels
C-bugCategory - BugCategory - Bug
Description
CatchClause
oxc/crates/oxc_ast/src/ast/js.rs
Lines 1307 to 1313 in 07506ec
| pub struct CatchClause<'a> { | |
| #[cfg_attr(feature = "serialize", serde(flatten))] | |
| pub span: Span, | |
| pub param: Option<CatchParameter<'a>>, | |
| pub body: Box<'a, BlockStatement<'a>>, | |
| pub scope_id: Cell<Option<ScopeId>>, | |
| } |
In semantic builder:
oxc/crates/oxc_semantic/src/builder.rs
Lines 1351 to 1363 in 07506ec
| fn visit_catch_clause(&mut self, clause: &CatchClause<'a>) { | |
| let kind = AstKind::CatchClause(self.alloc(clause)); | |
| self.enter_scope(ScopeFlags::empty(), &clause.scope_id); | |
| clause.scope_id.set(Some(self.current_scope_id)); | |
| self.enter_node(kind); | |
| if let Some(param) = &clause.param { | |
| self.visit_catch_parameter(param); | |
| } | |
| self.visit_statements(&clause.body.body); | |
| self.leave_node(kind); | |
| self.leave_scope(); | |
| } | |
In Visit
oxc/crates/oxc_ast/src/generated/visit.rs
Lines 3691 to 3707 in 07506ec
| #[inline] | |
| pub fn walk_catch_clause<'a, V: Visit<'a>>(visitor: &mut V, it: &CatchClause<'a>) { | |
| let scope_events_cond = it.param.is_some(); | |
| if scope_events_cond { | |
| visitor.enter_scope(ScopeFlags::empty(), &it.scope_id); | |
| } | |
| let kind = AstKind::CatchClause(visitor.alloc(it)); | |
| visitor.enter_node(kind); | |
| if let Some(param) = &it.param { | |
| visitor.visit_catch_parameter(param); | |
| } | |
| visitor.visit_block_statement(&it.body); | |
| visitor.leave_node(kind); | |
| if scope_events_cond { | |
| visitor.leave_scope(); | |
| } | |
| } |
The difference between them is that one calls visit_statements(it.body.body) and the other visit_block_statements(it.body)
Because we will create a scope within the CatchClause, we do not need to create a scope again in the BlockStatement.
Is there a better way to resolve this problem? Such as changing the body to Vec<'a, Statements<'a>>
Metadata
Metadata
Assignees
Labels
C-bugCategory - BugCategory - Bug