Skip to content

Commit

Permalink
fix: catch caluse
Browse files Browse the repository at this point in the history
  • Loading branch information
Dunqing committed Jul 11, 2024
1 parent 27590a7 commit 97fce04
Show file tree
Hide file tree
Showing 2 changed files with 760 additions and 24 deletions.
26 changes: 13 additions & 13 deletions crates/oxc_semantic/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,19 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {

self.current_scope_id = self.scope.add_scope(parent_scope_id, flags);
scope_id.set(Some(self.current_scope_id));

// TODO: replace node-based check with scope-based
if !flags.is_top()
&& matches!(self.nodes.parent_kind(self.current_node_id), Some(AstKind::CatchClause(_)))
{
// Clone the `CatchClause` bindings and add them to the current scope.
// to make it easier to check redeclare errors.
if let Some(parent_scope_id) = parent_scope_id {
let bindings = self.scope.get_bindings(parent_scope_id).clone();
self.scope.get_bindings_mut(self.current_scope_id).extend(bindings);
}
}

self.unresolved_references.push(UnresolvedReferences::default());
}

Expand Down Expand Up @@ -1693,19 +1706,6 @@ impl<'a> SemanticBuilder<'a> {
AstKind::YieldExpression(_) => {
self.set_function_node_flag(NodeFlags::HasYield);
}
AstKind::BlockStatement(_) => {
if matches!(
self.nodes.parent_kind(self.current_node_id),
Some(AstKind::CatchClause(_))
) {
// Clone the `CatchClause` bindings and add them to the current scope.
// to make it easier to check redeclare errors.
if let Some(parent_scope_id) = self.scope.get_parent_id(self.current_scope_id) {
let bindings = self.scope.get_bindings(parent_scope_id).clone();
self.scope.get_bindings_mut(self.current_scope_id).extend(bindings);
}
}
}
_ => {}
}
}
Expand Down
Loading

0 comments on commit 97fce04

Please sign in to comment.