-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Implement optional chaining #6349
Comments
It would be great to see this in for 1.12 - though it's a sizeable piece of work and probably lower priority than RegEx or BigInt - probably smaller than those but still non-simple. I did some initial exploration unfortunately the complexity spiralled further than I thought it would. The dot operator is used in a lot of contexts with slightly different semantics and this matches them in many cases though is different in some with both the optional short cutting feature AND the fact that optional assignment is disallowed. Nonetheless this should be doable in the parser + bytecode emitter by desugaring the operation into a sequence of existing actions. Anyone keen to try it? (it should be fun but not easy). |
I'm taking another look at this, though parsing it correctly is really not simple - hopefully getting the parsing right will be harder than the actual implementation. |
I've got the bulk of an implementation ready - it's based on top of #6545 though so would like to get that merged before I open a PR. Also not quite finished - has some oddities/specific cases to sort out e.g. if you end an optional chain with .apply() things go wrong AND still need to write tests. |
Optional chaining (https://github.com/tc39/proposal-optional-chaining) is now stage 4 and should be implemented; hopefully not too hard, roughly speaking:
I may try and do this in the next couple of weeks if no one else is.
The text was updated successfully, but these errors were encountered: