Skip to content
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

Open
rhuanjl opened this issue Dec 5, 2019 · 3 comments · May be fixed by #6973
Open

Implement optional chaining #6349

rhuanjl opened this issue Dec 5, 2019 · 3 comments · May be fixed by #6973

Comments

@rhuanjl
Copy link
Collaborator

rhuanjl commented Dec 5, 2019

Optional chaining (https://github.com/tc39/proposal-optional-chaining) is now stage 4 and should be implemented; hopefully not too hard, roughly speaking:

a?.someExpression;
//is sugar for
a ? a.someExpression : undefined;

I may try and do this in the next couple of weeks if no one else is.

@rhuanjl
Copy link
Collaborator Author

rhuanjl commented Apr 11, 2020

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).

@rhuanjl
Copy link
Collaborator Author

rhuanjl commented Dec 19, 2020

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.

@rhuanjl
Copy link
Collaborator Author

rhuanjl commented Dec 22, 2020

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.

@ShortDevelopment ShortDevelopment linked a pull request Apr 15, 2024 that will close this issue
17 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant