-
-
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: Throws on new foo?.bar!()
#15439
Conversation
{ | ||
"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": [] | ||
} | ||
}, |
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.
There is a change here, now we keep ?.
in ast.
This aligns their behavior.
new foo?. bar();
new foo. bar?.();
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/53990/ |
Drive-by suggestion: Might be good to have a test for the (equally awkward) syntax |
foo?.[0] | ||
foo![0] |
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.
Shouldn't we test new foo?.[0];
and new foo![0];
instead?
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.
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) && |
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 check if we can remove the isOptionalChain
implementation now?
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.
lgtm, thanks!
All credit to @JLHwung, thanks!