-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Fix side effect detection in optional chains #5589
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
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-detection 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 #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 [email protected]. 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:
getLiteralValueAtPathAsChainElement
is the backbone of the new logic. It behaves the same asgetLiteralValueAtPath
but 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.hasEffectsAsChainElement
similarly works likehasEffects
but first relies ongetLiteralValueAtPathAsChainElement
to 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.