Skip to content

Commit

Permalink
fix: incorrect conciseBody lookahead (#14194)
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Jan 21, 2022
1 parent b05dad7 commit e5d29f6
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/babel-parser/src/parser/expression.js
Expand Up @@ -2373,8 +2373,10 @@ export default class ExpressionParser extends LValParser {
): N.ArrowFunctionExpression {
this.scope.enter(SCOPE_FUNCTION | SCOPE_ARROW);
let flags = functionFlags(isAsync, false);
// ConciseBody and AsyncConciseBody inherit [In]
if (!this.match(tt.bracketL) && this.prodParam.hasIn) {
// ConciseBody[In] :
// [lookahead ≠ {] ExpressionBody[?In, ~Await]
// { FunctionBody[~Yield, ~Await] }
if (!this.match(tt.braceL) && this.prodParam.hasIn) {
flags |= PARAM_IN;
}
this.prodParam.enter(flags);
Expand Down
@@ -0,0 +1 @@
() => [] in x
@@ -0,0 +1,40 @@
{
"type": "File",
"start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}},
"program": {
"type": "Program",
"start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}},
"expression": {
"type": "ArrowFunctionExpression",
"start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}},
"id": null,
"generator": false,
"async": false,
"params": [],
"body": {
"type": "BinaryExpression",
"start":6,"end":13,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":13}},
"left": {
"type": "ArrayExpression",
"start":6,"end":8,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":8}},
"elements": []
},
"operator": "in",
"right": {
"type": "Identifier",
"start":12,"end":13,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":13},"identifierName":"x"},
"name": "x"
}
}
}
}
],
"directives": []
}
}
@@ -0,0 +1 @@
() => {} in x
@@ -0,0 +1,3 @@
{
"throws": "Unexpected token (1:9)"
}

0 comments on commit e5d29f6

Please sign in to comment.