From 9d365d81e868624c9a04b925bd214362a958c2c7 Mon Sep 17 00:00:00 2001 From: Dunqing Date: Sun, 14 Jul 2024 18:34:33 +0800 Subject: [PATCH] refactor(semantic): simplify adding SymbolFlags::Export --- crates/oxc_semantic/src/builder.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/crates/oxc_semantic/src/builder.rs b/crates/oxc_semantic/src/builder.rs index 1be4ce0963df1a..f448ccd15e84b5 100644 --- a/crates/oxc_semantic/src/builder.rs +++ b/crates/oxc_semantic/src/builder.rs @@ -1539,8 +1539,17 @@ impl<'a> SemanticBuilder<'a> { /* cfg */ match kind { - AstKind::ExportDefaultDeclaration(_) => { - self.current_symbol_flags |= SymbolFlags::Export; + AstKind::ExportDefaultDeclaration(decl) => { + // Only if the declaration has an id, we mark it as an export + if match &decl.declaration { + ExportDefaultDeclarationKind::FunctionDeclaration(ref func) => { + func.id.is_some() + } + ExportDefaultDeclarationKind::ClassDeclaration(ref class) => class.id.is_some(), + _ => true, + } { + self.current_symbol_flags |= SymbolFlags::Export; + } } AstKind::ExportNamedDeclaration(decl) => { self.current_symbol_flags |= SymbolFlags::Export; @@ -1588,7 +1597,6 @@ impl<'a> SemanticBuilder<'a> { if class.is_declaration() { class.bind(self); } - self.current_symbol_flags -= SymbolFlags::Export; self.make_all_namespaces_valuelike(); } AstKind::ClassBody(body) => { @@ -1608,9 +1616,6 @@ impl<'a> SemanticBuilder<'a> { AstKind::BindingRestElement(element) => { element.bind(self); } - AstKind::FormalParameters(_) => { - self.current_symbol_flags -= SymbolFlags::Export; - } AstKind::FormalParameter(param) => { param.bind(self); } @@ -1699,11 +1704,10 @@ impl<'a> SemanticBuilder<'a> { self.current_node_flags -= NodeFlags::Class; self.class_table_builder.pop_class(); } - AstKind::ExportDefaultDeclaration(_) => { + AstKind::BindingIdentifier(_) => { self.current_symbol_flags -= SymbolFlags::Export; } AstKind::ExportNamedDeclaration(decl) => { - self.current_symbol_flags -= SymbolFlags::Export; if decl.export_kind.is_type() { self.current_reference_flag -= ReferenceFlag::Type; }