Skip to content

Commit

Permalink
fix(semantic): missing SymbolFlags::Export when identifier used in Ex…
Browse files Browse the repository at this point in the history
…portDefaultDeclaration (#2837)
  • Loading branch information
Dunqing committed Mar 27, 2024
1 parent 528744c commit 947a9f0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
20 changes: 17 additions & 3 deletions crates/oxc_semantic/src/builder.rs
Expand Up @@ -7,6 +7,7 @@ use oxc_ast::{ast::*, AstKind, Trivias, Visit};
use oxc_diagnostics::Error;
use oxc_span::{CompactStr, SourceType, Span};
use oxc_syntax::{
identifier::is_identifier_name,
module_record::{ExportImportName, ExportLocalName, ModuleRecord},
operator::AssignmentOperator,
};
Expand Down Expand Up @@ -333,10 +334,23 @@ impl<'a> SemanticBuilder<'a> {
});

self.module_record.local_export_entries.iter().for_each(|entry| {
if let ExportLocalName::Name(name_span) = &entry.local_name {
if let Some(symbol_id) = self.scope.get_root_binding(name_span.name()) {
self.symbols.union_flag(symbol_id, SymbolFlags::Export);
match &entry.local_name {
ExportLocalName::Name(name_span) => {
if let Some(symbol_id) = self.scope.get_root_binding(name_span.name()) {
self.symbols.union_flag(symbol_id, SymbolFlags::Export);
}
}
ExportLocalName::Default(_) => {
// export default identifier
// ^^^^^^^^^^
let identifier = entry.span.source_text(self.source_text);
if is_identifier_name(identifier) {
if let Some(symbol_id) = self.scope.get_root_binding(identifier) {
self.symbols.union_flag(symbol_id, SymbolFlags::Export);
}
}
}
ExportLocalName::Null => {}
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_semantic/tests/symbols.rs
Expand Up @@ -92,7 +92,7 @@ fn test_export_flag() {
let tester = SemanticTester::js(
"
const a = 1;
export { a, b, c as d };
export { a, b as d };
class b {}
export default c;
function c() {}
Expand Down

0 comments on commit 947a9f0

Please sign in to comment.