Skip to content

Commit

Permalink
Merge pull request #126 from eslint/issue121
Browse files Browse the repository at this point in the history
Fix: Yield should parse without an argument (fixes #121)
  • Loading branch information
nzakas committed Apr 11, 2015
2 parents 4ca96e5 + 8ae98cf commit 037f1bf
Show file tree
Hide file tree
Showing 6 changed files with 238 additions and 2 deletions.
10 changes: 9 additions & 1 deletion espree.js
Original file line number Diff line number Diff line change
Expand Up @@ -4644,7 +4644,15 @@ function parseYieldExpression() {
delegateFlag = true;
}

expr = parseAssignmentExpression();
if (peekLineTerminator()) {
return markerApply(marker, astNodeFactory.createYieldExpression(null, delegateFlag));
}

if (!match(";")) {
if (!match("}") && lookahead.type !== Token.EOF) {
expr = parseAssignmentExpression();
}
}

return markerApply(marker, astNodeFactory.createYieldExpression(expr, delegateFlag));
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ast-node-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ module.exports = {
createYieldExpression: function(argument, delegate) {
return {
type: astNodeTypes.YieldExpression,
argument: argument,
argument: argument || null,
delegate: delegate
};
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
module.exports = {
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "FunctionExpression",
"id": null,
"params": [],
"body": {
"type": "BlockStatement",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "YieldExpression",
"argument": null,
"delegate": false,
"range": [
16,
21
],
"loc": {
"start": {
"line": 1,
"column": 16
},
"end": {
"line": 1,
"column": 21
}
}
},
"range": [
16,
22
],
"loc": {
"start": {
"line": 1,
"column": 16
},
"end": {
"line": 1,
"column": 22
}
}
}
],
"range": [
14,
23
],
"loc": {
"start": {
"line": 1,
"column": 14
},
"end": {
"line": 1,
"column": 23
}
}
},
"generator": true,
"expression": false,
"range": [
1,
23
],
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 23
}
}
},
"range": [
0,
25
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 25
}
}
}
],
"sourceType": "script",
"range": [
0,
25
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 25
}
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(function* () { yield });
113 changes: 113 additions & 0 deletions tests/fixtures/ecma-features/generators/yield-without-value.result.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
module.exports = {
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "FunctionExpression",
"id": null,
"params": [],
"body": {
"type": "BlockStatement",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "YieldExpression",
"argument": null,
"delegate": false,
"range": [
16,
21
],
"loc": {
"start": {
"line": 1,
"column": 16
},
"end": {
"line": 1,
"column": 21
}
}
},
"range": [
16,
22
],
"loc": {
"start": {
"line": 1,
"column": 16
},
"end": {
"line": 1,
"column": 22
}
}
}
],
"range": [
14,
24
],
"loc": {
"start": {
"line": 1,
"column": 14
},
"end": {
"line": 1,
"column": 24
}
}
},
"generator": true,
"expression": false,
"range": [
1,
24
],
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 24
}
}
},
"range": [
0,
26
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 26
}
}
}
],
"sourceType": "script",
"range": [
0,
26
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 26
}
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(function* () { yield; });

0 comments on commit 037f1bf

Please sign in to comment.