Repository navigation
Implement proposal-optional-chaining - #2572
Conversation
|
Omg <3 I've been lobbying for someone at Facebook to champion it at tc39 for at least 4 years, I'm so happy that it's moving along :) If prettier support can do even a tiny bit at making it move forward, I'm supportive! |
| obj?.[expr]; | ||
| func?.(...args); | ||
|
|
||
| a?.(); |
There was a problem hiding this comment.
Is this the actual syntax? It looks weird, I would have written it as a?()
There was a problem hiding this comment.
That's the syntax currently in the proposal, but there is no "actual syntax" here - this is a stage 1 proposal, which amounts to "someone on the committee thought something kinda vaguely like this might be a good idea". Its syntax and semantics are likely to change radically and repeatedly before it makes it into the language, if it ever does.
That said, a?() in particular is unlikely because it's ambiguous: a?(0) could be a call, or could be the first two thirds of a ternary.
There was a problem hiding this comment.
CoffeeScript made it work by not having ternaries at all. (This has the amusing effect that some code, like a=b?(c,d)+e:f, is both valid CoffeeScript and valid JS but with totally different semantics in each case.)
Life is much easier when you don't have to worry about old code.
|
Attempted to clean it up a bit by decreasing the overall number of code branches, not sure if I made it better or worse. 🤷♂️ f06318b |
https://github.com/tc39/proposal-optional-chaining
I had to add code to more places that I would have liked. Might need to clean this up a bit.
Closes #2568
cc. @bakkot @existentialism want to give this a sanity check?
@vjeux Think it is too early to add support for this?