#4496·esbuild

Suboptimal minification when safe logical assignments are possible

Author: fabiospampinatoCreated Jul 8, 2026Updated Sep 14, 2026
Labelssuboptimal-output

Repro.

Basically using these flags:

--minify --target=esnext

And this input code:

javascript
let foo;
foo = foo || 1;
export {foo}

We get this output code:

javascript
let o;o=o||1;export{o as foo};

But I think we should really be getting this:

javascript
let o;o||=1;export{o as foo};

I understand in the presence of setters and proxies this may lead to slightly different execution, but there are some basic cases where we are sure we are not triggering a setter nor a proxy trap, like this one, so presumably the better minification should be emitted.