You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Looks like this affects Terser too (which you also discovered): terser/terser#1587. This currently happens for all bitwise operators in esbuild:
Before (esbuild)
After (esbuild)
if ((a | b) === 0) throw '|'
if (!(a | b)) throw "|"
if ((a & b) === 0) throw '&'
if (!(a & b)) throw "&"
if ((a ^ b) === 0) throw '^'
if (!(a ^ b)) throw "^"
if ((a << b) === 0) throw '<<'
if (!(a << b)) throw "<<"
if ((a >> b) === 0) throw '>>'
if (!(a >> b)) throw ">>"
if ((a >>> b) === 0) throw '>>>'
if (!(a >>> b)) throw ">>>"
if (~a === 0) throw '~'
if (!~a) throw "~"
It's mostly the same for Terser except Terser doesn't do it for the >>> operator, which is funnily enough the only operator for which this is actually safe to do (because >>> throws when used with bigints):
Before (Terser)
After (Terser)
if ((a | b) === 0) throw '|'
if (!(a | b)) throw "|"
if ((a & b) === 0) throw '&'
if (!(a & b)) throw "&"
if ((a ^ b) === 0) throw '^'
if (!(a ^ b)) throw "^"
if ((a << b) === 0) throw '<<'
if (!(a << b)) throw "<<"
if ((a >> b) === 0) throw '>>'
if (!(a >> b)) throw ">>"
if ((a >>> b) === 0) throw '>>>'
if (a >>> b == 0) throw ">>>"
if (~a === 0) throw '~'
if (0 == ~a) throw "~"
Edit: Although the conversion of ~a === 0 to ~a == 0 that Terser does here is also problematic: ~-1n === 0 is false but ~-1n == 0 is true.
For input
esbuild outputs
But this changes the behavior when
foo(0n, 0n)
is called.No error happens before minification, but an error happens after minification.
The text was updated successfully, but these errors were encountered: