-
-
Notifications
You must be signed in to change notification settings - Fork 722
feat(minifier): support ForStatements for single use variable inlining #13755
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
feat(minifier): support ForStatements for single use variable inlining #13755
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
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. |
There was a problem hiding this 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 extends the single use variable inlining optimization to support for-in and for-of statements. The minifier can now inline variables that are used only once in the right-hand side expression of these loop constructs.
- Adds single use variable substitution for for-in and for-of statement right-hand side expressions
- Includes proper handling of variable declaration initializers in for-in statements (Annex B.3.5)
- Updates test coverage with new test cases for both for-in and for-of scenarios
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| crates/oxc_minifier/src/peephole/minimize_statements.rs | Implements single use variable substitution for for-in and for-of statements |
| crates/oxc_minifier/tests/peephole/inline_single_use_variable.rs | Adds test cases for the new optimization |
| tasks/track_memory_allocations/allocs_minifier.snap | Updates memory allocation benchmarks |
| tasks/minsize/minsize.snap | Updates minification size benchmarks |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
CodSpeed Instrumentation Performance ReportMerging #13755 will not alter performanceComparing Summary
Footnotes |
6a8c861 to
a823891
Compare
Merge activity
|
#13755) Inline single use variables in for statements: ```js function wrapper1() { var x = foo; for (var i = x; i < 10; i++) console.log(i) } function wrapper2() { var i, x = foo; for (i = x; i < 10; i++) console.log(i) } // to function wrapper1() { for (var i = foo; i < 10; i++) console.log(i) } function wrapper2() { var i; for (i = foo; i < 10; i++) console.log(i) } ``` ```js function wrapper() { var x = {}; for (var a in x) console.log(a) } // to function wrapper() { for (var a in {}) console.log(a) } ``` ```js function wrapper() { var x = []; for (var a of x) console.log(a) } // to function wrapper() { for (var a of []) console.log(a) } ``` refs #13277
a823891 to
c364ad1
Compare
…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

Inline single use variables in for statements:
refs #13277