-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Detect variable reassignments in modules without side effects #5658
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
Detect variable reassignments in modules without side effects #5658
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Thank you for your contribution! ❤️You can try out this pull request locally by installing Rollup via npm install rollup/rollup#gh-5650_treeshake_module_side_effects_bug Notice: Ensure you have installed the latest stable Rust toolchain. If you haven't installed it yet, please see https://www.rust-lang.org/tools/install to learn how to download Rustup and install Rust. or load it into the REPL: |
Performance report!Rough benchmark
Internal benchmark
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #5658 +/- ##
=======================================
Coverage 99.39% 99.39%
=======================================
Files 242 242
Lines 9345 9348 +3
Branches 2470 2470
=======================================
+ Hits 9288 9291 +3
Misses 48 48
Partials 9 9 ☔ View full report in Codecov by Sentry. |
0d3627d
to
da1281b
Compare
This PR has been released as part of rollup@4.22.0. You can test it via |
It appears that this might cause some build failures that need further investigation.
It appears that this might cause some build failures that need further investigation.
This PR contains:
Are tests included?
Breaking Changes?
List any relevant issue numbers:
moduleSideEffects: false
removes side effectful getter inside a exported function since 4.9.2 #5408Description
The bug was quite intricate:
This took me quite some thinking to fix. The problem is that while the contract of
moduleSideEffects: false
means that we check the module for side-effectful code if at least one export is used, there are situations in Rollup where we "use" an export without including it in the bundle.To mitigate this, accessing an identifier during tree-shaking will now always mark the module as "potentially included", overriding the moduleSideEffects flag, because obviously we used a variable of that module.
To not break a previous fix around TDZ detection, I needed to rework this slightly as well: Now modules are marked when they receive a proper tree-shaking pass and if we use a variable from a module that did not receive a pass, we do not perform TDZ detection for that variable as the logic would be faulty.