Skip to content

Commit

Permalink
refactor(semantic): simplify adding SymbolFlags::Export
Browse files Browse the repository at this point in the history
  • Loading branch information
Dunqing committed Jul 14, 2024
1 parent 83bd40d commit 9d365d8
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions crates/oxc_semantic/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) => {
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 9d365d8

Please sign in to comment.