-
-
Notifications
You must be signed in to change notification settings - Fork 845
feat(tree-shaking): track dynamic imports in object properties #15443
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
LingyuCoder
wants to merge
1
commit into
seal/unused-export-dynamic-import-tree-shaking
from
seal/unused-dynamic-import-tree-shaking
+220
−5
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
1 change: 1 addition & 0 deletions
1
...pack-test/configCases/tree-shaking/unused-object-property-dynamic-import-using/dispose.js
This file contains hidden or 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 const value = "resource disposed"; |
9 changes: 9 additions & 0 deletions
9
...rspack-test/configCases/tree-shaking/unused-object-property-dynamic-import-using/index.js
This file contains hidden or 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 @@ | ||
| import fs from "fs"; | ||
| import path from "path"; | ||
| import { disposalImport } from "./module"; | ||
|
|
||
| it("should keep dynamic imports used by implicit resource disposal", async () => { | ||
| const disposed = await disposalImport; | ||
| expect(disposed.value).toBe("resource disposed"); | ||
| expect(fs.existsSync(path.join(__dirname, "dispose.js"))).toBe(true); | ||
| }); |
9 changes: 9 additions & 0 deletions
9
...spack-test/configCases/tree-shaking/unused-object-property-dynamic-import-using/module.js
This file contains hidden or 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 @@ | ||
| export let disposalImport; | ||
|
|
||
| using resource = { | ||
| [Symbol.dispose]: () => { | ||
| disposalImport = import( | ||
| /* webpackChunkName: "dispose" */ "./dispose" | ||
| ); | ||
| }, | ||
| }; |
14 changes: 14 additions & 0 deletions
14
...est/configCases/tree-shaking/unused-object-property-dynamic-import-using/rspack.config.js
This file contains hidden or 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,14 @@ | ||
| /** @type {import("@rspack/core").Configuration} */ | ||
| module.exports = { | ||
| target: 'node', | ||
| output: { | ||
| chunkFilename: '[name].js', | ||
| }, | ||
| optimization: { | ||
| innerGraph: true, | ||
| minimize: false, | ||
| providedExports: true, | ||
| sideEffects: true, | ||
| usedExports: true, | ||
| }, | ||
| }; |
5 changes: 5 additions & 0 deletions
5
...-test/configCases/tree-shaking/unused-object-property-dynamic-import-using/test.filter.js
This file contains hidden or 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,5 @@ | ||
| const { | ||
| supportsUsing, | ||
| } = require("@rspack/test-tools/helper/legacy/supportsUsing"); | ||
|
|
||
| module.exports = () => supportsUsing(); |
1 change: 1 addition & 0 deletions
1
...est/configCases/tree-shaking/unused-object-property-dynamic-import/default-unused-lazy.js
This file contains hidden or 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 const value = "unused default dynamic import"; |
9 changes: 9 additions & 0 deletions
9
...ack-test/configCases/tree-shaking/unused-object-property-dynamic-import/default-unused.js
This file contains hidden or 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 @@ | ||
| import { effects } from "./module"; | ||
|
|
||
| export default { | ||
| id: effects.push("unused default"), | ||
| loader: () => | ||
| import( | ||
| /* webpackChunkName: "default-unused" */ "./default-unused-lazy" | ||
| ), | ||
| }; |
1 change: 1 addition & 0 deletions
1
...-test/configCases/tree-shaking/unused-object-property-dynamic-import/default-used-lazy.js
This file contains hidden or 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 const value = "used default dynamic import"; |
7 changes: 7 additions & 0 deletions
7
...spack-test/configCases/tree-shaking/unused-object-property-dynamic-import/default-used.js
This file contains hidden or 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 { effects } from "./module"; | ||
|
|
||
| export default { | ||
| id: effects.push("used default"), | ||
| loader: () => | ||
| import(/* webpackChunkName: "default-used" */ "./default-used-lazy"), | ||
| }; |
1 change: 1 addition & 0 deletions
1
tests/rspack-test/configCases/tree-shaking/unused-object-property-dynamic-import/eager.js
This file contains hidden or 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 const value = "eager dynamic import"; |
30 changes: 30 additions & 0 deletions
30
tests/rspack-test/configCases/tree-shaking/unused-object-property-dynamic-import/index.js
This file contains hidden or 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 @@ | ||
| import fs from "fs"; | ||
| import path from "path"; | ||
| import { effects, live, usedFeature } from "./module"; | ||
| import "./default-unused"; | ||
| import usedDefaultFeature from "./default-used"; | ||
|
|
||
| it("should omit dynamic imports in unused object property functions", async () => { | ||
| expect(live).toBe("live"); | ||
| expect(effects).toEqual([ | ||
| "unused arrow", | ||
| "unused function", | ||
| "unused nested loader", | ||
| "used loader", | ||
| "eager import", | ||
| "unused default", | ||
| "used default", | ||
| ]); | ||
|
|
||
| const used = await usedFeature.loader(); | ||
| expect(used.value).toBe("used dynamic import"); | ||
| const usedDefault = await usedDefaultFeature.loader(); | ||
| expect(usedDefault.value).toBe("used default dynamic import"); | ||
|
|
||
| expect(fs.existsSync(path.join(__dirname, "unused.js"))).toBe(false); | ||
| expect(fs.existsSync(path.join(__dirname, "unused-nested.js"))).toBe(false); | ||
| expect(fs.existsSync(path.join(__dirname, "default-unused.js"))).toBe(false); | ||
| expect(fs.existsSync(path.join(__dirname, "used.js"))).toBe(true); | ||
| expect(fs.existsSync(path.join(__dirname, "default-used.js"))).toBe(true); | ||
| expect(fs.existsSync(path.join(__dirname, "eager.js"))).toBe(true); | ||
| }); |
36 changes: 36 additions & 0 deletions
36
tests/rspack-test/configCases/tree-shaking/unused-object-property-dynamic-import/module.js
This file contains hidden or 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,36 @@ | ||
| export const effects = []; | ||
|
|
||
| function createId(id) { | ||
| effects.push(id); | ||
| return id; | ||
| } | ||
|
|
||
| export const unusedArrowFeature = { | ||
| id: createId("unused arrow"), | ||
| loader: () => import(/* webpackChunkName: "unused" */ "./unused"), | ||
| }; | ||
|
|
||
| export const unusedFunctionFeature = { | ||
| id: createId("unused function"), | ||
| loader: function () { | ||
| return import(/* webpackChunkName: "unused" */ "./unused"); | ||
| }, | ||
| }; | ||
|
|
||
| export const unusedNestedFeature = { | ||
| id: createId("unused nested loader"), | ||
| loader: () => () => | ||
| import(/* webpackChunkName: "unused-nested" */ "./unused"), | ||
| }; | ||
|
|
||
| export const usedFeature = { | ||
| id: createId("used loader"), | ||
| loader: () => import(/* webpackChunkName: "used" */ "./used"), | ||
| }; | ||
|
|
||
| export const unusedEagerFeature = { | ||
| id: createId("eager import"), | ||
| value: import(/* webpackChunkName: "eager" */ "./eager"), | ||
| }; | ||
|
|
||
| export const live = "live"; |
14 changes: 14 additions & 0 deletions
14
...pack-test/configCases/tree-shaking/unused-object-property-dynamic-import/rspack.config.js
This file contains hidden or 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,14 @@ | ||
| /** @type {import("@rspack/core").Configuration} */ | ||
| module.exports = { | ||
| target: 'node', | ||
| output: { | ||
| chunkFilename: '[name].js', | ||
| }, | ||
| optimization: { | ||
| innerGraph: true, | ||
| minimize: false, | ||
| providedExports: true, | ||
| sideEffects: true, | ||
| usedExports: true, | ||
| }, | ||
| }; |
1 change: 1 addition & 0 deletions
1
tests/rspack-test/configCases/tree-shaking/unused-object-property-dynamic-import/unused.js
This file contains hidden or 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 const value = "unused dynamic import"; |
1 change: 1 addition & 0 deletions
1
tests/rspack-test/configCases/tree-shaking/unused-object-property-dynamic-import/used.js
This file contains hidden or 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 const value = "used dynamic import"; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.