-
Notifications
You must be signed in to change notification settings - Fork 548
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* wip: basic code splitting * Fix tests * Adjust location of `chunk_graph.rs` * Fix import from source * snapshots * skip rollup test * render chunk exports * Update status * print test status in ci * enable more test
- Loading branch information
Showing
32 changed files
with
267 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use string_wizard::MagicString; | ||
|
||
use crate::bundler::graph::graph::Graph; | ||
|
||
use super::chunk::Chunk; | ||
|
||
impl Chunk { | ||
pub fn render_exports_for_esm(&self, graph: &Graph) -> Option<MagicString<'static>> { | ||
if self.exports_to_other_chunks.is_empty() { | ||
return None; | ||
} | ||
let mut s = MagicString::new(""); | ||
let mut export_items = self | ||
.exports_to_other_chunks | ||
.iter() | ||
.map(|(export_ref, alias)| { | ||
let canonical_ref = graph.symbols.par_get_canonical_ref(*export_ref); | ||
let canonical_name = &self.canonical_names[&canonical_ref]; | ||
if canonical_name == alias { | ||
format!("{canonical_name}") | ||
} else { | ||
format!("{canonical_name} as {alias}") | ||
} | ||
}) | ||
.collect::<Vec<_>>(); | ||
export_items.sort(); | ||
s.append(format!("export {{ {} }};", export_items.join(", "),)); | ||
Some(s) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use string_wizard::MagicString; | ||
|
||
use crate::bundler::{chunk_graph::ChunkGraph, graph::graph::Graph}; | ||
|
||
use super::chunk::Chunk; | ||
|
||
impl Chunk { | ||
pub fn render_imports_for_esm( | ||
&self, | ||
graph: &Graph, | ||
chunk_graph: &ChunkGraph, | ||
) -> MagicString<'static> { | ||
let mut s = MagicString::new(""); | ||
self.imports_from_other_chunks.iter().for_each(|(chunk_id, items)| { | ||
let chunk = &chunk_graph.chunks[*chunk_id]; | ||
let mut import_items = items | ||
.iter() | ||
.map(|item| { | ||
let imported = chunk | ||
.canonical_names | ||
.get(&graph.symbols.par_get_canonical_ref(item.import_ref)) | ||
.cloned() | ||
.unwrap(); | ||
let alias = item.export_alias.as_ref().unwrap(); | ||
if imported == alias { | ||
format!("{imported}") | ||
} else { | ||
format!("{imported} as {alias}") | ||
} | ||
}) | ||
.collect::<Vec<_>>(); | ||
import_items.sort(); | ||
s.append(format!( | ||
"import {{ {} }} from \"./{}\";", | ||
import_items.join(", "), | ||
chunk.file_name.as_ref().unwrap() | ||
)); | ||
}); | ||
s | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...rolldown/src/bundler/chunk/chunk_graph.rs → crates/rolldown/src/bundler/chunk_graph.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
pub mod bitset; | ||
pub mod bundle; | ||
mod chunk_graph; | ||
mod graph; | ||
mod module; | ||
pub mod options; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
32 changes: 32 additions & 0 deletions
32
crates/rolldown/tests/esbuild/splitting/assign-to-local/artifacts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
source: crates/rolldown/tests/common/case.rs | ||
expression: content | ||
input_file: crates/rolldown/tests/esbuild/splitting/assign-to-local | ||
--- | ||
# 2.js | ||
|
||
```js | ||
// shared.js | ||
let foo | ||
function setFoo(value) { | ||
foo = value | ||
} | ||
export { foo, setFoo }; | ||
``` | ||
# a.js | ||
|
||
```js | ||
import { foo, setFoo } from "./2.js"; | ||
// a.js | ||
setFoo(123) | ||
console.log(foo) | ||
``` | ||
# b.js | ||
|
||
```js | ||
import { foo } from "./2.js"; | ||
// b.js | ||
console.log(foo) | ||
``` |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.