diff --git a/src/parser/util.js b/src/parser/util.js index ea34bec217..00865943e8 100644 --- a/src/parser/util.js +++ b/src/parser/util.js @@ -65,7 +65,18 @@ pp.isLineBreak = function () { pp.canInsertSemicolon = function () { return this.match(tt.eof) || this.match(tt.braceR) || - this.isLineBreak(); + this.isLineBreak() || + (this.hasPlugin("lightscript") && ( + // LSC oneline statement ASI cases + // Allow if x: throw y else: throw z + this.match(tt._else) || + this.match(tt._elif) || + // Allow (-> throw new Error)() + this.match(tt.parenR) || + // Technically it is legal to insert a ; after a ;. + // Allows -> throw new Error; f() + this.state.tokens[this.state.tokens.length - 1].type === tt.semi + )); }; // TODO diff --git a/src/plugins/lightscript.js b/src/plugins/lightscript.js index 71769d9a3a..d574d79edb 100644 --- a/src/plugins/lightscript.js +++ b/src/plugins/lightscript.js @@ -134,40 +134,41 @@ pp.parseObjectComprehension = function(node) { return this.finishNode(node, "ObjectComprehension"); }; -// c/p parseBlock +pp.parseInlineWhiteBlock = function(node) { + if (this.state.type.startsExpr) return this.parseMaybeAssign(); + // oneline statement case + node.body = [this.parseStatement(true)]; + node.directives = []; + this.addExtra(node, "curly", false); + return this.finishNode(node, "BlockStatement"); +}; + +pp.parseMultilineWhiteBlock = function(node, indentLevel) { + this.parseBlockBody(node, false, false, indentLevel); + if (!node.body.length) { + this.unexpected(node.start, "Expected an Indent or Statement"); + } + + this.addExtra(node, "curly", false); + return this.finishNode(node, "BlockStatement"); +}; -pp.parseWhiteBlock = function (allowDirectives?, isExpression?) { +pp.parseWhiteBlock = function (isExpression?) { const node = this.startNode(), indentLevel = this.state.indentLevel; - // must start with colon or arrow - if (isExpression) { - this.expect(tt.colon); - if (!this.isLineBreak()) return this.parseMaybeAssign(); - } else if (this.eat(tt.colon)) { - if (!this.isLineBreak()) return this.parseStatement(false); - } else if (this.eat(tt.arrow)) { - if (!this.isLineBreak()) { - if (this.match(tt.braceL)) { - // restart node at brace start instead of arrow start - const node = this.startNode(); - this.next(); - this.parseBlockBody(node, allowDirectives, false, tt.braceR); - this.addExtra(node, "curly", true); - return this.finishNode(node, "BlockStatement"); - } else { - return this.parseMaybeAssign(); - } + if (!this.eat(tt.colon)) this.unexpected(null, "Whitespace Block must start with a colon or arrow"); + + // Oneline whiteblock + if (!this.isLineBreak()) { + if (isExpression) { + return this.parseInlineWhiteBlock(node); + } else { + return this.parseStatement(false); } - } else { - this.unexpected(null, "Whitespace Block must start with a colon or arrow"); } - // never parse directives if curly braces aren't used (TODO: document) - this.parseBlockBody(node, false, false, indentLevel); - this.addExtra(node, "curly", false); - if (!node.body.length) this.unexpected(node.start, "Expected an Indent or Statement"); - - return this.finishNode(node, "BlockStatement"); + // TODO: document the fact that directives aren't parsed + return this.parseMultilineWhiteBlock(node, indentLevel); }; pp.expectCommaOrLineBreak = function () { @@ -301,7 +302,23 @@ pp.parseArrowFunctionBody = function (node) { this.state.labels = []; this.state.inFunction = true; - node.body = this.parseWhiteBlock(true); + const indentLevel = this.state.indentLevel; + const nodeAtArrow = this.startNode(); + this.expect(tt.arrow); + if (!this.isLineBreak()) { + if (this.match(tt.braceL)) { + // restart node at brace start instead of arrow start + node.body = this.startNode(); + this.next(); + this.parseBlockBody(node.body, true, false, tt.braceR); + this.addExtra(node.body, "curly", true); + node.body = this.finishNode(node.body, "BlockStatement"); + } else { + node.body = this.parseInlineWhiteBlock(nodeAtArrow); + } + } else { + node.body = this.parseMultilineWhiteBlock(nodeAtArrow, indentLevel); + } if (node.body.type !== "BlockStatement") { node.expression = true; @@ -376,7 +393,7 @@ pp.parseIf = function (node, isExpression) { } else if (!isColon) { node.consequent = this.parseMaybeAssign(); } else { - node.consequent = this.parseWhiteBlock(false, true); + node.consequent = this.parseWhiteBlock(true); } } else { node.consequent = this.parseStatement(false); @@ -425,7 +442,7 @@ pp.parseIfAlternate = function (node, isExpression, ifIsWhiteBlock, ifIndentLeve } else if (!this.match(tt.colon)) { return this.parseMaybeAssign(); } else { - return this.parseWhiteBlock(false, true); + return this.parseWhiteBlock(true); } } @@ -613,9 +630,9 @@ export default function (instance) { // whitespace following a colon instance.extend("parseBlock", function (inner) { - return function (allowDirectives) { + return function () { if (this.match(tt.colon)) { - return this.parseWhiteBlock(allowDirectives); + return this.parseWhiteBlock(); } const block = inner.apply(this, arguments); this.addExtra(block, "curly", true); diff --git a/src/tokenizer/types.js b/src/tokenizer/types.js index 42bc48c51e..8e0d0a3807 100644 --- a/src/tokenizer/types.js +++ b/src/tokenizer/types.js @@ -80,7 +80,7 @@ export const types = { doubleColon: new TokenType("::", { beforeExpr }), dot: new TokenType("."), question: new TokenType("?", { beforeExpr }), - arrow: new TokenType("=>", { beforeExpr }), + arrow: new TokenType("=>", { beforeExpr, startsExpr }), template: new TokenType("template"), ellipsis: new TokenType("...", { beforeExpr }), backQuote: new TokenType("`", { startsExpr }), @@ -152,7 +152,7 @@ export const keywords = { "new": new KeywordTokenType("new", { beforeExpr, startsExpr }), "this": new KeywordTokenType("this", { startsExpr }), "super": new KeywordTokenType("super", { startsExpr }), - "class": new KeywordTokenType("class"), + "class": new KeywordTokenType("class", { startsExpr }), "extends": new KeywordTokenType("extends", { beforeExpr }), "export": new KeywordTokenType("export"), "import": new KeywordTokenType("import", { startsExpr }), diff --git a/test/fixtures/flow/type-annotations/99/expected.json b/test/fixtures/flow/type-annotations/99/expected.json index b261c3eff9..1c35c17698 100644 --- a/test/fixtures/flow/type-annotations/99/expected.json +++ b/test/fixtures/flow/type-annotations/99/expected.json @@ -161,269 +161,5 @@ ], "directives": [] }, - "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 - } - } - } - ] + "comments": [] } diff --git a/test/fixtures/lightscript/arrow-expressions/fat-class-expr/actual.js b/test/fixtures/lightscript/arrow-expressions/fat-class-expr/actual.js new file mode 100644 index 0000000000..c8b010804c --- /dev/null +++ b/test/fixtures/lightscript/arrow-expressions/fat-class-expr/actual.js @@ -0,0 +1 @@ +x = arg => class X {} diff --git a/test/fixtures/lightscript/arrow-expressions/fat-class-expr/expected.json b/test/fixtures/lightscript/arrow-expressions/fat-class-expr/expected.json new file mode 100644 index 0000000000..8f6a32cf56 --- /dev/null +++ b/test/fixtures/lightscript/arrow-expressions/fat-class-expr/expected.json @@ -0,0 +1,175 @@ +{ + "type": "File", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "sourceType": "script", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "kind": "const", + "extra": { + "implicit": true + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "id": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "init": { + "type": "ArrowFunctionExpression", + "start": 4, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 4, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "arg" + }, + "name": "arg" + } + ], + "skinny": false, + "body": { + "type": "ClassExpression", + "start": 11, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "id": { + "type": "Identifier", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 18 + }, + "identifierName": "X" + }, + "name": "X" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 19, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "body": [] + } + } + } + } + ] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/arrow-expressions/oneline-stmt/actual.js b/test/fixtures/lightscript/arrow-expressions/oneline-stmt/actual.js new file mode 100644 index 0000000000..09dd16ccc3 --- /dev/null +++ b/test/fixtures/lightscript/arrow-expressions/oneline-stmt/actual.js @@ -0,0 +1 @@ +-> throw new Error diff --git a/test/fixtures/lightscript/arrow-expressions/oneline-stmt/expected.json b/test/fixtures/lightscript/arrow-expressions/oneline-stmt/expected.json new file mode 100644 index 0000000000..7282b6c1c6 --- /dev/null +++ b/test/fixtures/lightscript/arrow-expressions/oneline-stmt/expected.json @@ -0,0 +1,139 @@ +{ + "type": "File", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "BlockStatement", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "body": [ + { + "type": "ThrowStatement", + "start": 3, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "argument": { + "type": "NewExpression", + "start": 9, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "callee": { + "type": "Identifier", + "start": 13, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 18 + }, + "identifierName": "Error" + }, + "name": "Error" + }, + "arguments": [] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/arrow-expressions/skinny-double/actual.js b/test/fixtures/lightscript/arrow-expressions/skinny-double/actual.js new file mode 100644 index 0000000000..8ee35e0c47 --- /dev/null +++ b/test/fixtures/lightscript/arrow-expressions/skinny-double/actual.js @@ -0,0 +1 @@ +f() -> -> x diff --git a/test/fixtures/lightscript/arrow-expressions/skinny-double/expected.json b/test/fixtures/lightscript/arrow-expressions/skinny-double/expected.json new file mode 100644 index 0000000000..07ebac842e --- /dev/null +++ b/test/fixtures/lightscript/arrow-expressions/skinny-double/expected.json @@ -0,0 +1,109 @@ +{ + "type": "File", + "start": 0, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "sourceType": "script", + "body": [ + { + "type": "NamedArrowDeclaration", + "start": 0, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "id": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "f" + }, + "name": "f" + }, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "ArrowFunctionExpression", + "start": 7, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "Identifier", + "start": 10, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/arrow-expressions/skinny-oneline-stmt-semi/actual.js b/test/fixtures/lightscript/arrow-expressions/skinny-oneline-stmt-semi/actual.js new file mode 100644 index 0000000000..077bb60c5c --- /dev/null +++ b/test/fixtures/lightscript/arrow-expressions/skinny-oneline-stmt-semi/actual.js @@ -0,0 +1 @@ +-> for idx i in Array(1): i; after() diff --git a/test/fixtures/lightscript/arrow-expressions/skinny-oneline-stmt-semi/expected.json b/test/fixtures/lightscript/arrow-expressions/skinny-oneline-stmt-semi/expected.json new file mode 100644 index 0000000000..82c109f5e3 --- /dev/null +++ b/test/fixtures/lightscript/arrow-expressions/skinny-oneline-stmt-semi/expected.json @@ -0,0 +1,257 @@ +{ + "type": "File", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 28 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 28 + } + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "BlockStatement", + "start": 0, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 28 + } + }, + "body": [ + { + "type": "ForInArrayStatement", + "start": 3, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 28 + } + }, + "idx": { + "type": "Identifier", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "i" + }, + "name": "i" + }, + "body": { + "type": "ExpressionStatement", + "start": 26, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 28 + } + }, + "expression": { + "type": "Identifier", + "start": 26, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 27 + }, + "identifierName": "i" + }, + "name": "i" + } + }, + "array": { + "type": "CallExpression", + "start": 16, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "callee": { + "type": "Identifier", + "start": 16, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 21 + }, + "identifierName": "Array" + }, + "name": "Array" + }, + "arguments": [ + { + "type": "NumericLiteral", + "start": 22, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + ] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + }, + { + "type": "ExpressionStatement", + "start": 29, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 29 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "expression": { + "type": "CallExpression", + "start": 29, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 29 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "callee": { + "type": "Identifier", + "start": 29, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 29 + }, + "end": { + "line": 1, + "column": 34 + }, + "identifierName": "after" + }, + "name": "after" + }, + "arguments": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/arrow-expressions/skinny-oneline-stmt/actual.js b/test/fixtures/lightscript/arrow-expressions/skinny-oneline-stmt/actual.js new file mode 100644 index 0000000000..e3e948d845 --- /dev/null +++ b/test/fixtures/lightscript/arrow-expressions/skinny-oneline-stmt/actual.js @@ -0,0 +1 @@ +-> for idx i in Array(1): i diff --git a/test/fixtures/lightscript/arrow-expressions/skinny-oneline-stmt/expected.json b/test/fixtures/lightscript/arrow-expressions/skinny-oneline-stmt/expected.json new file mode 100644 index 0000000000..bd37695194 --- /dev/null +++ b/test/fixtures/lightscript/arrow-expressions/skinny-oneline-stmt/expected.json @@ -0,0 +1,209 @@ +{ + "type": "File", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "BlockStatement", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "body": [ + { + "type": "ForInArrayStatement", + "start": 3, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "idx": { + "type": "Identifier", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "i" + }, + "name": "i" + }, + "body": { + "type": "ExpressionStatement", + "start": 26, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "expression": { + "type": "Identifier", + "start": 26, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 27 + }, + "identifierName": "i" + }, + "name": "i" + } + }, + "array": { + "type": "CallExpression", + "start": 16, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "callee": { + "type": "Identifier", + "start": 16, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 21 + }, + "identifierName": "Array" + }, + "name": "Array" + }, + "arguments": [ + { + "type": "NumericLiteral", + "start": 22, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + ] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/arrow-expressions/stmt-call/actual.js b/test/fixtures/lightscript/arrow-expressions/stmt-call/actual.js new file mode 100644 index 0000000000..ffd457e110 --- /dev/null +++ b/test/fixtures/lightscript/arrow-expressions/stmt-call/actual.js @@ -0,0 +1 @@ +(-> throw new Error)() diff --git a/test/fixtures/lightscript/arrow-expressions/stmt-call/expected.json b/test/fixtures/lightscript/arrow-expressions/stmt-call/expected.json new file mode 100644 index 0000000000..86e6952484 --- /dev/null +++ b/test/fixtures/lightscript/arrow-expressions/stmt-call/expected.json @@ -0,0 +1,159 @@ +{ + "type": "File", + "start": 0, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "expression": { + "type": "CallExpression", + "start": 0, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "callee": { + "type": "ArrowFunctionExpression", + "start": 1, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "BlockStatement", + "start": 1, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "body": [ + { + "type": "ThrowStatement", + "start": 4, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "argument": { + "type": "NewExpression", + "start": 10, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "callee": { + "type": "Identifier", + "start": 14, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 19 + }, + "identifierName": "Error" + }, + "name": "Error" + }, + "arguments": [] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + }, + "extra": { + "parenthesized": true, + "parenStart": 0 + } + }, + "arguments": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/arrow-methods/class-skinny-oneline-stmt/actual.js b/test/fixtures/lightscript/arrow-methods/class-skinny-oneline-stmt/actual.js new file mode 100644 index 0000000000..cb3da60fc2 --- /dev/null +++ b/test/fixtures/lightscript/arrow-methods/class-skinny-oneline-stmt/actual.js @@ -0,0 +1,2 @@ +class X: + method() -> for idx i in Array(10): i diff --git a/test/fixtures/lightscript/arrow-methods/class-skinny-oneline-stmt/expected.json b/test/fixtures/lightscript/arrow-methods/class-skinny-oneline-stmt/expected.json new file mode 100644 index 0000000000..014ef59011 --- /dev/null +++ b/test/fixtures/lightscript/arrow-methods/class-skinny-oneline-stmt/expected.json @@ -0,0 +1,264 @@ +{ + "type": "File", + "start": 0, + "end": 48, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 39 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 48, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 39 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 48, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 39 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "X" + }, + "name": "X" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 7, + "end": 48, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 2, + "column": 39 + } + }, + "body": [ + { + "type": "ClassMethod", + "start": 11, + "end": 48, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 39 + } + }, + "computed": false, + "key": { + "type": "Identifier", + "start": 11, + "end": 17, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 8 + }, + "identifierName": "method" + }, + "name": "method" + }, + "static": false, + "kind": "method", + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "BlockStatement", + "start": 20, + "end": 48, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 39 + } + }, + "body": [ + { + "type": "ForInArrayStatement", + "start": 23, + "end": 48, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 39 + } + }, + "idx": { + "type": "Identifier", + "start": 31, + "end": 32, + "loc": { + "start": { + "line": 2, + "column": 22 + }, + "end": { + "line": 2, + "column": 23 + }, + "identifierName": "i" + }, + "name": "i" + }, + "body": { + "type": "ExpressionStatement", + "start": 47, + "end": 48, + "loc": { + "start": { + "line": 2, + "column": 38 + }, + "end": { + "line": 2, + "column": 39 + } + }, + "expression": { + "type": "Identifier", + "start": 47, + "end": 48, + "loc": { + "start": { + "line": 2, + "column": 38 + }, + "end": { + "line": 2, + "column": 39 + }, + "identifierName": "i" + }, + "name": "i" + } + }, + "array": { + "type": "CallExpression", + "start": 36, + "end": 45, + "loc": { + "start": { + "line": 2, + "column": 27 + }, + "end": { + "line": 2, + "column": 36 + } + }, + "callee": { + "type": "Identifier", + "start": 36, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 27 + }, + "end": { + "line": 2, + "column": 32 + }, + "identifierName": "Array" + }, + "name": "Array" + }, + "arguments": [ + { + "type": "NumericLiteral", + "start": 42, + "end": 44, + "loc": { + "start": { + "line": 2, + "column": 33 + }, + "end": { + "line": 2, + "column": 35 + } + }, + "extra": { + "rawValue": 10, + "raw": "10" + }, + "value": 10 + } + ] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/arrow-methods/obj-skinny-oneline-stmt/actual.js b/test/fixtures/lightscript/arrow-methods/obj-skinny-oneline-stmt/actual.js new file mode 100644 index 0000000000..b3aa470902 --- /dev/null +++ b/test/fixtures/lightscript/arrow-methods/obj-skinny-oneline-stmt/actual.js @@ -0,0 +1,3 @@ +x = { + method() -> for idx i in Array(10): i +} diff --git a/test/fixtures/lightscript/arrow-methods/obj-skinny-oneline-stmt/expected.json b/test/fixtures/lightscript/arrow-methods/obj-skinny-oneline-stmt/expected.json new file mode 100644 index 0000000000..7e36959deb --- /dev/null +++ b/test/fixtures/lightscript/arrow-methods/obj-skinny-oneline-stmt/expected.json @@ -0,0 +1,285 @@ +{ + "type": "File", + "start": 0, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "sourceType": "script", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "kind": "const", + "extra": { + "implicit": true + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 0, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "init": { + "type": "ObjectExpression", + "start": 4, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "properties": [ + { + "type": "ObjectMethod", + "start": 8, + "end": 45, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 39 + } + }, + "method": true, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 8, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 8 + }, + "identifierName": "method" + }, + "name": "method" + }, + "kind": "method", + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "BlockStatement", + "start": 17, + "end": 45, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 39 + } + }, + "body": [ + { + "type": "ForInArrayStatement", + "start": 20, + "end": 45, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 39 + } + }, + "idx": { + "type": "Identifier", + "start": 28, + "end": 29, + "loc": { + "start": { + "line": 2, + "column": 22 + }, + "end": { + "line": 2, + "column": 23 + }, + "identifierName": "i" + }, + "name": "i" + }, + "body": { + "type": "ExpressionStatement", + "start": 44, + "end": 45, + "loc": { + "start": { + "line": 2, + "column": 38 + }, + "end": { + "line": 2, + "column": 39 + } + }, + "expression": { + "type": "Identifier", + "start": 44, + "end": 45, + "loc": { + "start": { + "line": 2, + "column": 38 + }, + "end": { + "line": 2, + "column": 39 + }, + "identifierName": "i" + }, + "name": "i" + } + }, + "array": { + "type": "CallExpression", + "start": 33, + "end": 42, + "loc": { + "start": { + "line": 2, + "column": 27 + }, + "end": { + "line": 2, + "column": 36 + } + }, + "callee": { + "type": "Identifier", + "start": 33, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 27 + }, + "end": { + "line": 2, + "column": 32 + }, + "identifierName": "Array" + }, + "name": "Array" + }, + "arguments": [ + { + "type": "NumericLiteral", + "start": 39, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 33 + }, + "end": { + "line": 2, + "column": 35 + } + }, + "extra": { + "rawValue": 10, + "raw": "10" + }, + "value": 10 + } + ] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + ] + } + } + ] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/automatic-semicolon-insertion/new/actual.js b/test/fixtures/lightscript/automatic-semicolon-insertion/new/actual.js index 97e8117a85..b9801e8573 100644 --- a/test/fixtures/lightscript/automatic-semicolon-insertion/new/actual.js +++ b/test/fixtures/lightscript/automatic-semicolon-insertion/new/actual.js @@ -1,2 +1,2 @@ new X -(() -> {}) +(() -> return) diff --git a/test/fixtures/lightscript/automatic-semicolon-insertion/new/expected.json b/test/fixtures/lightscript/automatic-semicolon-insertion/new/expected.json index fe9c25f8d4..a2967bd0f9 100644 --- a/test/fixtures/lightscript/automatic-semicolon-insertion/new/expected.json +++ b/test/fixtures/lightscript/automatic-semicolon-insertion/new/expected.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 16, + "end": 20, "loc": { "start": { "line": 1, @@ -9,13 +9,13 @@ }, "end": { "line": 2, - "column": 10 + "column": 14 } }, "program": { "type": "Program", "start": 0, - "end": 16, + "end": 20, "loc": { "start": { "line": 1, @@ -23,7 +23,7 @@ }, "end": { "line": 2, - "column": 10 + "column": 14 } }, "sourceType": "script", @@ -79,7 +79,7 @@ { "type": "ExpressionStatement", "start": 6, - "end": 16, + "end": 20, "loc": { "start": { "line": 2, @@ -87,13 +87,13 @@ }, "end": { "line": 2, - "column": 10 + "column": 14 } }, "expression": { "type": "ArrowFunctionExpression", "start": 7, - "end": 15, + "end": 19, "loc": { "start": { "line": 2, @@ -101,7 +101,7 @@ }, "end": { "line": 2, - "column": 9 + "column": 13 } }, "id": null, @@ -112,22 +112,39 @@ "skinny": true, "body": { "type": "BlockStatement", - "start": 13, - "end": 15, + "start": 10, + "end": 19, "loc": { "start": { "line": 2, - "column": 7 + "column": 4 }, "end": { "line": 2, - "column": 9 + "column": 13 } }, - "body": [], + "body": [ + { + "type": "ReturnStatement", + "start": 13, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "argument": null + } + ], "directives": [], "extra": { - "curly": true + "curly": false } }, "extra": { diff --git a/test/fixtures/lightscript/if-expression/oneline-stmt/actual.js b/test/fixtures/lightscript/if-expression/oneline-stmt/actual.js new file mode 100644 index 0000000000..45fb36cbb0 --- /dev/null +++ b/test/fixtures/lightscript/if-expression/oneline-stmt/actual.js @@ -0,0 +1,2 @@ +-> + x = if y: return z else: throw new Error diff --git a/test/fixtures/lightscript/if-expression/oneline-stmt/expected.json b/test/fixtures/lightscript/if-expression/oneline-stmt/expected.json new file mode 100644 index 0000000000..8df7170f95 --- /dev/null +++ b/test/fixtures/lightscript/if-expression/oneline-stmt/expected.json @@ -0,0 +1,298 @@ +{ + "type": "File", + "start": 0, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 42 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 42 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 42 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 42 + } + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "BlockStatement", + "start": 0, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 42 + } + }, + "body": [ + { + "type": "VariableDeclaration", + "start": 5, + "end": 45, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 42 + } + }, + "kind": "const", + "extra": { + "implicit": true + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 5, + "end": 45, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 42 + } + }, + "id": { + "type": "Identifier", + "start": 5, + "end": 6, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + }, + "identifierName": "x" + }, + "name": "x" + }, + "init": { + "type": "IfExpression", + "start": 9, + "end": 45, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 42 + } + }, + "test": { + "type": "Identifier", + "start": 12, + "end": 13, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 10 + }, + "identifierName": "y" + }, + "name": "y" + }, + "consequent": { + "type": "BlockStatement", + "start": 13, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "body": [ + { + "type": "ReturnStatement", + "start": 15, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "argument": { + "type": "Identifier", + "start": 22, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 20 + }, + "identifierName": "z" + }, + "name": "z" + } + } + ], + "directives": [], + "extra": { + "curly": false + } + }, + "alternate": { + "type": "BlockStatement", + "start": 28, + "end": 45, + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 2, + "column": 42 + } + }, + "body": [ + { + "type": "ThrowStatement", + "start": 30, + "end": 45, + "loc": { + "start": { + "line": 2, + "column": 27 + }, + "end": { + "line": 2, + "column": 42 + } + }, + "argument": { + "type": "NewExpression", + "start": 36, + "end": 45, + "loc": { + "start": { + "line": 2, + "column": 33 + }, + "end": { + "line": 2, + "column": 42 + } + }, + "callee": { + "type": "Identifier", + "start": 40, + "end": 45, + "loc": { + "start": { + "line": 2, + "column": 37 + }, + "end": { + "line": 2, + "column": 42 + }, + "identifierName": "Error" + }, + "name": "Error" + }, + "arguments": [] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + } + ] + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/if-statement/oneline-return-undelimited/expected.json b/test/fixtures/lightscript/if-statement/oneline-return-undelimited/expected.json new file mode 100644 index 0000000000..9ae52f58a5 --- /dev/null +++ b/test/fixtures/lightscript/if-statement/oneline-return-undelimited/expected.json @@ -0,0 +1,193 @@ +{ + "type": "File", + "start": 0, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 34 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 34 + } + }, + "sourceType": "script", + "body": [ + { + "type": "NamedArrowDeclaration", + "start": 0, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 34 + } + }, + "id": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "f" + }, + "name": "f" + }, + "generator": false, + "expression": false, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "BlockStatement", + "start": 4, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 2, + "column": 34 + } + }, + "body": [ + { + "type": "IfStatement", + "start": 9, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 34 + } + }, + "test": { + "type": "BooleanLiteral", + "start": 13, + "end": 17, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "value": true + }, + "consequent": { + "type": "ReturnStatement", + "start": 19, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "argument": { + "type": "NumericLiteral", + "start": 26, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + }, + "alternate": { + "type": "ReturnStatement", + "start": 33, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 26 + }, + "end": { + "line": 2, + "column": 34 + } + }, + "argument": { + "type": "NumericLiteral", + "start": 40, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 33 + }, + "end": { + "line": 2, + "column": 34 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/if-statement/oneline-return-undelimited/options.json b/test/fixtures/lightscript/if-statement/oneline-return-undelimited/options.json deleted file mode 100644 index 1a1435d58d..0000000000 --- a/test/fixtures/lightscript/if-statement/oneline-return-undelimited/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token, expected ; (2:21)" -} diff --git a/test/fixtures/lightscript/named-arrow-functions/skinny-oneline-stmt/actual.js b/test/fixtures/lightscript/named-arrow-functions/skinny-oneline-stmt/actual.js new file mode 100644 index 0000000000..482c28f8e4 --- /dev/null +++ b/test/fixtures/lightscript/named-arrow-functions/skinny-oneline-stmt/actual.js @@ -0,0 +1 @@ +f() -> for key k in o: k diff --git a/test/fixtures/lightscript/named-arrow-functions/skinny-oneline-stmt/expected.json b/test/fixtures/lightscript/named-arrow-functions/skinny-oneline-stmt/expected.json new file mode 100644 index 0000000000..66e2afa80b --- /dev/null +++ b/test/fixtures/lightscript/named-arrow-functions/skinny-oneline-stmt/expected.json @@ -0,0 +1,173 @@ +{ + "type": "File", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "sourceType": "script", + "body": [ + { + "type": "NamedArrowDeclaration", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "id": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "f" + }, + "name": "f" + }, + "generator": false, + "expression": false, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "BlockStatement", + "start": 4, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "body": [ + { + "type": "ForInObjectStatement", + "start": 7, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "key": { + "type": "Identifier", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 16 + }, + "identifierName": "k" + }, + "name": "k" + }, + "body": { + "type": "ExpressionStatement", + "start": 23, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "expression": { + "type": "Identifier", + "start": 23, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 24 + }, + "identifierName": "k" + }, + "name": "k" + } + }, + "object": { + "type": "Identifier", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 21 + }, + "identifierName": "o" + }, + "name": "o" + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + ], + "directives": [] + } +} \ No newline at end of file