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: throw when async() call param is object with assignement #13410

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 7 additions & 5 deletions packages/babel-parser/src/parser/expression.js
Expand Up @@ -766,6 +766,7 @@ export default class ExpressionParser extends LValParser {
optional: boolean,
): N.Expression {
const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
const refExpressionErrors = new ExpressionErrors();
tony-go marked this conversation as resolved.
Show resolved Hide resolved
this.state.maybeInArrowParameters = true;

this.next(); // eat `(`
Expand All @@ -780,14 +781,14 @@ export default class ExpressionParser extends LValParser {
node.optional = optional;
}
if (optional) {
node.arguments = this.parseCallExpressionArguments(tt.parenR, false);
node.arguments = this.parseCallExpressionArguments(tt.parenR);
} else {
node.arguments = this.parseCallExpressionArguments(
tt.parenR,
state.maybeAsyncArrow,
base.type === "Import",
base.type !== "Super",
node,
refExpressionErrors,
);
}
this.finishCallExpression(node, state.optionalChainMember);
Expand All @@ -801,6 +802,7 @@ export default class ExpressionParser extends LValParser {
node,
);
} else {
this.checkExpressionErrors(refExpressionErrors, true);
if (state.maybeAsyncArrow) {
this.expressionScope.exit();
}
Expand Down Expand Up @@ -890,10 +892,10 @@ export default class ExpressionParser extends LValParser {

parseCallExpressionArguments(
close: TokenType,
possibleAsyncArrow: boolean,
dynamicImport?: boolean,
allowPlaceholder?: boolean,
nodeForExtra?: ?N.Node,
refExpressionErrors?: ?ExpressionErrors,
): $ReadOnlyArray<?N.Expression> {
const elts = [];
let first = true;
Expand Down Expand Up @@ -931,8 +933,8 @@ export default class ExpressionParser extends LValParser {
elts.push(
this.parseExprListItem(
false,
possibleAsyncArrow ? new ExpressionErrors() : undefined,
possibleAsyncArrow ? { start: 0 } : undefined,
refExpressionErrors || new ExpressionErrors(),
tony-go marked this conversation as resolved.
Show resolved Hide resolved
tony-go marked this conversation as resolved.
Show resolved Hide resolved
{ start: 0 },
tony-go marked this conversation as resolved.
Show resolved Hide resolved
allowPlaceholder,
),
);
Expand Down
@@ -0,0 +1 @@
async({ __proto__: x, __proto__: y })
tony-go marked this conversation as resolved.
Show resolved Hide resolved
@@ -0,0 +1,71 @@
{
"type": "File",
"start":0,"end":37,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":37}},
"errors": [
"SyntaxError: Redefinition of __proto__ property. (1:22)"
],
"program": {
"type": "Program",
"start":0,"end":37,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":37}},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start":0,"end":37,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":37}},
"expression": {
"type": "CallExpression",
"start":0,"end":37,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":37}},
"callee": {
"type": "Identifier",
"start":0,"end":5,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":5},"identifierName":"async"},
"name": "async"
},
"arguments": [
{
"type": "ObjectExpression",
"start":6,"end":36,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":36}},
"properties": [
{
"type": "ObjectProperty",
"start":8,"end":20,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":20}},
"method": false,
"key": {
"type": "Identifier",
"start":8,"end":17,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":17},"identifierName":"__proto__"},
"name": "__proto__"
},
"computed": false,
"shorthand": false,
"value": {
"type": "Identifier",
"start":19,"end":20,"loc":{"start":{"line":1,"column":19},"end":{"line":1,"column":20},"identifierName":"x"},
"name": "x"
}
},
{
"type": "ObjectProperty",
"start":22,"end":34,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":34}},
"method": false,
"key": {
"type": "Identifier",
"start":22,"end":31,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":31},"identifierName":"__proto__"},
"name": "__proto__"
},
"computed": false,
"shorthand": false,
"value": {
"type": "Identifier",
"start":33,"end":34,"loc":{"start":{"line":1,"column":33},"end":{"line":1,"column":34},"identifierName":"y"},
"name": "y"
}
}
]
}
]
}
}
],
"directives": []
}
}
@@ -0,0 +1 @@
async({ foo33 = 1 });
@@ -0,0 +1,3 @@
{
"throws": "Unexpected token (1:14)"
}