Skip to content

Commit

Permalink
Allow yielding an arrow function withour parens around the param (#6877)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo authored and existentialism committed Nov 22, 2017
1 parent 80b4b71 commit 464df13
Show file tree
Hide file tree
Showing 3 changed files with 378 additions and 3 deletions.
18 changes: 15 additions & 3 deletions packages/babylon/src/parser/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -620,8 +620,12 @@ export default class ExpressionParser extends LValParser {
node: N.ArrowFunctionExpression,
call: N.CallExpression,
): N.ArrowFunctionExpression {
const oldYield = this.state.yieldInPossibleArrowParameters;
this.state.yieldInPossibleArrowParameters = null;
this.expect(tt.arrow);
return this.parseArrowExpression(node, call.arguments, true);
this.parseArrowExpression(node, call.arguments, true);
this.state.yieldInPossibleArrowParameters = oldYield;
return node;
}

// Parse a no-call expression (like argument of `new` or `::` operators).
Expand Down Expand Up @@ -715,14 +719,22 @@ export default class ExpressionParser extends LValParser {
this.next();
return this.parseFunction(node, false, false, true);
} else if (canBeArrow && id.name === "async" && this.match(tt.name)) {
const oldYield = this.state.yieldInPossibleArrowParameters;
this.state.yieldInPossibleArrowParameters = null;
const params = [this.parseIdentifier()];
this.expect(tt.arrow);
// let foo = bar => {};
return this.parseArrowExpression(node, params, true);
this.parseArrowExpression(node, params, true);
this.state.yieldInPossibleArrowParameters = oldYield;
return node;
}

if (canBeArrow && !this.canInsertSemicolon() && this.eat(tt.arrow)) {
return this.parseArrowExpression(node, [id]);
const oldYield = this.state.yieldInPossibleArrowParameters;
this.state.yieldInPossibleArrowParameters = null;
this.parseArrowExpression(node, [id]);
this.state.yieldInPossibleArrowParameters = oldYield;
return node;
}

return id;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function *f() {
(yield a => a);
(yield async a => a);
(yield async (a) => a);
}
Loading

0 comments on commit 464df13

Please sign in to comment.