Skip to content

Conversation

@sapphi-red
Copy link
Member

@sapphi-red sapphi-red commented Sep 15, 2025

function wrapper() { var x = a; for (let a of x) console.log(a) }

should not be compress to

function wrapper() { for (let a of a) console.log(a) }

because a points to a different variable as the scope is different.
This PR fixes those kinds of cases for all for statements.

Found in rolldown/rolldown#6220

refs #13755

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

sapphi-red commented Sep 15, 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 Sep 15, 2025

CodSpeed Instrumentation Performance Report

Merging #13769 will not alter performance

Comparing 09-15-fix_minifier_don_t_inline_single_use_variables_that_are_not_literals_to_for_statement_initializers (f0af9a4) with main (b6eba27)1

Summary

✅ 37 untouched

Footnotes

  1. No successful run was found on main (f0af9a4) during the generation of this report, so b6eba27 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 September 15, 2025 05:24
Copilot AI review requested due to automatic review settings September 15, 2025 05:24
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 bug in the minifier's single-use variable inlining optimization where variables were incorrectly inlined into for statement initializers when they would reference different scoped variables with the same name.

  • Prevents inlining non-literal variables into for statement binding declarations to avoid scope confusion
  • Updates test cases to cover the specific edge cases involving variable scope conflicts
  • Adds parameter to control when only literal values should be inlined

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
crates/oxc_minifier/src/peephole/minimize_statements.rs Adds scope-aware parameter to prevent non-literal inlining in for statements
crates/oxc_minifier/tests/peephole/inline_single_use_variable.rs Updates and adds test cases to verify correct behavior with scoped variables
tasks/track_memory_allocations/allocs_minifier.snap Updated memory allocation snapshots
tasks/minsize/minsize.snap Updated minification size snapshots

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@sapphi-red sapphi-red marked this pull request as draft September 15, 2025 05:27
@sapphi-red sapphi-red force-pushed the 09-15-fix_minifier_don_t_inline_single_use_variables_that_are_not_literals_to_for_statement_initializers branch from 5532789 to 94b2953 Compare September 15, 2025 05:38
@sapphi-red sapphi-red marked this pull request as ready for review September 15, 2025 05:40
@sapphi-red sapphi-red requested a review from Boshen September 15, 2025 05:42
@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label Sep 15, 2025
Copy link
Member

Boshen commented Sep 15, 2025

Merge activity

…s to for statement initializers (#13769)

```js
function wrapper() { var x = a; for (let a of x) console.log(a) }
```
should not be compress to
```js
function wrapper() { for (let a of a) console.log(a) }
```
because `a` points to a different variable as the scope is different.
This PR fixes those kinds of cases for all for statements.

Found in rolldown/rolldown#6220

refs #13755
@graphite-app graphite-app bot force-pushed the 09-15-fix_minifier_don_t_inline_single_use_variables_that_are_not_literals_to_for_statement_initializers branch from 94b2953 to f0af9a4 Compare September 15, 2025 06:00
@graphite-app graphite-app bot merged commit f0af9a4 into main Sep 15, 2025
25 checks passed
@graphite-app graphite-app bot deleted the 09-15-fix_minifier_don_t_inline_single_use_variables_that_are_not_literals_to_for_statement_initializers branch September 15, 2025 06:05
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Sep 15, 2025
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.

3 participants