Skip to content

fix(minifier): avoid illegal var; when folding unused arguments copy loop#21421

Merged
Dunqing merged 2 commits intooxc-project:mainfrom
fazba:fix/minifier-rewrite-arguments-copy-loop
Apr 15, 2026
Merged

fix(minifier): avoid illegal var; when folding unused arguments copy loop#21421
Dunqing merged 2 commits intooxc-project:mainfrom
fazba:fix/minifier-rewrite-arguments-copy-loop

Conversation

@fazba
Copy link
Copy Markdown
Contributor

@fazba fazba commented Apr 14, 2026

Summary

When peephole-folding the classic arguments copy loop, we could end up with an empty VariableDeclaration initializer (for (var; …)), which prints as invalid var; and can confuse downstream folding (e.g. try_fold_for hoisting).

Changes

  • Only build the [...arguments] / .slice(offset) array initializer when there is a binding pattern for the copy result (r_id_pat).
  • If there is no binding pattern, clear for_stmt.init instead of emitting an empty VariableDeclaration, so the loop becomes for (; 0;) and dead-code elimination can remove it cleanly.

Tests

  • Added a regression in crates/oxc_minifier/tests/peephole/substitute_alternate_syntax.rs covering unused copy result + consequent (must not become illegal var;).

AI usage

This change was developed with assistance from Cursor; I reviewed the diff and tests locally before opening this PR.

…y loop

When the copy result has no binding pattern, clear the `for` initializer
instead of emitting an empty `VariableDeclaration`.

Made-with: Cursor
@github-actions github-actions Bot added A-minifier Area - Minifier C-bug Category - Bug labels Apr 14, 2026
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 15, 2026

Merging this PR will not alter performance

✅ 44 untouched benchmarks
⏩ 7 skipped benchmarks1


Comparing fazba:fix/minifier-rewrite-arguments-copy-loop (3a2cd88) with main (4417fe3)

Open in CodSpeed

Footnotes

  1. 7 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Copy link
Copy Markdown
Member

@Dunqing Dunqing left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

@Dunqing Dunqing merged commit b3ed467 into oxc-project:main Apr 15, 2026
33 checks passed
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>
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