-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When transform nullish coalescing it transform != null which may lead to wrong result #3772
Comments
$ node -p 'a=0;b=1;a??b'
0
$ node -p 'a=0;b=1;a!=null?a:b'
0 |
The only difference is Apart from It appears that esbuild has adopted this strategy by default. |
Yes, the But it's such an obscure edge case that I have decided I don't care about it. FWIW terser, another popular JavaScript minifier, has also decided that they don't care about It's ancient web history and doesn't belong in modern JavaScript code. It's not worth bloating everyone's code by transforming I'm closing this issue as I won't be changing anything here.
Note that |
esbuild version: esbuild
node version: 16.20.0
Below is my code
Run result:
a = b != null ? b : 1;
Expected result:
a = b !== null && a !== undefined ? b : 1;
Since result of
0 ?? 1
is 0, this may lead to wrong result, is there any settings that can make it right?The text was updated successfully, but these errors were encountered: