-
Notifications
You must be signed in to change notification settings - Fork 864
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
Optional Chaining Operator ?. #1593
Conversation
.?
.?
.?
.?
Please uncomment |
That's done and the results are part of the last commit. Sadly troubleshooting through those tests has exposed a problem with this approach to implementing this operator. The core idea was to replace optional chaining operator expression tree with a conditional expression like below
but this means that we're rewriting the tree into something like this
and crucially the actual ASTNode for So, I don't think this works without cloning ASTNodes, which turns out is not that easy as one could expect. I ended up finding a hacky way to do this ( I don't even want to think about the performance hit.. 🙄 ) but I really hope someone knows a better way.. |
Thnx for trying! Not an expert at all in this area, but maybe an approach like was taken in the exponential operator implementation could help That implementation implements it's logic for interpreted and compiled mode in two different locations (see separate commits for each area). What I'm suggesting is instead of rewriting the ast tree, maybe instead implement the explicit logic for dealing with this operator again: no expert, so maybe a complete bogus suggestion 🤪 |
Following your advice, I've added 3 new bytecodes to handle in the Interpreter / Compiler :
To handle the optional property get ( |
This one requires another rebase, and sadly it isn't easy either -- seemed straightforward but now tests are passing. Could you please take a crack at a "git rebase" here? Even if you rebase, and then later on we have more conflicts -- since a bunch of people are adding language features at once -- we reduce the burden on future rebases every time we do it. Thanks! |
I've merged latest master into it @gbrail, hope that will do it. |
Thanks -- one of the things that we have done in GitHub is to disable "merge commits," which keeps the history clear if we ever need to go back. That means that someone (often GitHub) needs to "rebase" the changes. Locally, you can do that on your branch using "git rebase master," after which you can "git push -f" to update this branch with the new commit history. Git is basically taking all your commits and replaying them on the top of the tree. The problem is that this branch is intertwined with a bunch of other changes, so if I try to do that myself, I have to go back through the history and understand what changed. Could you please give it a try? If it doesn't work then we'll take a look again later. |
@gbrail maybe we ought to make that clear in the contributing section in the readme, that we don't accept merge commits? |
… language/expressions/optional-chaining section in test262 and reworking the solution to pass them, including the necessity to clone ASTNode to avoid problems introduced due to structural sharing betweek left and right of left.?rigth.
…tional method call for `?.` operator
…imilar to visitGetProp
700aab0
to
f150caf
Compare
Thank you for a detailed info on how to rebase, I frankly just didn't realise there is a rule against merge commits in PRs. That's a perfectly fair ask though, no problem at all. Having said that it probably wouldn't hurt to make it explicit in the README.md. Back to the topic of this PR - I've rebased everything on top of latest master, hopefully it's ready for a review now? |
Wrt merge commits: could even fail the pipeline if these are detected |
100% ! Why make a human check it, if a computer can do it, right? |
Thanks for doing this -- I merged this manually (yet another conflict) and it's all merged now. Thanks! |
Optional chaining operator by transforming into conditional expression in IRFactory, similar #1591
Closes #937