Skip to content

Commit

Permalink
fix: side effects plugin should not compute based on affected
Browse files Browse the repository at this point in the history
  • Loading branch information
JSerFeng committed Sep 11, 2024
1 parent 930e351 commit 78041b8
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,21 @@ async fn nmf_module(

#[plugin_hook(CompilationOptimizeDependencies for SideEffectsFlagPlugin)]
fn optimize_dependencies(&self, compilation: &mut Compilation) -> Result<Option<bool>> {
let affected_modules = compilation
.unaffected_modules_cache
.get_affected_modules_with_chunk_graph()
.lock()
.expect("should lock")
.clone();
dbg!(affected_modules);
// TODO: use affected module optimization
let mut modules: IdentifierSet = compilation
.get_module_graph()
.modules()
.keys()
.copied()
.collect();

let mut modules: IdentifierSet = if compilation.options.new_incremental_enabled() {
compilation
.unaffected_modules_cache
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const v = 'foo'
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {v as value} from "./module";

let v = value;
module.hot.accept('./module', () => {
v = value
});

it("should auto-reexport an ES6 imported value on accept with newTreeshaking", async function (done) {
expect(v).toBe("foo");
NEXT(
require("../../update")(done, true, () => {
expect(v).toBe("foo");
done();
})
);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {v} from './reexports'
v;
export {v};
----
import {v} from './reexports'
v;// no-op
export {v};
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,2 @@
import {v} from './foo';
export {v};
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import {v} from './reexports-deep';
export {v};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/** @type {import("@rspack/core").Configuration} */
module.exports = {
optimization: {
sideEffects: true,
providedExports: true,
}
};

0 comments on commit 78041b8

Please sign in to comment.