Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions src/plugins/lightscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ pp.parseObjectComprehension = function(node) {

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

// must start with colon or arrow
if (isExpression) {
Expand All @@ -147,8 +146,6 @@ pp.parseWhiteBlock = function (allowDirectives?, isExpression?) {
} else if (this.eat(tt.colon)) {
if (!this.isLineBreak()) return this.parseStatement(false);
} else if (this.eat(tt.arrow)) {
allowEmptyBody = true;

if (!this.isLineBreak()) {
if (this.match(tt.braceL)) {
// restart node at brace start instead of arrow start
Expand All @@ -157,7 +154,7 @@ pp.parseWhiteBlock = function (allowDirectives?, isExpression?) {
this.parseBlockBody(node, allowDirectives, false, tt.braceR);
this.addExtra(node, "curly", true);
return this.finishNode(node, "BlockStatement");
} else if (this.state.type.startsExpr) {
} else {
return this.parseMaybeAssign();
}
}
Expand All @@ -168,9 +165,7 @@ pp.parseWhiteBlock = function (allowDirectives?, isExpression?) {
// never parse directives if curly braces aren't used (TODO: document)
this.parseBlockBody(node, false, false, indentLevel);
this.addExtra(node, "curly", false);
if (!allowEmptyBody && !node.body.length) {
this.unexpected(node.start, "Expected an Indent or Statement");
}
if (!node.body.length) this.unexpected(node.start, "Expected an Indent or Statement");

return this.finishNode(node, "BlockStatement");
};
Expand Down
2 changes: 1 addition & 1 deletion src/tokenizer/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export const types = {
doubleColon: new TokenType("::", { beforeExpr }),
dot: new TokenType("."),
question: new TokenType("?", { beforeExpr }),
arrow: new TokenType("=>", { beforeExpr, startsExpr }),
arrow: new TokenType("=>", { beforeExpr }),
template: new TokenType("template"),
ellipsis: new TokenType("...", { beforeExpr }),
backQuote: new TokenType("`", { startsExpr }),
Expand Down
266 changes: 265 additions & 1 deletion test/fixtures/flow/type-annotations/99/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,269 @@
],
"directives": []
},
"comments": []
"comments": [],
"tokens": [
{
"type": {
"label": "(",
"beforeExpr": true,
"startsExpr": true,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,
"postfix": false,
"binop": null
},
"start": 0,
"end": 1,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 1
}
}
},
{
"type": {
"label": "name",
"beforeExpr": false,
"startsExpr": true,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,
"postfix": false,
"binop": null
},
"value": "foo",
"start": 1,
"end": 4,
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 4
}
}
},
{
"type": {
"label": ",",
"beforeExpr": true,
"startsExpr": false,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,
"postfix": false,
"binop": null,
"updateContext": null
},
"start": 4,
"end": 5,
"loc": {
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 1,
"column": 5
}
}
},
{
"type": {
"label": "name",
"beforeExpr": false,
"startsExpr": true,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,
"postfix": false,
"binop": null
},
"value": "bar",
"start": 6,
"end": 9,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 9
}
}
},
{
"type": {
"label": ")",
"beforeExpr": false,
"startsExpr": false,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,
"postfix": false,
"binop": null
},
"start": 9,
"end": 10,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 10
}
}
},
{
"type": {
"label": ":",
"beforeExpr": true,
"startsExpr": false,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,
"postfix": false,
"binop": null,
"updateContext": null
},
"start": 10,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 10
},
"end": {
"line": 1,
"column": 11
}
}
},
{
"type": {
"label": "name",
"beforeExpr": false,
"startsExpr": true,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,
"postfix": false,
"binop": null
},
"value": "z",
"start": 12,
"end": 13,
"loc": {
"start": {
"line": 1,
"column": 12
},
"end": {
"line": 1,
"column": 13
}
}
},
{
"type": {
"label": "=>",
"beforeExpr": true,
"startsExpr": false,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,
"postfix": false,
"binop": null,
"updateContext": null
},
"start": 14,
"end": 16,
"loc": {
"start": {
"line": 1,
"column": 14


},
"end": {
"line": 1,
"column": 16
}
}
},
{
"type": {
"label": "null",
"keyword": "null",
"beforeExpr": false,
"startsExpr": true,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,
"postfix": false,
"binop": null,
"updateContext": null
},
"value": "null",
"start": 17,
"end": 21,
"loc": {
"start": {
"line": 1,
"column": 17
},
"end": {
"line": 1,
"column": 21
}
}
},
{
"type": {
"label": "eof",
"beforeExpr": false,
"startsExpr": false,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,
"postfix": false,
"binop": null,
"updateContext": null
},
"start": 21,
"end": 21,
"loc": {
"start": {
"line": 1,
"column": 21
},
"end": {
"line": 1,
"column": 21
}
}
}
]
}

This file was deleted.

Loading