Skip to content

Commit 037f1bf

Browse files
committed
Merge pull request #126 from eslint/issue121
Fix: Yield should parse without an argument (fixes #121)
2 parents 4ca96e5 + 8ae98cf commit 037f1bf

6 files changed

+238
-2
lines changed

espree.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -4644,7 +4644,15 @@ function parseYieldExpression() {
46444644
delegateFlag = true;
46454645
}
46464646

4647-
expr = parseAssignmentExpression();
4647+
if (peekLineTerminator()) {
4648+
return markerApply(marker, astNodeFactory.createYieldExpression(null, delegateFlag));
4649+
}
4650+
4651+
if (!match(";")) {
4652+
if (!match("}") && lookahead.type !== Token.EOF) {
4653+
expr = parseAssignmentExpression();
4654+
}
4655+
}
46484656

46494657
return markerApply(marker, astNodeFactory.createYieldExpression(expr, delegateFlag));
46504658
}

lib/ast-node-factory.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ module.exports = {
787787
createYieldExpression: function(argument, delegate) {
788788
return {
789789
type: astNodeTypes.YieldExpression,
790-
argument: argument,
790+
argument: argument || null,
791791
delegate: delegate
792792
};
793793
},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
module.exports = {
2+
"type": "Program",
3+
"body": [
4+
{
5+
"type": "ExpressionStatement",
6+
"expression": {
7+
"type": "FunctionExpression",
8+
"id": null,
9+
"params": [],
10+
"body": {
11+
"type": "BlockStatement",
12+
"body": [
13+
{
14+
"type": "ExpressionStatement",
15+
"expression": {
16+
"type": "YieldExpression",
17+
"argument": null,
18+
"delegate": false,
19+
"range": [
20+
16,
21+
21
22+
],
23+
"loc": {
24+
"start": {
25+
"line": 1,
26+
"column": 16
27+
},
28+
"end": {
29+
"line": 1,
30+
"column": 21
31+
}
32+
}
33+
},
34+
"range": [
35+
16,
36+
22
37+
],
38+
"loc": {
39+
"start": {
40+
"line": 1,
41+
"column": 16
42+
},
43+
"end": {
44+
"line": 1,
45+
"column": 22
46+
}
47+
}
48+
}
49+
],
50+
"range": [
51+
14,
52+
23
53+
],
54+
"loc": {
55+
"start": {
56+
"line": 1,
57+
"column": 14
58+
},
59+
"end": {
60+
"line": 1,
61+
"column": 23
62+
}
63+
}
64+
},
65+
"generator": true,
66+
"expression": false,
67+
"range": [
68+
1,
69+
23
70+
],
71+
"loc": {
72+
"start": {
73+
"line": 1,
74+
"column": 1
75+
},
76+
"end": {
77+
"line": 1,
78+
"column": 23
79+
}
80+
}
81+
},
82+
"range": [
83+
0,
84+
25
85+
],
86+
"loc": {
87+
"start": {
88+
"line": 1,
89+
"column": 0
90+
},
91+
"end": {
92+
"line": 1,
93+
"column": 25
94+
}
95+
}
96+
}
97+
],
98+
"sourceType": "script",
99+
"range": [
100+
0,
101+
25
102+
],
103+
"loc": {
104+
"start": {
105+
"line": 1,
106+
"column": 0
107+
},
108+
"end": {
109+
"line": 1,
110+
"column": 25
111+
}
112+
}
113+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(function* () { yield });
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
module.exports = {
2+
"type": "Program",
3+
"body": [
4+
{
5+
"type": "ExpressionStatement",
6+
"expression": {
7+
"type": "FunctionExpression",
8+
"id": null,
9+
"params": [],
10+
"body": {
11+
"type": "BlockStatement",
12+
"body": [
13+
{
14+
"type": "ExpressionStatement",
15+
"expression": {
16+
"type": "YieldExpression",
17+
"argument": null,
18+
"delegate": false,
19+
"range": [
20+
16,
21+
21
22+
],
23+
"loc": {
24+
"start": {
25+
"line": 1,
26+
"column": 16
27+
},
28+
"end": {
29+
"line": 1,
30+
"column": 21
31+
}
32+
}
33+
},
34+
"range": [
35+
16,
36+
22
37+
],
38+
"loc": {
39+
"start": {
40+
"line": 1,
41+
"column": 16
42+
},
43+
"end": {
44+
"line": 1,
45+
"column": 22
46+
}
47+
}
48+
}
49+
],
50+
"range": [
51+
14,
52+
24
53+
],
54+
"loc": {
55+
"start": {
56+
"line": 1,
57+
"column": 14
58+
},
59+
"end": {
60+
"line": 1,
61+
"column": 24
62+
}
63+
}
64+
},
65+
"generator": true,
66+
"expression": false,
67+
"range": [
68+
1,
69+
24
70+
],
71+
"loc": {
72+
"start": {
73+
"line": 1,
74+
"column": 1
75+
},
76+
"end": {
77+
"line": 1,
78+
"column": 24
79+
}
80+
}
81+
},
82+
"range": [
83+
0,
84+
26
85+
],
86+
"loc": {
87+
"start": {
88+
"line": 1,
89+
"column": 0
90+
},
91+
"end": {
92+
"line": 1,
93+
"column": 26
94+
}
95+
}
96+
}
97+
],
98+
"sourceType": "script",
99+
"range": [
100+
0,
101+
26
102+
],
103+
"loc": {
104+
"start": {
105+
"line": 1,
106+
"column": 0
107+
},
108+
"end": {
109+
"line": 1,
110+
"column": 26
111+
}
112+
}
113+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(function* () { yield; });

0 commit comments

Comments
 (0)