Skip to content

Commit

Permalink
fix: add stmt info declare symbol for resolution found symbol (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
underfin authored Oct 25, 2023
1 parent 0f7c82c commit 50e191a
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 17 deletions.
41 changes: 24 additions & 17 deletions crates/rolldown/src/bundler/graph/linker.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use index_vec::IndexVec;
use oxc::{semantic::ReferenceId, span::Atom};
use oxc::span::Atom;
use rolldown_common::{
ExportsKind, ImportKind, LocalOrReExport, ModuleId, ResolvedExport, ResolvedExportRuntime,
SymbolRef, VirtualStmtInfo,
Expand All @@ -12,6 +12,7 @@ use crate::bundler::{
module::{
module::Module,
normal_module::{Resolution, UnresolvedSymbol, UnresolvedSymbols},
NormalModule,
},
};

Expand Down Expand Up @@ -279,21 +280,23 @@ impl<'graph> Linker<'graph> {
.collect::<FxHashMap<_, _>>();

#[allow(clippy::items_after_statements)]
fn create_local_symbol_and_reference(
fn create_local_symbol_for_found_resolution(
symbol_ref: SymbolRef,
exporter: ModuleId,
importer: &NormalModule,
importer_linker_module: &mut LinkerModule,
symbols: &mut Symbols,
) -> (SymbolRef, ReferenceId) {
let local_symbol = if symbol_ref.owner == exporter {
symbol_ref.symbol
) -> SymbolRef {
if symbol_ref.owner == importer.id {
symbol_ref
} else {
symbols.tables[exporter].create_symbol(Atom::from("#FACADE#"))
};
let symbol_ref_of_local: SymbolRef = (exporter, local_symbol).into();
symbols.union(symbol_ref_of_local, symbol_ref);
let ref_id = symbols.tables[exporter].create_reference(Some(local_symbol));

(symbol_ref_of_local, ref_id)
let local_symbol_ref = importer.generate_local_symbol(
Atom::from("#FACADE#"),
importer_linker_module,
symbols,
);
symbols.union(local_symbol_ref, symbol_ref);
local_symbol_ref
}
}

importer.named_exports.keys().for_each(|exported| {
Expand All @@ -307,10 +310,11 @@ impl<'graph> Linker<'graph> {
}
Resolution::Ambiguous => panic!("named export must be resolved"),
Resolution::Found(ext) => {
let tmp = create_local_symbol_and_reference(ext, importer.id, symbols);
let local_symbol_ref =
create_local_symbol_for_found_resolution(ext, importer, linker_module, symbols);
linker_module
.resolved_exports
.insert(exported.clone(), ResolvedExport::Symbol(tmp.0));
.insert(exported.clone(), ResolvedExport::Symbol(local_symbol_ref));
}
Resolution::Runtime(symbol_ref) => {
let local_symbol_ref = if importer.is_entry {
Expand All @@ -329,8 +333,11 @@ impl<'graph> Linker<'graph> {
resolutions.into_iter().for_each(|(exported, left)| match left {
Resolution::None => panic!("shouldn't has left which is None"),
Resolution::Found(ext) => {
let tmp = create_local_symbol_and_reference(ext, importer.id, symbols);
linker_module.resolved_exports.insert(exported.clone(), ResolvedExport::Symbol(tmp.0));
let local_symbol_ref =
create_local_symbol_for_found_resolution(ext, importer, linker_module, symbols);
linker_module
.resolved_exports
.insert(exported.clone(), ResolvedExport::Symbol(local_symbol_ref));
}
Resolution::Ambiguous => {}
Resolution::Runtime(symbol_ref) => {
Expand Down
1 change: 1 addition & 0 deletions crates/rolldown/tests/fixtures/reexport_star/a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const abc = undefined
30 changes: 30 additions & 0 deletions crates/rolldown/tests/fixtures/reexport_star/artifacts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
source: crates/rolldown/tests/common/case.rs
expression: content
input_file: crates/rolldown/tests/fixtures/reexport_star
---
# 2.js

```js
// a.js
var a_ns = {
get abc() { return abc }
};
const abc = undefined
```
# entry.js

```js
// entry.js
export { a_ns as a };
```
# main.js

```js
// main.js
export { a_ns as a };
```
1 change: 1 addition & 0 deletions crates/rolldown/tests/fixtures/reexport_star/entry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * as a from './a'
1 change: 1 addition & 0 deletions crates/rolldown/tests/fixtures/reexport_star/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * as a from './a'
14 changes: 14 additions & 0 deletions crates/rolldown/tests/fixtures/reexport_star/test.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"input": {
"input": [
{
"name": "main",
"import": "main.js"
},
{
"name": "entry",
"import": "entry.js"
}
]
}
}

0 comments on commit 50e191a

Please sign in to comment.