Latest Results
fix(es/minifier): remove unused variable initializer cycles (#12106)
**Description:**
DCE previously visited variable initializers without associating
deferred references with the initialized binding. References inside
function, arrow, and eligible class expressions were therefore treated
as top-level graph entries, which prevented otherwise unreachable
dependency cycles from being removed.
For example:
```js
var AsyncParsePluginContext = class {
parse(current) {
return parseAsync(current);
}
};
async function parseAsync() {
return new AsyncParsePluginContext();
}
```
The reference to `parseAsync` was incorrectly treated as an entry:
```text
entry -> parseAsync -> AsyncParsePluginContext
```
This PR attributes references from direct deferred-value initializers to
their variable binding:
```text
AsyncParsePluginContext <-> parseAsync
```
With no external entry into this strongly connected component, DCE can
remove the entire unused cycle.
The optimization applies to identifier bindings initialized directly
with:
- Function expressions
- Arrow functions
- Class expressions without heritage, decorators, computed keys, static
initialization, or other observable definition-time work
Named function and class expressions are also handled using their local
expression bindings, preventing self-references from being mistaken for
references to outer declarations with the same symbol.
The conservative behavior is preserved for eager or potentially
observable initializers, including:
- Destructuring bindings
- Class heritage
- Effectful class definitions
- Static initialization
- Eager `let` and `const` dependency cycles
The new DCE fixture covers:
- Removable `var`, `let`, and `const` function and class expression
cycles
- Cycles retained through an external reference
- Named function and class expression bindings
- Class heritage and effectful static initialization
- Eager `let` and `const` cycles
The minifier size snapshot is also updated to reflect the resulting
`echarts.js` gzip reduction from `314.10 KiB` to `314.09 KiB`.
**Testing:**
- `cargo test -p swc_ecma_transforms_optimization`
- `cargo test -p swc_ecma_minifier`
- `crates/swc_ecma_minifier/scripts/exec.sh`
- `crates/swc_ecma_minifier/scripts/test.sh`
- `cargo fmt --all`
- `cargo clippy --all --all-targets -- -D warnings` Latest Branches
+2%
kdy1:kdy1/add-changeset-pr-target-push -2%
SyMind:codex/fix-unused-var-init-cycle +2%
refactor/ast-function-body © 2026 CodSpeed Technology