Skip to content

Commit bda54e5

Browse files
committed
Comprehension fixes
1 parent 476419a commit bda54e5

File tree

4 files changed

+373
-3
lines changed

4 files changed

+373
-3
lines changed

src/parser/expression.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1089,10 +1089,10 @@ pp.parseObj = function (isPattern, refShorthandDefaultPos) {
10891089
this.hasPlugin("enhancedComprehension") &&
10901090
(this.match(tt._for) || this.match(tt._case))
10911091
) {
1092-
if (isPattern) {
1093-
this.unexpected(null, "Comprehensions are illegal in patterns.");
1094-
}
10951092
if (this.lookahead().type !== tt.colon) {
1093+
if (isPattern) {
1094+
this.unexpected(null, "Comprehensions are illegal in patterns.");
1095+
}
10961096
node.properties.push(this.parseSomeComprehension());
10971097
hasComprehension = true;
10981098
continue;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
if true: {
2+
for elem e in arr: e
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
{
2+
"type": "File",
3+
"start": 0,
4+
"end": 35,
5+
"loc": {
6+
"start": {
7+
"line": 1,
8+
"column": 0
9+
},
10+
"end": {
11+
"line": 3,
12+
"column": 1
13+
}
14+
},
15+
"program": {
16+
"type": "Program",
17+
"start": 0,
18+
"end": 35,
19+
"loc": {
20+
"start": {
21+
"line": 1,
22+
"column": 0
23+
},
24+
"end": {
25+
"line": 3,
26+
"column": 1
27+
}
28+
},
29+
"sourceType": "script",
30+
"body": [
31+
{
32+
"type": "IfStatement",
33+
"start": 0,
34+
"end": 35,
35+
"loc": {
36+
"start": {
37+
"line": 1,
38+
"column": 0
39+
},
40+
"end": {
41+
"line": 3,
42+
"column": 1
43+
}
44+
},
45+
"test": {
46+
"type": "BooleanLiteral",
47+
"start": 3,
48+
"end": 7,
49+
"loc": {
50+
"start": {
51+
"line": 1,
52+
"column": 3
53+
},
54+
"end": {
55+
"line": 1,
56+
"column": 7
57+
}
58+
},
59+
"value": true
60+
},
61+
"consequent": {
62+
"type": "BlockStatement",
63+
"start": 7,
64+
"end": 35,
65+
"loc": {
66+
"start": {
67+
"line": 1,
68+
"column": 7
69+
},
70+
"end": {
71+
"line": 3,
72+
"column": 1
73+
}
74+
},
75+
"body": [
76+
{
77+
"type": "ExpressionStatement",
78+
"start": 9,
79+
"end": 35,
80+
"loc": {
81+
"start": {
82+
"line": 1,
83+
"column": 9
84+
},
85+
"end": {
86+
"line": 3,
87+
"column": 1
88+
}
89+
},
90+
"expression": {
91+
"type": "ObjectComprehension",
92+
"start": 9,
93+
"end": 35,
94+
"loc": {
95+
"start": {
96+
"line": 1,
97+
"column": 9
98+
},
99+
"end": {
100+
"line": 3,
101+
"column": 1
102+
}
103+
},
104+
"properties": [],
105+
"loop": {
106+
"type": "ForInArrayStatement",
107+
"start": 13,
108+
"end": 33,
109+
"loc": {
110+
"start": {
111+
"line": 2,
112+
"column": 2
113+
},
114+
"end": {
115+
"line": 2,
116+
"column": 22
117+
}
118+
},
119+
"elem": {
120+
"type": "Identifier",
121+
"start": 22,
122+
"end": 23,
123+
"loc": {
124+
"start": {
125+
"line": 2,
126+
"column": 11
127+
},
128+
"end": {
129+
"line": 2,
130+
"column": 12
131+
},
132+
"identifierName": "e"
133+
},
134+
"name": "e"
135+
},
136+
"body": {
137+
"type": "ExpressionStatement",
138+
"start": 32,
139+
"end": 33,
140+
"loc": {
141+
"start": {
142+
"line": 2,
143+
"column": 21
144+
},
145+
"end": {
146+
"line": 2,
147+
"column": 22
148+
}
149+
},
150+
"expression": {
151+
"type": "Identifier",
152+
"start": 32,
153+
"end": 33,
154+
"loc": {
155+
"start": {
156+
"line": 2,
157+
"column": 21
158+
},
159+
"end": {
160+
"line": 2,
161+
"column": 22
162+
},
163+
"identifierName": "e"
164+
},
165+
"name": "e"
166+
}
167+
},
168+
"array": {
169+
"type": "Identifier",
170+
"start": 27,
171+
"end": 30,
172+
"loc": {
173+
"start": {
174+
"line": 2,
175+
"column": 16
176+
},
177+
"end": {
178+
"line": 2,
179+
"column": 19
180+
},
181+
"identifierName": "arr"
182+
},
183+
"name": "arr"
184+
}
185+
}
186+
}
187+
}
188+
],
189+
"directives": [],
190+
"extra": {
191+
"curly": false
192+
}
193+
},
194+
"alternate": null
195+
}
196+
],
197+
"directives": []
198+
}
199+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
{
2+
"type": "File",
3+
"start": 0,
4+
"end": 35,
5+
"loc": {
6+
"start": {
7+
"line": 1,
8+
"column": 0
9+
},
10+
"end": {
11+
"line": 3,
12+
"column": 1
13+
}
14+
},
15+
"program": {
16+
"type": "Program",
17+
"start": 0,
18+
"end": 35,
19+
"loc": {
20+
"start": {
21+
"line": 1,
22+
"column": 0
23+
},
24+
"end": {
25+
"line": 3,
26+
"column": 1
27+
}
28+
},
29+
"sourceType": "script",
30+
"body": [
31+
{
32+
"type": "IfStatement",
33+
"start": 0,
34+
"end": 35,
35+
"loc": {
36+
"start": {
37+
"line": 1,
38+
"column": 0
39+
},
40+
"end": {
41+
"line": 3,
42+
"column": 1
43+
}
44+
},
45+
"test": {
46+
"type": "BooleanLiteral",
47+
"start": 3,
48+
"end": 7,
49+
"loc": {
50+
"start": {
51+
"line": 1,
52+
"column": 3
53+
},
54+
"end": {
55+
"line": 1,
56+
"column": 7
57+
}
58+
},
59+
"value": true
60+
},
61+
"consequent": {
62+
"type": "BlockStatement",
63+
"start": 9,
64+
"end": 35,
65+
"loc": {
66+
"start": {
67+
"line": 1,
68+
"column": 9
69+
},
70+
"end": {
71+
"line": 3,
72+
"column": 1
73+
}
74+
},
75+
"body": [
76+
{
77+
"type": "ForInArrayStatement",
78+
"start": 13,
79+
"end": 33,
80+
"loc": {
81+
"start": {
82+
"line": 2,
83+
"column": 2
84+
},
85+
"end": {
86+
"line": 2,
87+
"column": 22
88+
}
89+
},
90+
"elem": {
91+
"type": "Identifier",
92+
"start": 22,
93+
"end": 23,
94+
"loc": {
95+
"start": {
96+
"line": 2,
97+
"column": 11
98+
},
99+
"end": {
100+
"line": 2,
101+
"column": 12
102+
},
103+
"identifierName": "e"
104+
},
105+
"name": "e"
106+
},
107+
"body": {
108+
"type": "ExpressionStatement",
109+
"start": 32,
110+
"end": 33,
111+
"loc": {
112+
"start": {
113+
"line": 2,
114+
"column": 21
115+
},
116+
"end": {
117+
"line": 2,
118+
"column": 22
119+
}
120+
},
121+
"expression": {
122+
"type": "Identifier",
123+
"start": 32,
124+
"end": 33,
125+
"loc": {
126+
"start": {
127+
"line": 2,
128+
"column": 21
129+
},
130+
"end": {
131+
"line": 2,
132+
"column": 22
133+
},
134+
"identifierName": "e"
135+
},
136+
"name": "e"
137+
}
138+
},
139+
"array": {
140+
"type": "Identifier",
141+
"start": 27,
142+
"end": 30,
143+
"loc": {
144+
"start": {
145+
"line": 2,
146+
"column": 16
147+
},
148+
"end": {
149+
"line": 2,
150+
"column": 19
151+
},
152+
"identifierName": "arr"
153+
},
154+
"name": "arr"
155+
}
156+
}
157+
],
158+
"directives": [],
159+
"extra": {
160+
"curly": true
161+
}
162+
},
163+
"alternate": null
164+
}
165+
],
166+
"directives": []
167+
}
168+
}

0 commit comments

Comments
 (0)