Skip to content

ast-codegen: visit it.body.body orit.body in CatchClause? #4186

@Dunqing

Description

@Dunqing

CatchClause

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:

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

#[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 - Bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions