-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Optional chaining #6973
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
base: master
Are you sure you want to change the base?
Optional chaining #6973
Conversation
f4d884a to
cc54764
Compare
rhuanjl
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this looks neater than my version was, though struggling to follow how it handles every branch. What happens if you do a function call in an optional chain does it crash?
(Not going to merge until we have some significant test coverage)
|
I'm currently working on function calls. Edit: Function call should work now but |
No copy of expression result needed anymore
|
The jitted code currently crashes at this assertion (causing the test-failures) ChakraCore/lib/Backend/GlobOpt.cpp Line 11384 in 1f6e17c
|
aae4d9f to
a9a1c70
Compare
b132685 to
9904051
Compare
1a46f30 to
8baa9e6
Compare
5958fb4 to
8c4eddf
Compare
| EmitOptionalChainWrapper(pexpr->AsParseNodeUni(), byteCodeGenerator, funcInfo, [&](ParseNode *innerNode) { | ||
| EmitDelete(innerNode, innerNode, byteCodeGenerator, funcInfo); | ||
| }); | ||
| pnode->location = pexpr->location; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We "copy" the value from the knopOptChain node to the knopDelete node
| // Every `?.` node will call `EmitNullPropagation` | ||
| // `EmitNullPropagation` short-circuits to `skipLabel` in case of a nullish value | ||
| emitChainContent(innerNode); | ||
| pnodeOptChain->location = innerNode->location; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of acquiring a tmp I copy the location of pnodeOptChain to innerNode
(In case the caller has already aquired a tmp)
| innerNode->location = pnodeOptChain->location; |
And copy it back after emitting innerNode
(In case the location was NoRegister and the emission of innerNode aquired a tmp)
| pnodeOptChain->location = innerNode->location; |
00c00c3 to
55dea9f
Compare
|
@rhuanjl Just in time for the first aniversary (🎉) of this PR, I'll mark it as ready for review!
|
|
I see that there has been more activity in the repository. Is there any chance of merging this PR? |
I'll take a look in the next week, back when we were last working on this I was worried about a couple of potentially untested code paths. FYI: the only people who contribute to this repository now do it as a hobby and have unrelated jobs hence the glacial progress. I'm happy to give a bit of time to help any new contributor learn the ropes if you're aware of interest it would be good to see more happening here. |
This PR aims to add support for the stage-4 proposal optional-chaining.
It's inspired by the work of @rhuanjl but uses a more hacky approach to parsing.
Goals
ToDo
eval?.('a'))eval)deletethis(a.b)().cshould be equivalent toa.b().ca?.[++x]++xshould not be evaluated ifaisnullorundefineda?.3:0(ternary) astkOptChain(?.)tmp-renaming forevalresulteval("foo?.()")oreval("foo?.property")applycall optimization?Only triggered for 2 nested
forloops with assignmentChakraCore/test/loop/loopinversion.js
Lines 60 to 66 in e26c81f
Out of scope
EmitInvoke(seems unused)Spec: Optional Chains
Fixes #6349