Fix side effect detection in optional chains#5589
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
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-5579_improve-chaining-side-effect-detectionNotice: 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 #5589 +/- ##
=======================================
Coverage 99.05% 99.05%
=======================================
Files 241 242 +1
Lines 9273 9297 +24
Branches 2444 2461 +17
=======================================
+ Hits 9185 9209 +24
Misses 58 58
Partials 30 30 ☔ View full report in Codecov by Sentry. |
b78d0a8 to
58f7f32
Compare
Also, do not unnecessarily deoptimize chain expressions
|
This PR has been released as part of rollup@4.19.1. You can test it via |
This PR contains:
Are tests included?
Breaking Changes?
List any relevant issue numbers:
Description
This reworks side effect detection in optional chaining so that in case there is an optional link in a chain that skips the remainder of the chain, any side effects in the start of the chain are still observed.
To do that, I introduce two new methods in chain elements:
getLiteralValueAtPathAsChainElementis the backbone of the new logic. It behaves the same asgetLiteralValueAtPathbut has an additional Symbol return value if it is called on a skipped chain. It first calls the same method on the previous chain link and short-circuits if that call also returns that Symbol.hasEffectsAsChainElementsimilarly works likehasEffectsbut first relies ongetLiteralValueAtPathAsChainElementto detect a broken chain. That way, we can observe all side effects left of the optional link while still skipping all side effects to the right.