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 274df4b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
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 274df4b

Please sign in to comment.