Skip to content

feat(minifier): fold switch stmt whose parent is not block stmt - #25403

Merged
Dunqing merged 1 commit into
oxc-project:mainfrom
armano2:feat/try_fold_switch-in-dce
Aug 23, 2026
Merged

feat(minifier): fold switch stmt whose parent is not block stmt#25403
Dunqing merged 1 commit into
oxc-project:mainfrom
armano2:feat/try_fold_switch-in-dce

Conversation

@armano2

@armano2 armano2 commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Move removal of dead code from switch stmts to remove_dead_code, this change enables processing of switch stmts whose parent is not list of stmts

current minification processes stmts whose parents are block stmts and they are last stmt of set block, this change also allows us to remove empty blocks and last break from switch cases whose parent is not block stmt

if (a) { b(); if (c) switch (d) { case 1: case 2: break; } c(); }
//            ^~~~~~ due to body not being a block we where not able to process this

// Current:
if (a) { if (b(), c) switch (d) { case 1: case 2: break } c() }
//                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ this switch case is not being processed

// This branch:
a && (b(), c && d, c());
//              ^ switch cases can be correctly processed

note: this change applies only dce, and dosn't substitute switch stmts with if'stmts

changes in stack:

@armano2
armano2 requested a review from Dunqing as a code owner August 8, 2026 13:46
@codspeed-hq

codspeed-hq Bot commented Aug 8, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 62 untouched benchmarks
⏩ 19 skipped benchmarks1


Comparing armano2:feat/try_fold_switch-in-dce (797c8ec) with main (fd61cd8)

Open in CodSpeed

Footnotes

  1. 19 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.

@Sysix Sysix added the A-minifier Area - Minifier label Aug 8, 2026
@armano2
armano2 force-pushed the feat/try_fold_switch-in-dce branch from 1a96331 to bb57886 Compare August 9, 2026 13:39
@armano2
armano2 force-pushed the feat/try_fold_switch-in-dce branch from a05d604 to ce668f0 Compare August 20, 2026 22:37
@armano2 armano2 changed the title feat(minifier): fold switch stmt whose parent is non last non block stmt Aug 22, 2026
@Dunqing

Dunqing commented Aug 23, 2026

Copy link
Copy Markdown
Member

@codex review

@Dunqing

Dunqing commented Aug 23, 2026

Copy link
Copy Markdown
Member

/monitor-oxc run

@oxc-guard

oxc-guard Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: ce668f0d6c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Dunqing Dunqing left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you!

@Dunqing
Dunqing force-pushed the feat/try_fold_switch-in-dce branch from ce668f0 to 797c8ec Compare August 23, 2026 14:01
@Dunqing
Dunqing merged commit b6e9e5e into oxc-project:main Aug 23, 2026
38 checks passed
@armano2
armano2 deleted the feat/try_fold_switch-in-dce branch August 23, 2026 17:06
graphite-app Bot pushed a commit that referenced this pull request Aug 24, 2026
### 🚀 Features

- b6e9e5e minifier: Fold switch stmt whose parent is not block stmt (#25403) (Armano)

### 🐛 Bug Fixes

- 8a9bdbd estree: Include decorators in `FormalParameterRest ` spans (#26021) (camc314)
- 6f0c7cf minifier: Avoid merging `if` to `for` in sloppy mode when containing function declaration (#25638) (sapphi-red)
- 2cde1f6 rust: Address nightly deprecations (#25998) (Boshen)
- 6c5ad1b codegen: Only add mapping names for `PrivateIdentifier`s which have changed (#25958) (overlookmotel)
- 2dad1e0 parser: Track irregular line terminators in trivia (#25947) (camc314)
- 58ba651 minifier: Avoid merging `if` to `for` when the body contains a function declaration (#25637) (sapphi-red)
- a185ac3 codegen: Print `#` before private identifier in TS signature key (#25938) (overlookmotel)
- af82a07 minifier: Keep unary `+` when the other operand has side effects (#25645) (Kotaro Chikuba)

### ⚡ Performance

- 53f6270 packages/codegen: Eagerly initialize `mapNames` (#25979) (overlookmotel)
- 5b43c60 packages/codegen: Split recording mappings into multiple functions (#25978) (overlookmotel)
- cc947b5 packages/codegen: Reduce property lookups (#25977) (overlookmotel)
- c22a9cc packages/codegen: Combine condition checks (#25976) (overlookmotel)
- 215a6a5 packages/codegen: Add functions for writing/marking unnamed mappings (#25975) (overlookmotel)
- fe444cc codegen: Avoid allocations for single comment anchors (#25598) (camc314)
- a0aee81 minifier: Do not rebuild expression when substituting void to null (#25964) (Armano)
- 1004439 packages/codegen: Merge `mark` and `write` calls in `printImportAttributes` (#25972) (overlookmotel)
- 94c8a34 packages/codegen: Remove `node` param from `printString` and `printNonNegativeFloat` (#25971) (overlookmotel)
- 7e2b4b3 packages/codegen: `printNonNegativeFloat` write mapping directly (#25968) (overlookmotel)
- f09c8ab minifier: Avoid creation of unnecessary conditional expressions (#25931) (Armano)
- 53ff080 packages/codegen: Remove `lastWasPostfixClose` (#25888) (overlookmotel)

### 📚 Documentation

- 07de646 packages/codegen: Fix JSDoc comments on `write*` methods (#25966) (overlookmotel)
- 3b09c04 packages/codegen: Clarify comment (#25959) (overlookmotel)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-minifier Area - Minifier

3 participants