fix(minifier): avoid illegal var; when folding unused arguments copy loop#21421
Merged
Dunqing merged 2 commits intooxc-project:mainfrom Apr 15, 2026
Merged
Conversation
…y loop When the copy result has no binding pattern, clear the `for` initializer instead of emitting an empty `VariableDeclaration`. Made-with: Cursor
Merging this PR will not alter performance
Comparing Footnotes
|
Dunqing
added a commit
that referenced
this pull request
Apr 16, 2026
### 💥 BREAKING CHANGES - 24fb7eb allocator: [**BREAKING**] Rename `Box` and `Vec` methods (#21395) (overlookmotel) ### 🚀 Features - ce5072d parser: Support `turbopack` magic comments (#20803) (Kane Wang) - f5deb55 napi/transform: Expose `optimizeConstEnums` and `optimizeEnums` options (#21388) (Dunqing) - 24b03de data_structures: Introduce `NonNullConst` and `NonNullMut` pointer types (#21425) (overlookmotel) ### 🐛 Bug Fixes - d7a359a ecmascript: Treat update expressions as unconditionally side-effectful (#21456) (Dunqing) - 56af2f4 transformer/async-to-generator: Correct scope of inferred named FE in async-to-generator (#21458) (Dunqing) - b3ed467 minifier: Avoid illegal `var;` when folding unused arguments copy loop (#21421) (fazba) - b0e8f13 minifier: Preserve `var` inside `catch` with same-named parameter (#21366) (Dunqing) - 4fb73a7 transformer/typescript: Preserve execution order for accessor with `useDefineForClassFields: false` (#21369) (Dunqing) ### ⚡ Performance - da3cc16 parser: Refactor out `LexerContext` (#21275) (Ulrich Stark) ### 📚 Documentation - c5b19bb allocator: Reformat comments in `Arena` (#21448) (overlookmotel) - 091e88e lexer: Update doc comment about perf benefit of reading through references (#21423) (overlookmotel) - 922cbee allocator: Remove references to "bump" from comments (#21397) (overlookmotel) Co-authored-by: Dunqing <29533304+Dunqing@users.noreply.github.com>
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.
Summary
When peephole-folding the classic
argumentscopy loop, we could end up with an emptyVariableDeclarationinitializer (for (var; …)), which prints as invalidvar;and can confuse downstream folding (e.g.try_fold_forhoisting).Changes
[...arguments]/.slice(offset)array initializer when there is a binding pattern for the copy result (r_id_pat).for_stmt.initinstead of emitting an emptyVariableDeclaration, so the loop becomesfor (; 0;)and dead-code elimination can remove it cleanly.Tests
crates/oxc_minifier/tests/peephole/substitute_alternate_syntax.rscovering unused copy result + consequent (must not become illegalvar;).AI usage
This change was developed with assistance from Cursor; I reviewed the diff and tests locally before opening this PR.