-
Notifications
You must be signed in to change notification settings - Fork 526
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app): use
IsolatingModuleFinalizer
for app output (#1317)
- Loading branch information
Showing
14 changed files
with
234 additions
and
61 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
crates/rolldown/src/module_finalizers/isolating/impl_visit_mut.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use oxc::ast::ast; | ||
use oxc::ast::VisitMut; | ||
|
||
use super::IsolatingModuleFinalizer; | ||
|
||
impl<'me, 'ast> VisitMut<'ast> for IsolatingModuleFinalizer<'me, 'ast> { | ||
fn visit_program(&mut self, _program: &mut ast::Program<'ast>) { | ||
// wrap the program within a function | ||
} | ||
} |
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,9 @@ | ||
use oxc::allocator::Allocator; | ||
use rolldown_common::AstScope; | ||
|
||
mod impl_visit_mut; | ||
|
||
pub struct IsolatingModuleFinalizer<'me, 'ast> { | ||
pub scope: &'me AstScope, | ||
pub alloc: &'ast Allocator, | ||
} |
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 +1,2 @@ | ||
pub mod isolating; | ||
pub mod scope_hoisting; |
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
16 changes: 16 additions & 0 deletions
16
crates/rolldown/tests/fixtures/function/format/app/multiple_entry_modules/_config.json
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,16 @@ | ||
{ | ||
"config": { | ||
"input": [ | ||
{ | ||
"name": "main", | ||
"import": "./main.js" | ||
}, | ||
{ | ||
"name": "other-entry", | ||
"import": "./other-entry.js" | ||
} | ||
], | ||
"format": "app" | ||
}, | ||
"expectExecuted": false | ||
} |
39 changes: 39 additions & 0 deletions
39
crates/rolldown/tests/fixtures/function/format/app/multiple_entry_modules/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,39 @@ | ||
--- | ||
source: crates/rolldown/tests/common/case.rs | ||
expression: content | ||
input_file: crates/rolldown/tests/fixtures/function/format/app/multiple_entry_modules | ||
--- | ||
# Assets | ||
|
||
## cube.mjs | ||
|
||
```js | ||
// square.js | ||
export default function square(x) { | ||
return x * x; | ||
} | ||
// cube.js | ||
import square from './square.js'; | ||
export default function cube(x) { | ||
return square(x) * x; | ||
} | ||
``` | ||
## main.mjs | ||
```js | ||
// hyper-cube.js | ||
import cube from './cube.js'; | ||
export default function hyperCube(x) { | ||
return cube(x) * x; | ||
} | ||
// main.js | ||
import hyperCube from './hyper-cube.js'; | ||
console.log(hyperCube(5)); | ||
``` | ||
## other-entry.mjs | ||
```js | ||
// other-entry.js | ||
import cube from './cube.js'; | ||
console.log(cube(5)); | ||
``` |
8 changes: 8 additions & 0 deletions
8
crates/rolldown/tests/fixtures/function/format/app/multiple_entry_modules/cube.js
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,8 @@ | ||
import square from './square.js'; | ||
|
||
// Everything used by both entry modules will become | ||
// a separate chunk that is imported by both entry | ||
// chunks to avoid code duplication | ||
export default function cube(x) { | ||
return square(x) * x; | ||
} |
7 changes: 7 additions & 0 deletions
7
crates/rolldown/tests/fixtures/function/format/app/multiple_entry_modules/hyper-cube.js
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,7 @@ | ||
import cube from './cube.js'; | ||
|
||
// This is only imported by one entry module and | ||
// shares a chunk with that module | ||
export default function hyperCube(x) { | ||
return cube(x) * x; | ||
} |
4 changes: 4 additions & 0 deletions
4
crates/rolldown/tests/fixtures/function/format/app/multiple_entry_modules/main.js
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,4 @@ | ||
// MULTIPLE ENTRY MODULES | ||
import hyperCube from './hyper-cube.js'; | ||
|
||
console.log(hyperCube(5)); |
4 changes: 4 additions & 0 deletions
4
crates/rolldown/tests/fixtures/function/format/app/multiple_entry_modules/other-entry.js
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,4 @@ | ||
// Additional entry modules create new chunks | ||
import cube from './cube.js'; | ||
|
||
console.log(cube(5)); |
4 changes: 4 additions & 0 deletions
4
crates/rolldown/tests/fixtures/function/format/app/multiple_entry_modules/square.js
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,4 @@ | ||
// This is also shared between the entry chunks | ||
export default function square(x) { | ||
return x * x; | ||
} |
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