Skip to content

Commit

Permalink
refactor: bind class expression in enter_scope
Browse files Browse the repository at this point in the history
  • Loading branch information
Dunqing committed Jul 14, 2024
1 parent 04cffb4 commit 9adbb61
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions crates/oxc_semantic/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,16 @@ impl<'a> SemanticBuilder<'a> {
self.symbols.union_flag(symbol_id, SymbolFlags::Export);
}
}

fn bind_class_expression(&mut self) {
if let AstKind::Class(class) = self.nodes.kind(self.current_node_id) {
if class.is_expression() {
// We must to bind class expression when enter BindingIdentifier,
// because we should add binding to current scope
class.bind(self);
}
}
}
}

impl<'a> Visit<'a> for SemanticBuilder<'a> {
Expand Down Expand Up @@ -455,6 +465,10 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
if self.unresolved_references.len() <= self.current_scope_depth {
self.unresolved_references.push(UnresolvedReferences::default());
}

if !flags.is_top() {
self.bind_class_expression();
}
}

fn leave_scope(&mut self) {
Expand Down Expand Up @@ -1546,20 +1560,6 @@ impl<'a> SemanticBuilder<'a> {
AstKind::ExportSpecifier(s) if s.export_kind.is_type() => {
self.current_reference_flag = ReferenceFlag::Type;
}
AstKind::BindingIdentifier(_) => {
if let Some(node) = self.nodes.parent_node(self.current_node_id) {
if let AstKind::Class(class) = node.kind() {
if class.is_expression() {
// We must to bind class expression when enter BindingIdentifier,
// because we should add binding to current scope
let previous_node_id = self.current_node_id;
self.current_node_id = node.id();
class.bind(self);
self.current_node_id = previous_node_id;
}
}
}
}
AstKind::ImportSpecifier(specifier) => {
specifier.bind(self);
}
Expand Down

0 comments on commit 9adbb61

Please sign in to comment.