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: Throws on new foo?.bar!() #15439

Merged
merged 3 commits into from Feb 21, 2023
Merged

Conversation

liuxingbaoyu
Copy link
Member

@liuxingbaoyu liuxingbaoyu commented Feb 19, 2023

Q                       A
Fixed Issues? #15377 (comment)
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass?
Documentation PR Link
Any Dependency Changes?
License MIT

All credit to @JLHwung, thanks!

@liuxingbaoyu liuxingbaoyu added PR: Spec Compliance 👓 A type of pull request used for our changelog categories pkg: parser area: typescript labels Feb 19, 2023
Comment on lines +40 to +69
{
"type": "ExpressionStatement",
"start":16,"end":32,"loc":{"start":{"line":2,"column":0,"index":16},"end":{"line":2,"column":16,"index":32}},
"expression": {
"type": "OptionalCallExpression",
"start":16,"end":31,"loc":{"start":{"line":2,"column":0,"index":16},"end":{"line":2,"column":15,"index":31}},
"callee": {
"type": "NewExpression",
"start":16,"end":27,"loc":{"start":{"line":2,"column":0,"index":16},"end":{"line":2,"column":11,"index":27}},
"callee": {
"type": "MemberExpression",
"start":20,"end":27,"loc":{"start":{"line":2,"column":4,"index":20},"end":{"line":2,"column":11,"index":27}},
"object": {
"type": "Identifier",
"start":20,"end":23,"loc":{"start":{"line":2,"column":4,"index":20},"end":{"line":2,"column":7,"index":23},"identifierName":"foo"},
"name": "foo"
},
"computed": false,
"property": {
"type": "Identifier",
"start":24,"end":27,"loc":{"start":{"line":2,"column":8,"index":24},"end":{"line":2,"column":11,"index":27},"identifierName":"bar"},
"name": "bar"
}
},
"arguments": []
},
"optional": true,
"arguments": []
}
},
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a change here, now we keep ?. in ast.
This aligns their behavior.

new foo?. bar();
new foo. bar?.();

@babel-bot
Copy link
Collaborator

babel-bot commented Feb 19, 2023

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

@ehoogeveen-medweb
Copy link
Contributor

Drive-by suggestion: Might be good to have a test for the (equally awkward) syntax foo?.[0] (compare foo![0]) as well.

Comment on lines 6 to 7
foo?.[0]
foo![0]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we test new foo?.[0]; and new foo![0]; instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops. :)

@@ -1919,17 +1924,6 @@ export default abstract class ExpressionParser extends LValParser {
node.callee = this.parseNoCallExpr();
if (node.callee.type === "Import") {
this.raise(Errors.ImportCallNotNewExpression, { at: node.callee });
} else if (
this.isOptionalChain(node.callee) &&
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 check if we can remove the isOptionalChain implementation now?

Copy link
Contributor

@JLHwung JLHwung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks!

@nicolo-ribaudo nicolo-ribaudo merged commit a2fdc20 into babel:main Feb 21, 2023
@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 24, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: typescript outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: parser PR: Spec Compliance 👓 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants