Skip to content

Commit e5d29f6

Browse files
authored
fix: incorrect conciseBody lookahead (#14194)
1 parent b05dad7 commit e5d29f6

5 files changed

Lines changed: 49 additions & 2 deletions

File tree

packages/babel-parser/src/parser/expression.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2373,8 +2373,10 @@ export default class ExpressionParser extends LValParser {
23732373
): N.ArrowFunctionExpression {
23742374
this.scope.enter(SCOPE_FUNCTION | SCOPE_ARROW);
23752375
let flags = functionFlags(isAsync, false);
2376-
// ConciseBody and AsyncConciseBody inherit [In]
2377-
if (!this.match(tt.bracketL) && this.prodParam.hasIn) {
2376+
// ConciseBody[In] :
2377+
// [lookahead ≠ {] ExpressionBody[?In, ~Await]
2378+
// { FunctionBody[~Yield, ~Await] }
2379+
if (!this.match(tt.braceL) && this.prodParam.hasIn) {
23782380
flags |= PARAM_IN;
23792381
}
23802382
this.prodParam.enter(flags);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
() => [] in x
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"type": "File",
3+
"start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}},
4+
"program": {
5+
"type": "Program",
6+
"start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}},
7+
"sourceType": "script",
8+
"interpreter": null,
9+
"body": [
10+
{
11+
"type": "ExpressionStatement",
12+
"start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}},
13+
"expression": {
14+
"type": "ArrowFunctionExpression",
15+
"start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}},
16+
"id": null,
17+
"generator": false,
18+
"async": false,
19+
"params": [],
20+
"body": {
21+
"type": "BinaryExpression",
22+
"start":6,"end":13,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":13}},
23+
"left": {
24+
"type": "ArrayExpression",
25+
"start":6,"end":8,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":8}},
26+
"elements": []
27+
},
28+
"operator": "in",
29+
"right": {
30+
"type": "Identifier",
31+
"start":12,"end":13,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":13},"identifierName":"x"},
32+
"name": "x"
33+
}
34+
}
35+
}
36+
}
37+
],
38+
"directives": []
39+
}
40+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
() => {} in x
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"throws": "Unexpected token (1:9)"
3+
}

0 commit comments

Comments
 (0)