Latest Results
docs(es/minifier): Clarify semantic preservation policy (#12349)
**Description:**
Clarify the minifier implementation and review policy to prioritize
correctness for common usage, performance, and maintainable code. Do not
require additional defensive logic solely for monkey-patched globals or
built-ins, unusual `arguments.length` reassignment, direct-eval
bindings, or dynamic name resolution in `with`.
Keep ordinary lexical shadowing, side effects, and exceptions within the
supported assumptions in scope. Require reviewers to demonstrate an
impact on common usage or an explicit support contract for mandatory
fixes. Align execution-test guidance with this policy without
authorizing hidden failures or blanket removal of existing handling or
tests.
The policy change is limited to the minifier AGENTS.md; a required patch
changeset is included. No runtime code or tests change.
Validation:
- Passed: `cargo fmt --all`, `git diff --check`, `cargo test -p
swc_ecma_minifier`, and minifier `./scripts/exec.sh`.
- The crate tests exited successfully but emitted missing `terser`
module errors from a helper script.
- `cargo clippy --all --all-targets -- -D warnings` failed on the
existing unused `noexec_mount_in` function in
`crates/swc_native_addon/src/platform/unix.rs:117`.
**Related issue (if exists):**
Motivated by the review discussions in #12343:
- https://github.com/swc-project/swc/pull/12343#discussion_r3988684574
- https://github.com/swc-project/swc/pull/12343#discussion_r3988684592
- https://github.com/swc-project/swc/pull/12343#discussion_r3988684587 fix(es/minifier): Preserve let initialization when dropping unused variables (#12345)
**Description:**
Fix a temporal dead zone (TDZ) violation introduced when `unused`
removes a declarator from a `let` declaration. A retained binding
without an initializer must be initialized before side effects from
later declarators can access it.
**Minimal reproduction**
Compressor options:
```json
{
"defaults": false,
"unused": true
}
```
Input:
```js
function test(read, props) {
let localCountry,
unused = (localCountry = read()),
{ value } = props;
return [localCountry, value];
}
console.log(JSON.stringify(test(() => "CN", { value: 1 })));
```
The input prints `["CN",1]`. Before this fix, the compressor produces:
```js
function test(read, props) {
localCountry = read();
let localCountry, { value } = props;
return [localCountry, value];
}
```
Calling this function throws `ReferenceError: Cannot access
'localCountry' before initialization`.
This reproduction requires the options above. The `compress` example
currently uses default compressor options, which optimize this input
differently and do not reproduce the error.
**Cause and fix**
1. The original declaration initializes its bindings from left to right.
Although `localCountry` has no initializer expression, evaluating its
declarator initializes the binding to `undefined`.
2. `unused` removes the unused binding but retains the assignment in its
initializer as a side effect.
3. `visit_mut_var_declarators` previously skipped retained declarators
without initializers without clearing `can_prepend`.
4. On reaching the destructuring declarator, it therefore moved the
collected assignment before the entire `let` declaration, placing the
assignment inside `localCountry`'s TDZ.
Clear `can_prepend` when a retained, initializer-free declarator belongs
to a `let` declaration. The side effect stays after that binding's
initialization. Existing handling of `var`, which is already initialized
before execution reaches the declaration, remains applicable.
The fixed output is:
```js
function test(read, props) {
let localCountry, { value } = (localCountry = read(), props);
return [localCountry, value];
}
```
Adds one fixture covering both a string result and an `undefined` result
from `read()`, plus patch changesets for `swc_ecma_minifier` and
`swc_core`.
**Validation:**
- Verified that the fixture fails before the fix and passes with the
fix.
- Executed the input and generated output separately with Node.js and
compared their stdout.
- `cargo test -p swc_ecma_minifier --test compress unused --quiet` — 155
tests passed.
- `cargo fmt -p swc_ecma_minifier -- --check`
- `cargo clippy -p swc_ecma_minifier --lib -- -D warnings`
**Related issue (if exists):**
None. Latest Branches
0%
codex/remove-export-default-from-benchmark 0%
codex/minifier-semantic-policy +7%
fix/template-literal-missing-cooked © 2026 CodSpeed Technology