From 9adbb6175a8dabd0e973bc773910f2f3092551eb Mon Sep 17 00:00:00 2001 From: Dunqing Date: Sun, 14 Jul 2024 11:18:10 +0800 Subject: [PATCH] refactor: bind class expression in enter_scope --- crates/oxc_semantic/src/builder.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/crates/oxc_semantic/src/builder.rs b/crates/oxc_semantic/src/builder.rs index 0e712bd6cc215..e57c95c480343 100644 --- a/crates/oxc_semantic/src/builder.rs +++ b/crates/oxc_semantic/src/builder.rs @@ -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> { @@ -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) { @@ -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); }