Skip to content

Commit ba10bc8

Browse files
committed
Oneline whiteblock parsing fixes
Restore `startsExpr` to arrow token type Remove extraneous `startNode` Cleanup - Remove `finishWhiteBlock` - Add back `startNode()` in arrow parsing Fix incorrect token stream in flow fixture - Result of adding `startsExpr` to `->` Fix incorrect token positions in fixture
1 parent cb58ac7 commit ba10bc8

File tree

4 files changed

+15
-283
lines changed

4 files changed

+15
-283
lines changed

src/plugins/lightscript.js

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -134,27 +134,23 @@ pp.parseObjectComprehension = function(node) {
134134
return this.finishNode(node, "ObjectComprehension");
135135
};
136136

137-
pp.finishWhiteBlock = function(node) {
138-
if (!node.body.length) {
139-
this.unexpected(node.start, "Expected an Indent or Statement");
140-
}
141-
142-
this.addExtra(node, "curly", false);
143-
return this.finishNode(node, "BlockStatement");
144-
};
145-
146137
pp.parseInlineWhiteBlock = function(node) {
147138
if (this.state.type.startsExpr) return this.parseMaybeAssign();
148139
// oneline statement case
149140
node.body = [this.parseStatement(true)];
150141
node.directives = [];
151-
return this.finishWhiteBlock(node);
142+
this.addExtra(node, "curly", false);
143+
return this.finishNode(node, "BlockStatement");
152144
};
153145

154-
155146
pp.parseMultilineWhiteBlock = function(node, indentLevel) {
156147
this.parseBlockBody(node, false, false, indentLevel);
157-
return this.finishWhiteBlock(node);
148+
if (!node.body.length) {
149+
this.unexpected(node.start, "Expected an Indent or Statement");
150+
}
151+
152+
this.addExtra(node, "curly", false);
153+
return this.finishNode(node, "BlockStatement");
158154
};
159155

160156
pp.parseWhiteBlock = function (isExpression?) {
@@ -307,7 +303,7 @@ pp.parseArrowFunctionBody = function (node) {
307303
this.state.inFunction = true;
308304

309305
const indentLevel = this.state.indentLevel;
310-
node.body = this.startNode();
306+
const nodeAtArrow = this.startNode();
311307
this.expect(tt.arrow);
312308
if (!this.isLineBreak()) {
313309
if (this.match(tt.braceL)) {
@@ -318,10 +314,10 @@ pp.parseArrowFunctionBody = function (node) {
318314
this.addExtra(node.body, "curly", true);
319315
node.body = this.finishNode(node.body, "BlockStatement");
320316
} else {
321-
node.body = this.parseInlineWhiteBlock(node.body);
317+
node.body = this.parseInlineWhiteBlock(nodeAtArrow);
322318
}
323319
} else {
324-
node.body = this.parseMultilineWhiteBlock(node.body, indentLevel);
320+
node.body = this.parseMultilineWhiteBlock(nodeAtArrow, indentLevel);
325321
}
326322

327323
if (node.body.type !== "BlockStatement") {

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 }),
83+
arrow: new TokenType("=>", { beforeExpr, startsExpr }),
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: 1 addition & 265 deletions
Original file line numberDiff line numberDiff line change
@@ -161,269 +161,5 @@
161161
],
162162
"directives": []
163163
},
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-
]
164+
"comments": []
429165
}

test/fixtures/lightscript/automatic-semicolon-insertion/new/expected.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
"loc": {
118118
"start": {
119119
"line": 2,
120-
"column": 7
120+
"column": 4
121121
},
122122
"end": {
123123
"line": 2,
@@ -144,7 +144,7 @@
144144
],
145145
"directives": [],
146146
"extra": {
147-
"curly": true
147+
"curly": false
148148
}
149149
},
150150
"extra": {

0 commit comments

Comments
 (0)