Latest Results
fix(es/minifier): always run hygiene before the mangler
The minify pipeline skipped `hygiene()` whenever the mangler was enabled,
on the assumption that the mangler renames everything hygiene would. That
assumption is false: the mangler preserves names it is not allowed to
rename — most importantly top-level bindings, which with the default
`mangle.top_level = false` are never renamed at all. It therefore cannot
deconflict a synthesized binding that collides with a preserved one.
IIFE inlining hoists a parameter (or body-level `var`) binding into the
enclosing scope, reusing its original nested syntax context. When that
lands at the top level next to a user binding of the same name, the two
collide:
SyntaxError: Identifier 'x' has already been declared
`hygiene()` renames one of them (e.g. to `x1`) and resolves the collision,
but it was being skipped precisely in the configuration that needs it
(compress + mangle, the default `@swc/core` script setup). SWC's parser
does not enforce lexical redeclaration, so the invalid output shipped
silently; Node rejects it at load. This surfaced in Turbopack/Next.js
output, whose top-level `eval('require')` shim also disables the
dead-parameter elimination that would otherwise remove the hoisted binding.
Fix: run `hygiene()` unconditionally after `optimize()` in every minify
entry point (`Compiler::minify`, the `transform()` minifier pass, and the
node minifier binding), and mirror this in the minifier test harness.
Hygiene runs after all compressor passes, so unlike a mid-pipeline rename
it does not desync usage data or regress optimization. A handful of
fixtures update: hygiene now disambiguates shadowed names (e.g. a nested
`function n()` that the mangler had left shadowing an outer `n`) — latent
bugs the same misconfiguration was producing without an error.
The wasm minifier binding inherits the fix through `Compiler::minify`.
Closes: https://github.com/swc-project/swc/issues/11977
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>lukesandberg:fix/issue-11977-iife-mangle-collision Latest Branches
-2%
kdy1/fix-11977-minifier-binding 0%
kdy1/nodejs-wasm-typescript-api 0%
kdy1/fix-11977-mangle-collision © 2026 CodSpeed Technology