Skip to content

Commit

Permalink
fix(side effects): should optimize for same target export (#8371)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahabhgk authored Nov 8, 2024
1 parent dfbe05f commit 1baa554
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion crates/rspack_core/src/exports_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1414,7 +1414,7 @@ impl ExportInfo {
.next()
.expect("should have export info target"); // refer https://github.com/webpack/webpack/blob/ac7e531436b0d47cd88451f497cdfd0dad41535d/lib/ExportsInfo.js#L1388-L1394
if original_target.dependency.as_ref() == Some(&target.dependency)
|| original_target.export == target.export
&& original_target.export == target.export
{
return None;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { value } from "./lib/index"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import * as values from "./const"

it("should generate correct export for dynamic reexports (dynamic cjs)", () => {
values;
expect(values.value).toBe(42);
})
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const value = 42;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
throw new Error("Boom!");
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./error"
export * from "./const"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"sideEffects": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**@type {import("@rspack/core").Configuration}*/
module.exports = {
optimization: {
sideEffects: true,
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -1780,6 +1780,7 @@ modules by path ./node_modules/pmodule/*.js 232 bytes
esm import specifier pmodule ./index.js
esm export ./c ./node_modules/pmodule/b.js
esm export import specifier ./c ./node_modules/pmodule/b.js
esm export import specifier ./b ./node_modules/pmodule/index.js
./node_modules/pmodule/a.js 60 bytes [orphan] [built]
[module unused]
esm export ./a ./node_modules/pmodule/index.js
Expand All @@ -1789,7 +1790,6 @@ modules by path ./node_modules/pmodule/*.js 232 bytes
esm export ./b ./node_modules/pmodule/index.js
esm export import specifier ./b ./node_modules/pmodule/index.js
esm export import specifier ./b ./node_modules/pmodule/index.js
esm export import specifier ./b ./node_modules/pmodule/index.js
modules by path ./*.js 213 bytes
./index.js 55 bytes [orphan] [built]
[no exports used]
Expand All @@ -1807,6 +1807,7 @@ modules by path ./*.js 213 bytes
| esm import specifier pmodule ./index.js
| esm export ./c ./node_modules/pmodule/b.js
| esm export import specifier ./c ./node_modules/pmodule/b.js
| esm export import specifier ./b ./node_modules/pmodule/index.js
Rspack x.x.x compiled successfully in X.23"
`;
Expand Down

2 comments on commit 1baa554

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Benchmark detail: Open

Name Base (2024-11-08 dfbe05f) Current Change
10000_big_production-mode + exec 44.5 s ± 1.64 s 44.2 s ± 839 ms -0.77 %
10000_development-mode + exec 1.84 s ± 19 ms 1.84 s ± 27 ms -0.02 %
10000_development-mode_hmr + exec 644 ms ± 4.5 ms 651 ms ± 10 ms +0.95 %
10000_production-mode + exec 2.43 s ± 34 ms 2.43 s ± 24 ms +0.15 %
arco-pro_development-mode + exec 1.79 s ± 60 ms 1.76 s ± 56 ms -1.74 %
arco-pro_development-mode_hmr + exec 430 ms ± 2.3 ms 432 ms ± 1.3 ms +0.44 %
arco-pro_production-mode + exec 3.2 s ± 61 ms 3.16 s ± 90 ms -1.17 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.25 s ± 63 ms 3.27 s ± 77 ms +0.53 %
threejs_development-mode_10x + exec 1.59 s ± 15 ms 1.61 s ± 18 ms +0.78 %
threejs_development-mode_10x_hmr + exec 777 ms ± 7.8 ms 781 ms ± 9.6 ms +0.58 %
threejs_production-mode_10x + exec 4.99 s ± 40 ms 5 s ± 34 ms +0.37 %

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Ran ecosystem CI: Open

suite result
modernjs ✅ success
_selftest ✅ success
rspress ✅ success
rslib ✅ success
rsbuild ✅ success
examples ✅ success
devserver ✅ success

Please sign in to comment.