-
Notifications
You must be signed in to change notification settings - Fork 503
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: only import needed runtime symbols (#324)
<!-- Thank you for contributing! --> ### Description The fix is done by more delicate analyzing the module type and import kind. This also fixes #319 (comment). <!-- Please insert your description here and provide especially info about the "what" this PR is solving --> ### Test Plan <!-- e.g. is there anything you'd like reviewers to focus on? --> ---
- Loading branch information
Showing
20 changed files
with
169 additions
and
99 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
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
4 changes: 4 additions & 0 deletions
4
crates/rolldown/tests/fixtures/compat/esm_require_cjs/_test.mjs
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 @@ | ||
import assert from 'assert' | ||
import { cjs } from './dist/main.mjs' | ||
|
||
assert.equal(cjs, 'cjs') |
26 changes: 26 additions & 0 deletions
26
crates/rolldown/tests/fixtures/compat/esm_require_cjs/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,26 @@ | ||
--- | ||
source: crates/rolldown/tests/common/case.rs | ||
expression: content | ||
input_file: crates/rolldown/tests/fixtures/compat/esm_require_cjs | ||
--- | ||
# Assets | ||
|
||
## main.mjs | ||
|
||
```js | ||
import { __commonJS } from "./_rolldown_runtime.mjs"; | ||
// cjs.js | ||
var require_cjs = __commonJS({ | ||
'cjs.js'(exports, module) { | ||
module.exports = 'cjs' | ||
} | ||
}); | ||
// main.js | ||
const cjs = require_cjs() | ||
export { cjs }; | ||
``` |
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 @@ | ||
module.exports = 'cjs' |
3 changes: 3 additions & 0 deletions
3
crates/rolldown/tests/fixtures/compat/esm_require_cjs/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,3 @@ | ||
const cjs = require('./cjs') | ||
|
||
export { cjs } |
1 change: 1 addition & 0 deletions
1
crates/rolldown/tests/fixtures/compat/esm_require_cjs/test.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 @@ | ||
{} |
4 changes: 4 additions & 0 deletions
4
crates/rolldown/tests/fixtures/compat/esm_require_esm/_test.mjs
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 @@ | ||
import assert from 'assert' | ||
import { esm } from './dist/main.mjs' | ||
|
||
assert.equal(esm.default, 'esm') |
31 changes: 31 additions & 0 deletions
31
crates/rolldown/tests/fixtures/compat/esm_require_esm/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,31 @@ | ||
--- | ||
source: crates/rolldown/tests/common/case.rs | ||
assertion_line: 97 | ||
expression: content | ||
input_file: crates/rolldown/tests/fixtures/compat/esm_require_esm | ||
--- | ||
# Assets | ||
|
||
## main.mjs | ||
|
||
```js | ||
import { __esm, __toCommonJS } from "./_rolldown_runtime.mjs"; | ||
// esm.js | ||
var esm_default; | ||
var esm_ns = { | ||
get default() { return esm_default } | ||
}; | ||
var init_esm = __esm({ | ||
'esm.js'() { | ||
esm_default = 'esm' | ||
} | ||
}); | ||
// main.js | ||
const esm = (init_esm(), __toCommonJS(esm_ns)) | ||
export { esm }; | ||
``` |
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 @@ | ||
export default 'esm' |
3 changes: 3 additions & 0 deletions
3
crates/rolldown/tests/fixtures/compat/esm_require_esm/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,3 @@ | ||
const esm = require('./esm') | ||
|
||
export { esm } |
1 change: 1 addition & 0 deletions
1
crates/rolldown/tests/fixtures/compat/esm_require_esm/test.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 @@ | ||
{} |
26 changes: 26 additions & 0 deletions
26
crates/rolldown/tests/fixtures/compat/esm_require_esm_unused/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,26 @@ | ||
--- | ||
source: crates/rolldown/tests/common/case.rs | ||
expression: content | ||
input_file: crates/rolldown/tests/fixtures/compat/esm_require_esm_unused | ||
--- | ||
# Assets | ||
|
||
## main.mjs | ||
|
||
```js | ||
import { __esm, __toCommonJS } from "./_rolldown_runtime.mjs"; | ||
// esm.js | ||
var esm_default; | ||
var esm_ns = { | ||
get default() { return esm_default } | ||
}; | ||
var init_esm = __esm({ | ||
'esm.js'() { | ||
esm_default = 'esm' | ||
} | ||
}); | ||
// main.js | ||
init_esm() | ||
``` |
1 change: 1 addition & 0 deletions
1
crates/rolldown/tests/fixtures/compat/esm_require_esm_unused/esm.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 @@ | ||
export default 'esm' |
1 change: 1 addition & 0 deletions
1
crates/rolldown/tests/fixtures/compat/esm_require_esm_unused/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 @@ | ||
require('./esm') |
1 change: 1 addition & 0 deletions
1
crates/rolldown/tests/fixtures/compat/esm_require_esm_unused/test.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 @@ | ||
{} |
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