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

fix: new (foo?.bar)() incorrectly throws exception OptionalChainingNoNew #15377

Merged
merged 1 commit into from
Jan 30, 2023

Conversation

liuxingbaoyu
Copy link
Member

@liuxingbaoyu liuxingbaoyu commented Jan 30, 2023

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

@liuxingbaoyu liuxingbaoyu added PR: Bug Fix 🐛 A type of pull request used for our changelog categories pkg: parser labels Jan 30, 2023
@babel-bot
Copy link
Collaborator

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/53807/

@liuxingbaoyu
Copy link
Member Author

I'm surprised that the test262 parser tests don't cover this. :)

@liuxingbaoyu liuxingbaoyu changed the title fix: new (foo?.bar)(); incorrectly throws exception OptionalChainingNoNew fix: new (foo?.bar)() incorrectly throws exception OptionalChainingNoNew Jan 30, 2023
@nicolo-ribaudo nicolo-ribaudo merged commit 41aac8b into babel:main Jan 30, 2023
} else if (this.isOptionalChain(node.callee)) {
} else if (
this.isOptionalChain(node.callee) &&
!node.callee.extra?.parenthesized
Copy link
Contributor

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!()

Copy link
Member Author

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

Copy link
Contributor

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.

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label May 3, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: parser PR: Bug Fix 🐛 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Inconsistent on different createParenthesizedExpressions option
5 participants