Latest Results
feat(es/minifier): Remove more trailing returns with values known to be undefined (#12723)
**Description:**
The minifier removes a `return` statement at the end of a function when
its value is `void x`. It did not remove the statement for other values
that are always `undefined`, for example `return a, void b`. The
minifier then kept the `return` and the `void`.
This PR changes `drop_unused_stmt_at_end_of_fn` to use `get_type`
instead of a check for `void`. If the returned expression is known to be
`undefined`, the minifier replaces `return <expr>` with `<expr>;`. The
expression stays in the output, so side effects do not change. The
function result is `undefined` in both forms.
Expressions that `get_type` reports as `undefined`:
- `void x`
- the global `undefined`. A local binding named `undefined` is not
matched.
- `a = <undefined>`
- a sequence, or a conditional, where every value is `undefined`
Example:
```js
// before
return anchor = this.start, void (restorePoint(range.start, anchor), restorePoint(range.end, anchor));
// after
anchor = this.start, restorePoint(range.start, anchor), restorePoint(range.end, anchor);
```
Test results:
- Fixtures in `crates/swc_ecma_minifier/tests/fixture/pr/12723` cover
each case above, an arrow function, and a shadowed `undefined` that must
stay. Each fixture has an `expected.stdout`, so the test also checks the
result of the minified code.
- Three of the new fixtures (`return-assign-void`, `return-seq-void`,
`return-seq-void-nested`) fail without this change. The other fixtures
pass without it, because other passes already remove `return undefined`
and `return a, undefined`. They stay as regression tests.
- The output of five existing fixtures gets shorter (`react-ace`,
`yui/6`, `react-dom-17.0.2`, terser `issue_1758`, and
`projects-size.snapshot.md`).
- `cargo test -p swc_ecma_minifier` passes.
- CodSpeed reports no change in performance.
**BREAKING CHANGE:**
**Related issue (if exists):**
š¤ Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: DongYun Kang <kdy.1997.dev@gmail.com>
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com> Latest Branches
0%
0%
0%
Ā© 2026 CodSpeed Technology