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: ExpressionBody should respect [In] parameter #11931

Merged
merged 1 commit into from Aug 26, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion packages/babel-parser/src/parser/expression.js
Expand Up @@ -2115,7 +2115,8 @@ export default class ExpressionParser extends LValParser {
this.state.inParameters = false;

if (isExpression) {
node.body = this.parseMaybeAssignAllowIn();
// https://tc39.es/ecma262/#prod-ExpressionBody
node.body = this.parseMaybeAssign();
Copy link
Contributor Author

@JLHwung JLHwung Aug 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After the [In] parameter tracking refactor, the fix is straightforward: parseMaybeAssign parses AssignmentExpression[?In], while parseMaybeAssignAllowIn parses AssignmentExpression[In].

According to the spec we should replace parseMaybeAssignAllowIn by parseMaybeAssign.

this.checkParams(node, false, allowExpression, false);
} else {
const oldStrict = this.state.strict;
Expand Down
@@ -0,0 +1,3 @@
const t = () => ({
v: (v) => v in z
})
@@ -0,0 +1,88 @@
{
"type": "File",
"start":0,"end":40,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":2}},
"program": {
"type": "Program",
"start":0,"end":40,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":2}},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "VariableDeclaration",
"start":0,"end":40,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":2}},
"declarations": [
{
"type": "VariableDeclarator",
"start":6,"end":40,"loc":{"start":{"line":1,"column":6},"end":{"line":3,"column":2}},
"id": {
"type": "Identifier",
"start":6,"end":7,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":7},"identifierName":"t"},
"name": "t"
},
"init": {
"type": "ArrowFunctionExpression",
"start":10,"end":40,"loc":{"start":{"line":1,"column":10},"end":{"line":3,"column":2}},
"id": null,
"generator": false,
"async": false,
"params": [],
"body": {
"type": "ObjectExpression",
"start":17,"end":39,"loc":{"start":{"line":1,"column":17},"end":{"line":3,"column":1}},
"properties": [
{
"type": "ObjectProperty",
"start":21,"end":37,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":18}},
"method": false,
"key": {
"type": "Identifier",
"start":21,"end":22,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":3},"identifierName":"v"},
"name": "v"
},
"computed": false,
"shorthand": false,
"value": {
"type": "ArrowFunctionExpression",
"start":24,"end":37,"loc":{"start":{"line":2,"column":5},"end":{"line":2,"column":18}},
"id": null,
"generator": false,
"async": false,
"params": [
{
"type": "Identifier",
"start":25,"end":26,"loc":{"start":{"line":2,"column":6},"end":{"line":2,"column":7},"identifierName":"v"},
"name": "v"
}
],
"body": {
"type": "BinaryExpression",
"start":31,"end":37,"loc":{"start":{"line":2,"column":12},"end":{"line":2,"column":18}},
"left": {
"type": "Identifier",
"start":31,"end":32,"loc":{"start":{"line":2,"column":12},"end":{"line":2,"column":13},"identifierName":"v"},
"name": "v"
},
"operator": "in",
"right": {
"type": "Identifier",
"start":36,"end":37,"loc":{"start":{"line":2,"column":17},"end":{"line":2,"column":18},"identifierName":"z"},
"name": "z"
}
}
}
}
],
"extra": {
"parenthesized": true,
"parenStart": 16
}
}
}
}
],
"kind": "const"
}
],
"directives": []
}
}
@@ -0,0 +1 @@
for (() => x in y;;);
@@ -0,0 +1,3 @@
{
"throws": "Unexpected token, expected \")\" (1:17)"
}