Latest Results
fix(es/minifier): Fold never-assigned variables in conditions (#12650)
**Description:**
The minifier kept a branch that depends on a variable that is declared
without an initializer and is never assigned. For example:
```js
let transform;
globalThis.process = (value) =>
transform ? transform(value) + ":UNREACHABLE_FEATURE_BRANCH" : value;
```
Before this change, the output kept `transform ? ... : value`. After
this change, the output is `globalThis.process = (value) => value;`, and
the unused `let transform;` declaration is removed.
Such a variable always reads as `undefined`, also inside closures. The
optimizer now records these variables and replaces a reference with
`void 0` only at positions where the value lets the expression fold:
- `if` tests and conditional expression tests
- the operand of `!` and `typeof`
- the left operand of `&&`, `||`, and `??`
- `==`, `!=`, `===`, and `!==` comparisons where both operands are
constant
- the base of an optional chain (`x?.y`, `x?.()`)
Other references keep the variable. A mangled name is shorter than `void
0`, so a full replacement makes the output larger. For example,
`get-intrinsic` declares `var undefined;` and reads it many times.
The optimizer does not record a variable in these cases:
- it is assigned anywhere, or it is updated with `++` or `--`
- it is read above its declaration (TDZ)
- it is exported, or it is a top-level variable without `toplevel`
- it is a parameter, a catch parameter, a `for` head binding, or
`arguments`
- its scope contains `eval` or `with`
This change also folds `void 0 ?? x` to `x` in the pure optimizer.
New fixtures are in `tests/fixture/issues/12643`. The `runtime` fixture
compares Node.js output before and after two minifications. Updated
outputs:
- `issues/8844`: `let x; x?.x?.();` is removed.
- `next/target-es2015`: an unused `devBuildPromiseResolve` callback is
removed.
- `pass-1/issue-6405`: the dead `if (val)` block is removed.
- `terser/.../issue_1670_2`: the IIFE remains with `passes: 2`. With
`passes: 3`, the output is `console.log("PASS")` again.
**Validation:**
- `cargo test -p swc_ecma_minifier` passed.
- `./scripts/exec.sh` in `crates/swc_ecma_minifier` passed.
- `cargo fmt --all` and `cargo clippy --all --all-targets -- -D
warnings` passed.
These results cover the source changes and fixtures. The changeset
commit was added after these runs.
Closes #12643
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Latest Branches
0%
0%
0%
© 2026 CodSpeed Technology