Skip to content

feat(minifier): prune empty case before trailing default#17994

Merged
graphite-app[bot] merged 1 commit intomainfrom
feat/minifier-prune-empty-case-before-default
Jan 14, 2026
Merged

feat(minifier): prune empty case before trailing default#17994
graphite-app[bot] merged 1 commit intomainfrom
feat/minifier-prune-empty-case-before-default

Conversation

@Boshen
Copy link
Member

@Boshen Boshen commented Jan 14, 2026

Summary

  • Adds minification optimization to remove empty case clauses that precede a trailing default clause when those cases contain only primitive literals
  • Port of evanw/esbuild@add452e

Example

// Before:
switch (x) { case 0: foo(); break; case 1: default: bar() }

// After:
switch (x) { case 0: foo(); break; default: bar() }

Test plan

  • Added tests for basic case with empty literal before default
  • Added tests for multiple empty literal cases
  • Added tests for non-literal identifiers (should NOT be removed)
  • Added tests for default not at end (preserved)
  • Added tests for string, null, and BigInt literals
  • All existing minifier tests pass

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings January 14, 2026 12:23
@github-actions github-actions bot added A-minifier Area - Minifier C-enhancement Category - New feature or request labels Jan 14, 2026
@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label Jan 14, 2026
Copy link
Member Author

Boshen commented Jan 14, 2026

Merge activity

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 adds a minification optimization that removes empty case clauses containing only primitive literals when they immediately precede a trailing default clause in switch statements. This is a port from esbuild that reduces code size without changing behavior.

Changes:

  • Added optimization logic to prune empty literal cases before trailing defaults
  • Added comprehensive test coverage for various literal types and edge cases

Reviewed changes

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

File Description
crates/oxc_minifier/src/peephole/minimize_statements.rs Implements the optimization to remove empty literal cases before trailing default
crates/oxc_minifier/tests/peephole/esbuild.rs Adds comprehensive test cases covering literals, non-literals, and edge cases

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codspeed-hq
Copy link

codspeed-hq bot commented Jan 14, 2026

CodSpeed Performance Report

Merging this PR will not alter performance

Comparing feat/minifier-prune-empty-case-before-default (3124787) with main (eee0342)

Summary

✅ 38 untouched benchmarks
⏩ 7 skipped benchmarks1

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.

graphite-app bot pushed a commit that referenced this pull request Jan 14, 2026
## Summary

- Adds minification optimization to remove empty `case` clauses that precede a trailing `default` clause when those cases contain only primitive literals
- Port of evanw/esbuild@add452e

### Example

```javascript
// Before:
switch (x) { case 0: foo(); break; case 1: default: bar() }

// After:
switch (x) { case 0: foo(); break; default: bar() }
```

## Test plan

- [x] Added tests for basic case with empty literal before default
- [x] Added tests for multiple empty literal cases
- [x] Added tests for non-literal identifiers (should NOT be removed)
- [x] Added tests for default not at end (preserved)
- [x] Added tests for string, null, and BigInt literals
- [x] All existing minifier tests pass

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@graphite-app graphite-app bot force-pushed the feat/minifier-prune-empty-case-before-default branch from 683f7f9 to bbda204 Compare January 14, 2026 12:52
## Summary

- Adds minification optimization to remove empty `case` clauses that precede a trailing `default` clause when those cases contain only primitive literals
- Port of evanw/esbuild@add452e

### Example

```javascript
// Before:
switch (x) { case 0: foo(); break; case 1: default: bar() }

// After:
switch (x) { case 0: foo(); break; default: bar() }
```

## Test plan

- [x] Added tests for basic case with empty literal before default
- [x] Added tests for multiple empty literal cases
- [x] Added tests for non-literal identifiers (should NOT be removed)
- [x] Added tests for default not at end (preserved)
- [x] Added tests for string, null, and BigInt literals
- [x] All existing minifier tests pass

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@graphite-app graphite-app bot force-pushed the feat/minifier-prune-empty-case-before-default branch from bbda204 to 9c6e344 Compare January 14, 2026 12:56
@graphite-app graphite-app bot merged commit 9c6e344 into main Jan 14, 2026
21 checks passed
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Jan 14, 2026
@graphite-app graphite-app bot deleted the feat/minifier-prune-empty-case-before-default branch January 14, 2026 13:02
if first_empty_idx < default_idx {
let default_case = switch_stmt.cases.pop().unwrap();
switch_stmt.cases.truncate(first_empty_idx);
switch_stmt.cases.push(default_case);
Copy link
Contributor

Choose a reason for hiding this comment

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

default case should be ommited when its empty, either empty block or no stmt

while first_empty_idx > 0 {
let case = &switch_stmt.cases[first_empty_idx - 1];
// Only remove empty cases with primitive literal tests
if case.consequent.is_empty()
Copy link
Contributor

@armano2 armano2 Jan 15, 2026

Choose a reason for hiding this comment

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

case that contains only break without label, block stmt, block with break could be also be considered empty

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-minifier Area - Minifier C-enhancement Category - New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants