fix(minifier): keep variables that are modified by combined assignments made by minification#13267
Merged
graphite-app[bot] merged 1 commit intomainfrom Aug 24, 2025
Conversation
Member
Author
CodSpeed Instrumentation Performance ReportMerging #13267 will not alter performanceComparing Summary
Footnotes |
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a minification bug where variables modified by combined assignments were incorrectly removed during dead code elimination. The issue occurred when expressions like v ?? (v = bar()) were compressed to v ??= bar() without updating the semantic information to mark the variable as being read.
- Updated peephole optimizations to mark variables as read when creating combined assignment operators
- Added comprehensive test coverage for various assignment operator transformations
- Fixed semantic analysis to prevent incorrect variable elimination
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| crates/oxc_minifier/tests/peephole/oxc.rs | Added test cases covering the variable elimination bug for different assignment operators |
| crates/oxc_minifier/src/peephole/minimize_logical_expression.rs | Updated to mark variables as read when transforming to combined assignments |
| crates/oxc_minifier/src/peephole/minimize_conditions.rs | Updated to mark variables as read when creating assignment operators from binary expressions |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
crates/oxc_minifier/src/peephole/minimize_logical_expression.rs
Outdated
Show resolved
Hide resolved
This was referenced Aug 23, 2025
758139a to
277b91e
Compare
277b91e to
fc93c07
Compare
fc93c07 to
da76589
Compare
32fc2e6 to
8d324c1
Compare
This was referenced Aug 24, 2025
Contributor
Merge activity
|
…ts made by minification (#13267) ```js (function() { let v; window.foo = function() { return v ?? (v = bar()); } })() ``` was compressed to ```js (function() { window.foo = function() { return bar(); } })() ``` . But this changes the semantics because `bar()` will be executed every time `window.foo()` is called after the minification. This was caused by not updating the semantics information when compressing `v ?? (v = bar())` into `v ??= bar()` (and other similar ones). This PR fixes that by updating the semantics information when those compressions are applied.
8d324c1 to
6003285
Compare
da76589 to
0e804aa
Compare
Base automatically changed from
08-24-fix_minifier_keep_property_access_before_call_expressions_as-is_to_preserve_this_value
to
main
August 24, 2025 08:48
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

was compressed to
. But this changes the semantics because
bar()will be executed every timewindow.foo()is called after the minification.This was caused by not updating the semantics information when compressing
v ?? (v = bar())intov ??= bar()(and other similar ones).This PR fixes that by updating the semantics information when those compressions are applied.