Correctly fail for invalid yield in for (#9398)

This commit is contained in:
Daniel Tschinder
2019-01-23 13:39:30 -08:00
committed by GitHub
parent d4e045ac24
commit 42c5d3fc4b
4 changed files with 9 additions and 7 deletions

View File

@@ -127,7 +127,7 @@ export default class ExpressionParser extends LValParser {
const startPos = this.state.start;
const startLoc = this.state.startLoc;
if (this.match(tt._yield) && this.state.inGenerator) {
let left = this.parseYield();
let left = this.parseYield(noIn);
if (afterLeftParse) {
left = afterLeftParse.call(this, left, startPos, startLoc);
}
@@ -2063,7 +2063,7 @@ export default class ExpressionParser extends LValParser {
// Parses yield expression inside generator.
parseYield(): N.YieldExpression {
parseYield(noIn?: ?boolean): N.YieldExpression {
const node = this.startNode();
if (this.state.inParameters) {
@@ -2088,7 +2088,7 @@ export default class ExpressionParser extends LValParser {
node.argument = null;
} else {
node.delegate = this.eat(tt.star);
node.argument = this.parseMaybeAssign();
node.argument = this.parseMaybeAssign(noIn);
}
return this.finishNode(node, "YieldExpression");
}

View File

@@ -0,0 +1,3 @@
function* g() {
for (yield '' in {}; ; ) ;
}

View File

@@ -0,0 +1,3 @@
{
"throws": "Invalid left-hand side in for-in statement (2:7)"
}