Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(semantic): missing SymbolFlags::Export when identifier used in ExportDefaultDeclaration #2837

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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