fix: throw when async() call param is object with assignement (#13410)
This commit is contained in:
parent
176bc24312
commit
a0369fdbfa
@ -767,28 +767,32 @@ export default class ExpressionParser extends LValParser {
|
||||
optional: boolean,
|
||||
): N.Expression {
|
||||
const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
|
||||
this.state.maybeInArrowParameters = true;
|
||||
let refExpressionErrors = null;
|
||||
|
||||
this.state.maybeInArrowParameters = true;
|
||||
this.next(); // eat `(`
|
||||
|
||||
let node = this.startNodeAt(startPos, startLoc);
|
||||
node.callee = base;
|
||||
|
||||
if (state.maybeAsyncArrow) {
|
||||
this.expressionScope.enter(newAsyncArrowScope());
|
||||
refExpressionErrors = new ExpressionErrors();
|
||||
}
|
||||
|
||||
if (state.optionalChainMember) {
|
||||
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);
|
||||
@ -803,6 +807,7 @@ export default class ExpressionParser extends LValParser {
|
||||
);
|
||||
} else {
|
||||
if (state.maybeAsyncArrow) {
|
||||
this.checkExpressionErrors(refExpressionErrors, true);
|
||||
this.expressionScope.exit();
|
||||
}
|
||||
this.toReferencedArguments(node);
|
||||
@ -891,10 +896,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;
|
||||
@ -932,8 +937,8 @@ export default class ExpressionParser extends LValParser {
|
||||
elts.push(
|
||||
this.parseExprListItem(
|
||||
false,
|
||||
possibleAsyncArrow ? new ExpressionErrors() : undefined,
|
||||
possibleAsyncArrow ? { start: 0 } : undefined,
|
||||
refExpressionErrors,
|
||||
{ start: 0 },
|
||||
allowPlaceholder,
|
||||
),
|
||||
);
|
||||
|
||||
1
packages/babel-parser/test/fixtures/es2017/async-arrow/parenthesized-assign-object/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/es2017/async-arrow/parenthesized-assign-object/input.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
async ({ __proto__: x, __proto__: y }) => {}
|
||||
72
packages/babel-parser/test/fixtures/es2017/async-arrow/parenthesized-assign-object/output.json
vendored
Normal file
72
packages/babel-parser/test/fixtures/es2017/async-arrow/parenthesized-assign-object/output.json
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":44,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":44}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":44,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":44}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":0,"end":44,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":44}},
|
||||
"expression": {
|
||||
"type": "ArrowFunctionExpression",
|
||||
"start":0,"end":44,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":44}},
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": true,
|
||||
"params": [
|
||||
{
|
||||
"type": "ObjectPattern",
|
||||
"start":7,"end":37,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":37}},
|
||||
"properties": [
|
||||
{
|
||||
"type": "ObjectProperty",
|
||||
"start":9,"end":21,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":21}},
|
||||
"method": false,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start":9,"end":18,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":18},"identifierName":"__proto__"},
|
||||
"name": "__proto__"
|
||||
},
|
||||
"computed": false,
|
||||
"shorthand": false,
|
||||
"value": {
|
||||
"type": "Identifier",
|
||||
"start":20,"end":21,"loc":{"start":{"line":1,"column":20},"end":{"line":1,"column":21},"identifierName":"x"},
|
||||
"name": "x"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ObjectProperty",
|
||||
"start":23,"end":35,"loc":{"start":{"line":1,"column":23},"end":{"line":1,"column":35}},
|
||||
"method": false,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start":23,"end":32,"loc":{"start":{"line":1,"column":23},"end":{"line":1,"column":32},"identifierName":"__proto__"},
|
||||
"name": "__proto__"
|
||||
},
|
||||
"computed": false,
|
||||
"shorthand": false,
|
||||
"value": {
|
||||
"type": "Identifier",
|
||||
"start":34,"end":35,"loc":{"start":{"line":1,"column":34},"end":{"line":1,"column":35},"identifierName":"y"},
|
||||
"name": "y"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":42,"end":44,"loc":{"start":{"line":1,"column":42},"end":{"line":1,"column":44}},
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
@ -0,0 +1 @@
|
||||
async({ __proto__: x, __proto__: y })
|
||||
@ -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)"
|
||||
}
|
||||
@ -0,0 +1 @@
|
||||
async?.({ __proto__: x, __proto__: y })
|
||||
@ -0,0 +1,72 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":39,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":39}},
|
||||
"errors": [
|
||||
"SyntaxError: Redefinition of __proto__ property. (1:24)"
|
||||
],
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":39,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":39}},
|
||||
"sourceType": "module",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":0,"end":39,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":39}},
|
||||
"expression": {
|
||||
"type": "OptionalCallExpression",
|
||||
"start":0,"end":39,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":39}},
|
||||
"callee": {
|
||||
"type": "Identifier",
|
||||
"start":0,"end":5,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":5},"identifierName":"async"},
|
||||
"name": "async"
|
||||
},
|
||||
"optional": true,
|
||||
"arguments": [
|
||||
{
|
||||
"type": "ObjectExpression",
|
||||
"start":8,"end":38,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":38}},
|
||||
"properties": [
|
||||
{
|
||||
"type": "ObjectProperty",
|
||||
"start":10,"end":22,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":22}},
|
||||
"method": false,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start":10,"end":19,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":19},"identifierName":"__proto__"},
|
||||
"name": "__proto__"
|
||||
},
|
||||
"computed": false,
|
||||
"shorthand": false,
|
||||
"value": {
|
||||
"type": "Identifier",
|
||||
"start":21,"end":22,"loc":{"start":{"line":1,"column":21},"end":{"line":1,"column":22},"identifierName":"x"},
|
||||
"name": "x"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ObjectProperty",
|
||||
"start":24,"end":36,"loc":{"start":{"line":1,"column":24},"end":{"line":1,"column":36}},
|
||||
"method": false,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start":24,"end":33,"loc":{"start":{"line":1,"column":24},"end":{"line":1,"column":33},"identifierName":"__proto__"},
|
||||
"name": "__proto__"
|
||||
},
|
||||
"computed": false,
|
||||
"shorthand": false,
|
||||
"value": {
|
||||
"type": "Identifier",
|
||||
"start":35,"end":36,"loc":{"start":{"line":1,"column":35},"end":{"line":1,"column":36},"identifierName":"y"},
|
||||
"name": "y"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user