Skip to content

Comments

fix(minifier): keep variables that are modified by combined assignments made by minification#13267

Merged
graphite-app[bot] merged 1 commit intomainfrom
08-23-fix_minifier_keep_variables_that_are_modified_by_combined_assignments_made_by_minification
Aug 24, 2025
Merged

fix(minifier): keep variables that are modified by combined assignments made by minification#13267
graphite-app[bot] merged 1 commit intomainfrom
08-23-fix_minifier_keep_variables_that_are_modified_by_combined_assignments_made_by_minification

Conversation

@sapphi-red
Copy link
Member

@sapphi-red sapphi-red commented Aug 23, 2025

(function() {
  let v;
  window.foo = function() {
    return v ?? (v = bar());
  }
})()

was compressed to

(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.

@github-actions github-actions bot added A-minifier Area - Minifier C-bug Category - Bug labels Aug 23, 2025
Copy link
Member Author

sapphi-red commented Aug 23, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@codspeed-hq
Copy link

codspeed-hq bot commented Aug 23, 2025

CodSpeed Instrumentation Performance Report

Merging #13267 will not alter performance

Comparing 08-23-fix_minifier_keep_variables_that_are_modified_by_combined_assignments_made_by_minification (0e804aa) with main (e7a49ed)1

Summary

✅ 34 untouched benchmarks

Footnotes

  1. No successful run was found on main (0e804aa) during the generation of this report, so e7a49ed was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@sapphi-red sapphi-red marked this pull request as ready for review August 23, 2025 06:50
Copilot AI review requested due to automatic review settings August 23, 2025 06:50
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Boshen Boshen self-assigned this Aug 23, 2025
@sapphi-red sapphi-red force-pushed the 08-23-fix_minifier_keep_variables_that_are_modified_by_combined_assignments_made_by_minification branch from 758139a to 277b91e Compare August 24, 2025 05:37
@sapphi-red sapphi-red changed the base branch from main to graphite-base/13267 August 24, 2025 06:38
@sapphi-red sapphi-red changed the base branch from graphite-base/13267 to main August 24, 2025 06:38
@sapphi-red sapphi-red changed the base branch from main to graphite-base/13267 August 24, 2025 06:38
@sapphi-red sapphi-red changed the base branch from graphite-base/13267 to main August 24, 2025 06:38
@sapphi-red sapphi-red changed the base branch from main to graphite-base/13267 August 24, 2025 06:38
@sapphi-red sapphi-red force-pushed the 08-23-fix_minifier_keep_variables_that_are_modified_by_combined_assignments_made_by_minification branch from 277b91e to fc93c07 Compare August 24, 2025 06:38
@sapphi-red sapphi-red changed the base branch from graphite-base/13267 to 08-24-fix_minifier_keep_property_access_before_call_expressions_as-is_to_preserve_this_value August 24, 2025 06:39
@sapphi-red sapphi-red force-pushed the 08-23-fix_minifier_keep_variables_that_are_modified_by_combined_assignments_made_by_minification branch from fc93c07 to da76589 Compare August 24, 2025 06:42
@sapphi-red sapphi-red force-pushed the 08-24-fix_minifier_keep_property_access_before_call_expressions_as-is_to_preserve_this_value branch from 32fc2e6 to 8d324c1 Compare August 24, 2025 06:42
@graphite-app graphite-app bot added the 0-merge Merge with Graphite Merge Queue label Aug 24, 2025
@graphite-app
Copy link
Contributor

graphite-app bot commented Aug 24, 2025

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.
@graphite-app graphite-app bot force-pushed the 08-24-fix_minifier_keep_property_access_before_call_expressions_as-is_to_preserve_this_value branch from 8d324c1 to 6003285 Compare August 24, 2025 08:42
@graphite-app graphite-app bot force-pushed the 08-23-fix_minifier_keep_variables_that_are_modified_by_combined_assignments_made_by_minification branch from da76589 to 0e804aa Compare August 24, 2025 08:43
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
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Aug 24, 2025
@graphite-app graphite-app bot merged commit 0e804aa into main Aug 24, 2025
25 checks passed
@graphite-app graphite-app bot deleted the 08-23-fix_minifier_keep_variables_that_are_modified_by_combined_assignments_made_by_minification branch August 24, 2025 08:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-minifier Area - Minifier C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants