-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
fix: new (foo?.bar)()
incorrectly throws exception OptionalChainingNoNew
#15377
fix: new (foo?.bar)()
incorrectly throws exception OptionalChainingNoNew
#15377
Conversation
liuxingbaoyu
commented
Jan 30, 2023
•
edited by gitpod-io
bot
edited by gitpod-io
bot
Q | A |
---|---|
Fixed Issues? | Fixes #15376 |
Patch: Bug Fix? | √ |
Major: Breaking Change? | |
Minor: New Feature? | |
Tests Added + Pass? | √ |
Documentation PR Link | |
Any Dependency Changes? | |
License | MIT |
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/53807/ |
I'm surprised that the |
new (foo?.bar)();
incorrectly throws exception OptionalChainingNoNew
new (foo?.bar)()
incorrectly throws exception OptionalChainingNoNew
} else if (this.isOptionalChain(node.callee)) { | ||
} else if ( | ||
this.isOptionalChain(node.callee) && | ||
!node.callee.extra?.parenthesized |
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.
Can you add a new test case for non null TS expression?
// invalid
new foo?.bar!()
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.
Yes, this test should throw an exception, but it doesn't.
But unfortunately I didn't find a good way to fix it.
The ast of ts is different from ours. It splits this statement into call(non-null(prop-access(new,question,id)))
.
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.
Maybe we can move the error reporting here?
if (noCalls && this.lookaheadCharCode() === charCodes.leftParenthesis) { |
When noCalls
is true
, we should throw the error anyway. If the next token is (
we stop otherwise we continue for the error recovery mode. As a bonus, we don't have to deal with extra?.parenthesized
(because it will be descended from parseExprAtom
instead) and it should work with non null TS expression, too.