Latest Results
fix(es/minifier): treat spread arguments of pure calls as side effects (#12585)
**Description:**
The reproduction in #12566 still fails on `main` after #12604:
```js
(function () {
function noop() {}
const it = [1, 2][Symbol.iterator]();
noop(...it);
console.log(it.next().done);
})();
```
With `{ compress: {}, mangle: {} }` the output is
`console.log([1,2][Symbol.iterator]().next().done);`, which prints
`false` instead of `true`.
#12604 fixed the arms of `Pure::ignore_return_value`. This call is also
dropped through `may_have_side_effects` in `swc_ecma_utils`, which
treats a call to a pure callee as side-effect free when its argument
expressions are, ignoring `spread`. The array arm of the same function
already counts a spread as a side effect; the pure call, pure `new` and
pure optional-call arms now do the same. The output becomes
`!function(){let
o=[1,2][Symbol.iterator]();[...o],console.log(o.next().done)}();`, which
prints `true`.
The change only keeps more code, and only when a pure call has a spread
argument. Performance: one `spread.is_some()` check per argument of a
pure call.
`swc_ecma_utils` is shared, so the `swc_ecma_transforms_optimization`
and `swc` tsc suites were run as well. Only 3 `tsc-references` minified
snapshots change: `newWithSpreadES6` now keeps `[...a, ...a]` for `new
f2(...a, ...a)`, and `destructuringParameterDeclaration3ES5/ES6` now
keep `array` and two `[...array]`, a size-only change.
**Tests:**
`tests/fixture/issues/12566/`, with `defaults/` and
`without-reduce-vars/`, each with `expected.stdout` and
`expected.repeat-stdout`. The input has 15 spread cases (inlined, empty,
builtin, class and `/*#__PURE__*/` callees, `new`, `?.()`, sequences,
`...null`) and two controls. On `main`, 3 of the 15 lines are still
wrong (`noop(...it)`, `new (class {})(...null)` and `(function ()
{})?.(...null)`) and the 4 tests fail.
- `cargo test -p swc_ecma_minifier`: 8061 passed, 0 failed.
- `cargo test -p swc --test tsc`: 4580 passed, 0 failed.
- `cargo test -p swc_ecma_utils -p swc_ecma_transforms_optimization`:
551 passed, as on `main`.
- `./scripts/exec.sh`, clippy and `cargo fmt -p swc_ecma_utils -p
swc_ecma_minifier -- --check`: clean.
**Related issue (if exists):**
Follow-up to #12604; the reproduction in #12566 still fails on `main`.
---
Found with a differential fuzzer. Drafted with AI assistance; I
confirmed locally that the 4 new fixture tests fail without the fix and
pass with it, and that the snippet above prints `false` with @swc/core
1.16.20 and on `main`, and `true` with this change. Latest Branches
+1%
fix/ts-namespace-enum-bindings 0%
0%
© 2026 CodSpeed Technology