Skip to content

Commit

Permalink
fix(semantic): ModuleRecord's indirect_export_entires missing reexpor…
Browse files Browse the repository at this point in the history
…ted imports
  • Loading branch information
Dunqing committed Mar 23, 2024
1 parent 1c07a99 commit 5e6292c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 17 deletions.
14 changes: 4 additions & 10 deletions crates/oxc_semantic/src/builder.rs
Expand Up @@ -7,7 +7,7 @@ use oxc_ast::{ast::*, AstKind, Trivias, Visit};
use oxc_diagnostics::Error;
use oxc_span::{CompactStr, SourceType, Span};
use oxc_syntax::{
module_record::{ExportLocalName, ModuleRecord},
module_record::{ExportImportName, ModuleRecord},
operator::AssignmentOperator,
};

Expand Down Expand Up @@ -324,18 +324,12 @@ impl<'a> SemanticBuilder<'a> {
}

fn add_export_flag_for_export_identifier(&mut self) {
self.module_record.local_export_entries.iter().for_each(|entry| match &entry.local_name {
ExportLocalName::Name(name_span) => {
if let Some(symbol_id) = self.scope.get_root_binding(name_span.name()) {
self.module_record.indirect_export_entries.iter().for_each(|entry| {
if let ExportImportName::Name(name) = &entry.import_name {
if let Some(symbol_id) = self.symbols.get_symbol_id_from_name(name.name()) {
self.symbols.union_flag(symbol_id, SymbolFlags::Export);
}
}
ExportLocalName::Default(span) => {
if let Some(symbol_id) = self.symbols.get_symbol_id_from_span(span) {
self.symbols.union_flag(symbol_id, SymbolFlags::Export);
}
}
ExportLocalName::Null => {}
});
}
}
Expand Down
14 changes: 7 additions & 7 deletions crates/oxc_semantic/src/module_record/builder.rs
Expand Up @@ -85,15 +85,14 @@ impl ModuleRecordBuilder {
for ee in export_entries {
// a. If ee.[[ModuleRequest]] is null, then
if ee.module_request.is_none() {
let local_name = match &ee.local_name {
ExportLocalName::Name(name) => Some(name),
let found_import_entry = match &ee.local_name {
ExportLocalName::Name(name) => self
.module_record
.import_entries
.iter()
.find(|entry| entry.local_name.name() == name.name()),
_ => None,
};
let found_import_entry = self
.module_record
.import_entries
.iter()
.find(|import_entry| Some(&import_entry.local_name) == local_name);
match found_import_entry {
// i. If ee.[[LocalName]] is not an element of importedBoundNames, then
None => {
Expand Down Expand Up @@ -130,6 +129,7 @@ impl ModuleRecordBuilder {
ImportImportName::NamespaceObject => unreachable!(),
},
export_name: ee.export_name.clone(),
span: ee.span,
..ExportEntry::default()
};
self.append_indirect_export_entry(export_entry);
Expand Down
27 changes: 27 additions & 0 deletions crates/oxc_semantic/src/module_record/mod.rs
Expand Up @@ -244,4 +244,31 @@ mod module_record_tests {
assert_eq!(module_record.local_export_entries.len(), 1);
assert_eq!(module_record.local_export_entries[0], export_entry);
}

#[test]
fn indirect_export_entries() {
let module_record =
build("import { x } from 'mod';export { x };export * as ns from 'mod';");
assert_eq!(module_record.indirect_export_entries.len(), 2);
assert_eq!(
module_record.indirect_export_entries[0],
ExportEntry {
module_request: Some(NameSpan::new("mod".into(), Span::new(18, 23))),
span: Span::new(33, 34),
import_name: ExportImportName::Name(NameSpan::new("x".into(), Span::new(9, 10))),
export_name: ExportExportName::Name(NameSpan::new("x".into(), Span::new(33, 34))),
local_name: ExportLocalName::Null,
}
);
assert_eq!(
module_record.indirect_export_entries[1],
ExportEntry {
module_request: Some(NameSpan::new("mod".into(), Span::new(57, 62))),
span: Span::new(0, 0),
import_name: ExportImportName::All,
export_name: ExportExportName::Name(NameSpan::new("ns".into(), Span::new(49, 51))),
local_name: ExportLocalName::Null,
}
);
}
}

0 comments on commit 5e6292c

Please sign in to comment.