Skip to content

Commit c69be04

Browse files
committed
Revert "Allow empty arrow bodies (#9)"
This reverts commit a7d60a7.
1 parent ce63a2f commit c69be04

18 files changed

Lines changed: 285 additions & 849 deletions

File tree

src/plugins/lightscript.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ pp.parseObjectComprehension = function(node) {
138138

139139
pp.parseWhiteBlock = function (allowDirectives?, isExpression?) {
140140
const node = this.startNode(), indentLevel = this.state.indentLevel;
141-
let allowEmptyBody = false;
142141

143142
// must start with colon or arrow
144143
if (isExpression) {
@@ -147,8 +146,6 @@ pp.parseWhiteBlock = function (allowDirectives?, isExpression?) {
147146
} else if (this.eat(tt.colon)) {
148147
if (!this.isLineBreak()) return this.parseStatement(false);
149148
} else if (this.eat(tt.arrow)) {
150-
allowEmptyBody = true;
151-
152149
if (!this.isLineBreak()) {
153150
if (this.match(tt.braceL)) {
154151
// restart node at brace start instead of arrow start
@@ -157,7 +154,7 @@ pp.parseWhiteBlock = function (allowDirectives?, isExpression?) {
157154
this.parseBlockBody(node, allowDirectives, false, tt.braceR);
158155
this.addExtra(node, "curly", true);
159156
return this.finishNode(node, "BlockStatement");
160-
} else if (this.state.type.startsExpr) {
157+
} else {
161158
return this.parseMaybeAssign();
162159
}
163160
}
@@ -168,9 +165,7 @@ pp.parseWhiteBlock = function (allowDirectives?, isExpression?) {
168165
// never parse directives if curly braces aren't used (TODO: document)
169166
this.parseBlockBody(node, false, false, indentLevel);
170167
this.addExtra(node, "curly", false);
171-
if (!allowEmptyBody && !node.body.length) {
172-
this.unexpected(node.start, "Expected an Indent or Statement");
173-
}
168+
if (!node.body.length) this.unexpected(node.start, "Expected an Indent or Statement");
174169

175170
return this.finishNode(node, "BlockStatement");
176171
};

src/tokenizer/types.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export const types = {
8080
doubleColon: new TokenType("::", { beforeExpr }),
8181
dot: new TokenType("."),
8282
question: new TokenType("?", { beforeExpr }),
83-
arrow: new TokenType("=>", { beforeExpr, startsExpr }),
83+
arrow: new TokenType("=>", { beforeExpr }),
8484
template: new TokenType("template"),
8585
ellipsis: new TokenType("...", { beforeExpr }),
8686
backQuote: new TokenType("`", { startsExpr }),

test/fixtures/flow/type-annotations/99/expected.json

Lines changed: 265 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,5 +161,269 @@
161161
],
162162
"directives": []
163163
},
164-
"comments": []
164+
"comments": [],
165+
"tokens": [
166+
{
167+
"type": {
168+
"label": "(",
169+
"beforeExpr": true,
170+
"startsExpr": true,
171+
"rightAssociative": false,
172+
"isLoop": false,
173+
"isAssign": false,
174+
"prefix": false,
175+
"postfix": false,
176+
"binop": null
177+
},
178+
"start": 0,
179+
"end": 1,
180+
"loc": {
181+
"start": {
182+
"line": 1,
183+
"column": 0
184+
},
185+
"end": {
186+
"line": 1,
187+
"column": 1
188+
}
189+
}
190+
},
191+
{
192+
"type": {
193+
"label": "name",
194+
"beforeExpr": false,
195+
"startsExpr": true,
196+
"rightAssociative": false,
197+
"isLoop": false,
198+
"isAssign": false,
199+
"prefix": false,
200+
"postfix": false,
201+
"binop": null
202+
},
203+
"value": "foo",
204+
"start": 1,
205+
"end": 4,
206+
"loc": {
207+
"start": {
208+
"line": 1,
209+
"column": 1
210+
},
211+
"end": {
212+
"line": 1,
213+
"column": 4
214+
}
215+
}
216+
},
217+
{
218+
"type": {
219+
"label": ",",
220+
"beforeExpr": true,
221+
"startsExpr": false,
222+
"rightAssociative": false,
223+
"isLoop": false,
224+
"isAssign": false,
225+
"prefix": false,
226+
"postfix": false,
227+
"binop": null,
228+
"updateContext": null
229+
},
230+
"start": 4,
231+
"end": 5,
232+
"loc": {
233+
"start": {
234+
"line": 1,
235+
"column": 4
236+
},
237+
"end": {
238+
"line": 1,
239+
"column": 5
240+
}
241+
}
242+
},
243+
{
244+
"type": {
245+
"label": "name",
246+
"beforeExpr": false,
247+
"startsExpr": true,
248+
"rightAssociative": false,
249+
"isLoop": false,
250+
"isAssign": false,
251+
"prefix": false,
252+
"postfix": false,
253+
"binop": null
254+
},
255+
"value": "bar",
256+
"start": 6,
257+
"end": 9,
258+
"loc": {
259+
"start": {
260+
"line": 1,
261+
"column": 6
262+
},
263+
"end": {
264+
"line": 1,
265+
"column": 9
266+
}
267+
}
268+
},
269+
{
270+
"type": {
271+
"label": ")",
272+
"beforeExpr": false,
273+
"startsExpr": false,
274+
"rightAssociative": false,
275+
"isLoop": false,
276+
"isAssign": false,
277+
"prefix": false,
278+
"postfix": false,
279+
"binop": null
280+
},
281+
"start": 9,
282+
"end": 10,
283+
"loc": {
284+
"start": {
285+
"line": 1,
286+
"column": 9
287+
},
288+
"end": {
289+
"line": 1,
290+
"column": 10
291+
}
292+
}
293+
},
294+
{
295+
"type": {
296+
"label": ":",
297+
"beforeExpr": true,
298+
"startsExpr": false,
299+
"rightAssociative": false,
300+
"isLoop": false,
301+
"isAssign": false,
302+
"prefix": false,
303+
"postfix": false,
304+
"binop": null,
305+
"updateContext": null
306+
},
307+
"start": 10,
308+
"end": 11,
309+
"loc": {
310+
"start": {
311+
"line": 1,
312+
"column": 10
313+
},
314+
"end": {
315+
"line": 1,
316+
"column": 11
317+
}
318+
}
319+
},
320+
{
321+
"type": {
322+
"label": "name",
323+
"beforeExpr": false,
324+
"startsExpr": true,
325+
"rightAssociative": false,
326+
"isLoop": false,
327+
"isAssign": false,
328+
"prefix": false,
329+
"postfix": false,
330+
"binop": null
331+
},
332+
"value": "z",
333+
"start": 12,
334+
"end": 13,
335+
"loc": {
336+
"start": {
337+
"line": 1,
338+
"column": 12
339+
},
340+
"end": {
341+
"line": 1,
342+
"column": 13
343+
}
344+
}
345+
},
346+
{
347+
"type": {
348+
"label": "=>",
349+
"beforeExpr": true,
350+
"startsExpr": false,
351+
"rightAssociative": false,
352+
"isLoop": false,
353+
"isAssign": false,
354+
"prefix": false,
355+
"postfix": false,
356+
"binop": null,
357+
"updateContext": null
358+
},
359+
"start": 14,
360+
"end": 16,
361+
"loc": {
362+
"start": {
363+
"line": 1,
364+
"column": 14
365+
366+
367+
},
368+
"end": {
369+
"line": 1,
370+
"column": 16
371+
}
372+
}
373+
},
374+
{
375+
"type": {
376+
"label": "null",
377+
"keyword": "null",
378+
"beforeExpr": false,
379+
"startsExpr": true,
380+
"rightAssociative": false,
381+
"isLoop": false,
382+
"isAssign": false,
383+
"prefix": false,
384+
"postfix": false,
385+
"binop": null,
386+
"updateContext": null
387+
},
388+
"value": "null",
389+
"start": 17,
390+
"end": 21,
391+
"loc": {
392+
"start": {
393+
"line": 1,
394+
"column": 17
395+
},
396+
"end": {
397+
"line": 1,
398+
"column": 21
399+
}
400+
}
401+
},
402+
{
403+
"type": {
404+
"label": "eof",
405+
"beforeExpr": false,
406+
"startsExpr": false,
407+
"rightAssociative": false,
408+
"isLoop": false,
409+
"isAssign": false,
410+
"prefix": false,
411+
"postfix": false,
412+
"binop": null,
413+
"updateContext": null
414+
},
415+
"start": 21,
416+
"end": 21,
417+
"loc": {
418+
"start": {
419+
"line": 1,
420+
"column": 21
421+
},
422+
"end": {
423+
"line": 1,
424+
"column": 21
425+
}
426+
}
427+
}
428+
]
165429
}

test/fixtures/lightscript/arrow-expressions/skinny-empty-double/actual.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)