-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix corner cases in optional_chains
#5110
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
Conversation
@kzc TIL: $ echo 'console.log([ function(){return this} ][0]())' | node
[ [Function (anonymous)] ] $ echo 'console.log(([ function(){return this} ][0])())' | node
[ [Function (anonymous)] ] $ echo 'console.log((0, [ function(){return this} ][0])())' | node
<ref *1> Object [global] So far so good − parentheses alone won't make a difference. Now, for the main course: $ echo 'console.log(null?.f())' | node
undefined $ echo 'console.log((null?.f)())' | node
[stdin]:1
console.log((null?.f)())
^
TypeError: (intermediate value) is not a function
at [stdin]:1:22 What is this I don't even. |
I think it makes sense. They are different expressions and have different ASTs:
esbuild shows how they are different:
It looks like a bug in uglify-js
|
This confirms it's a parse problem, not an output issue:
|
Only if you assume moronic specifications − removing support for this "feature" should be the real fix here. In fact, that's where I will start... |
To be honest, I'd expect them to be evaluated differently due to the parentheses - the first form is a conditional call or undefined, and the second is an unconditional call of an expression that may be undefined. The former form is useful, and the latter form is not. That part is self-consistent. What is not consistent is the call object
In my opinion the parenthesized call expression |
Thanks for the detailed analysis − will tackle this during the next spare cycle. |
optional_chains
optional_chains
After thinking about it, I think the motivation for keeping the call object
|
optional_chains
optional_chains
c69f06f
to
32a9c56
Compare
No description provided.