diff --git a/src/parser/expression.js b/src/parser/expression.js index 1e35663089..81264f6941 100644 --- a/src/parser/expression.js +++ b/src/parser/expression.js @@ -701,7 +701,7 @@ pp.parseExprAtom = function (refShorthandDefaultPos) { return isSafe ? this.parseSafeAwait(node) : this.parseAwait(node); } - case tt._else: + case tt._else: case tt._elif: if (this.hasPlugin("lightscript")) { this.unexpected(null, "Unmatched `else` (must match indentation of the line with `if`)."); } diff --git a/src/plugins/lightscript.js b/src/plugins/lightscript.js index e5f873c10d..583b9ec6b4 100644 --- a/src/plugins/lightscript.js +++ b/src/plugins/lightscript.js @@ -386,6 +386,18 @@ pp.parseNamedArrowFromCallExpression = function (node, call) { return this.finishNode(node, isMember ? "NamedArrowMemberExpression" : "NamedArrowExpression"); }; +pp.pushBlockState = function (blockType, indentLevel) { + this.state.blockStack.push({ blockType, indentLevel }); +}; + +pp.matchBlockState = function(blockType, indentLevel) { + return this.state.blockStack.some( (x) => x.blockType === blockType && x.indentLevel === indentLevel ); +}; + +pp.popBlockState = function() { + this.state.blockStack.pop(); +}; + // c/p parseIfStatement pp.parseIf = function (node, isExpression) { @@ -393,10 +405,13 @@ pp.parseIf = function (node, isExpression) { this.next(); node.test = this.parseParenExpression(); + const isColon = this.match(tt.colon); + if (isColon) this.pushBlockState("if", indentLevel); + if (isExpression) { if (this.match(tt.braceL)) { node.consequent = this.parseBlock(false); - } else if (!this.match(tt.colon)) { + } else if (!isColon) { node.consequent = this.parseMaybeAssign(); } else { node.consequent = this.parseWhiteBlock(false, true); @@ -405,16 +420,24 @@ pp.parseIf = function (node, isExpression) { node.consequent = this.parseStatement(false); } - node.alternate = this.parseIfAlternate(node, isExpression, indentLevel); + node.alternate = this.parseIfAlternate(node, isExpression, isColon, indentLevel); + + if (isColon) this.popBlockState(); return this.finishNode(node, isExpression ? "IfExpression" : "IfStatement"); }; -pp.parseIfAlternate = function (node, isExpression, indentLevel) { - const isColon = node.consequent.extra && node.consequent.extra.curly === false; - - // if whitespace-block, must match indent level - if (isColon && this.state.indentLevel !== indentLevel) { +pp.parseIfAlternate = function (node, isExpression, ifIsWhiteBlock, ifIndentLevel) { + if (!this.match(tt._elif) && !this.match(tt._else)) return null; + + // If the indent level here doesn't match with the current whiteblock `if`, or + // it matches with a whiteblock `if` higher on the stack, then this alternate + // clause does not match the current `if` -- so unwind the recursive descent. + const alternateIndentLevel = this.state.indentLevel; + if ( + (alternateIndentLevel !== ifIndentLevel) && + (ifIsWhiteBlock || this.matchBlockState("if", alternateIndentLevel)) + ) { return null; } diff --git a/src/tokenizer/state.js b/src/tokenizer/state.js index 0a83daf29c..e69f12055f 100644 --- a/src/tokenizer/state.js +++ b/src/tokenizer/state.js @@ -33,6 +33,8 @@ export default class State { this.leadingComments = []; this.commentStack = []; + this.blockStack = []; + this.pos = this.lineStart = 0; this.curLine = options.startLine; diff --git a/test/fixtures/lightscript/if-expression/elif-indent-mismatch/actual.js b/test/fixtures/lightscript/if-expression/elif-indent-mismatch/actual.js new file mode 100644 index 0000000000..0a656310ba --- /dev/null +++ b/test/fixtures/lightscript/if-expression/elif-indent-mismatch/actual.js @@ -0,0 +1,3 @@ +x = if false: 1 + elif true: + 2 diff --git a/test/fixtures/lightscript/if-expression/elif-indent-mismatch/options.json b/test/fixtures/lightscript/if-expression/elif-indent-mismatch/options.json new file mode 100644 index 0000000000..dab65d8f73 --- /dev/null +++ b/test/fixtures/lightscript/if-expression/elif-indent-mismatch/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unmatched `else` (must match indentation of the line with `if`). (2:2)" +} diff --git a/test/fixtures/lightscript/if-expression/oneline-then-block/actual.js b/test/fixtures/lightscript/if-expression/oneline-then-block/actual.js index 0a656310ba..8268673022 100644 --- a/test/fixtures/lightscript/if-expression/oneline-then-block/actual.js +++ b/test/fixtures/lightscript/if-expression/oneline-then-block/actual.js @@ -1,3 +1,4 @@ -x = if false: 1 +x = + if false: 1 elif true: 2 diff --git a/test/fixtures/lightscript/if-expression/oneline-then-block/expected.json b/test/fixtures/lightscript/if-expression/oneline-then-block/expected.json index c009910ae1..664d800eec 100644 --- a/test/fixtures/lightscript/if-expression/oneline-then-block/expected.json +++ b/test/fixtures/lightscript/if-expression/oneline-then-block/expected.json @@ -1,28 +1,28 @@ { "type": "File", "start": 0, - "end": 34, + "end": 36, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 3, + "line": 4, "column": 5 } }, "program": { "type": "Program", "start": 0, - "end": 34, + "end": 36, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 3, + "line": 4, "column": 5 } }, @@ -31,30 +31,33 @@ { "type": "VariableDeclaration", "start": 0, - "end": 34, + "end": 36, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 3, + "line": 4, "column": 5 } }, "kind": "const", + "extra": { + "implicit": true + }, "declarations": [ { "type": "VariableDeclarator", "start": 0, - "end": 34, + "end": 36, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 3, + "line": 4, "column": 5 } }, @@ -77,46 +80,46 @@ }, "init": { "type": "IfExpression", - "start": 4, - "end": 34, + "start": 6, + "end": 36, "loc": { "start": { - "line": 1, - "column": 4 + "line": 2, + "column": 2 }, "end": { - "line": 3, + "line": 4, "column": 5 } }, "test": { "type": "BooleanLiteral", - "start": 7, - "end": 12, + "start": 9, + "end": 14, "loc": { "start": { - "line": 1, - "column": 7 + "line": 2, + "column": 5 }, "end": { - "line": 1, - "column": 12 + "line": 2, + "column": 10 } }, "value": false }, "consequent": { "type": "NumericLiteral", - "start": 14, - "end": 15, + "start": 16, + "end": 17, "loc": { "start": { - "line": 1, - "column": 14 + "line": 2, + "column": 12 }, "end": { - "line": 1, - "column": 15 + "line": 2, + "column": 13 } }, "extra": { @@ -127,29 +130,29 @@ }, "alternate": { "type": "IfExpression", - "start": 18, - "end": 34, + "start": 20, + "end": 36, "loc": { "start": { - "line": 2, + "line": 3, "column": 2 }, "end": { - "line": 3, + "line": 4, "column": 5 } }, "test": { "type": "BooleanLiteral", - "start": 23, - "end": 27, + "start": 25, + "end": 29, "loc": { "start": { - "line": 2, + "line": 3, "column": 7 }, "end": { - "line": 2, + "line": 3, "column": 11 } }, @@ -157,44 +160,44 @@ }, "consequent": { "type": "BlockStatement", - "start": 27, - "end": 34, + "start": 29, + "end": 36, "loc": { "start": { - "line": 2, + "line": 3, "column": 11 }, "end": { - "line": 3, + "line": 4, "column": 5 } }, "body": [ { "type": "ExpressionStatement", - "start": 33, - "end": 34, + "start": 35, + "end": 36, "loc": { "start": { - "line": 3, + "line": 4, "column": 4 }, "end": { - "line": 3, + "line": 4, "column": 5 } }, "expression": { "type": "NumericLiteral", - "start": 33, - "end": 34, + "start": 35, + "end": 36, "loc": { "start": { - "line": 3, + "line": 4, "column": 4 }, "end": { - "line": 3, + "line": 4, "column": 5 } }, diff --git a/test/fixtures/lightscript/whitespace/nested-if-mixed-syntax/actual.js b/test/fixtures/lightscript/whitespace/nested-if-mixed-syntax/actual.js new file mode 100644 index 0000000000..519561e39e --- /dev/null +++ b/test/fixtures/lightscript/whitespace/nested-if-mixed-syntax/actual.js @@ -0,0 +1,9 @@ +if (a) { +b +if c: + d +elif e: + f +} else { + g +} diff --git a/test/fixtures/lightscript/whitespace/nested-if-mixed-syntax/expected.json b/test/fixtures/lightscript/whitespace/nested-if-mixed-syntax/expected.json new file mode 100644 index 0000000000..630550274a --- /dev/null +++ b/test/fixtures/lightscript/whitespace/nested-if-mixed-syntax/expected.json @@ -0,0 +1,344 @@ +{ + "type": "File", + "start": 0, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 9, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 9, + "column": 1 + } + }, + "sourceType": "script", + "body": [ + { + "type": "IfStatement", + "start": 0, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 9, + "column": 1 + } + }, + "test": { + "type": "Identifier", + "start": 4, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "a" + }, + "name": "a", + "extra": {} + }, + "consequent": { + "type": "BlockStatement", + "start": 7, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 1 + } + }, + "expression": { + "type": "Identifier", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 1 + }, + "identifierName": "b" + }, + "name": "b" + } + }, + { + "type": "IfStatement", + "start": 11, + "end": 32, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "test": { + "type": "Identifier", + "start": 14, + "end": 15, + "loc": { + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 4 + }, + "identifierName": "c" + }, + "name": "c" + }, + "consequent": { + "type": "BlockStatement", + "start": 15, + "end": 20, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 4, + "column": 3 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 19, + "end": 20, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 3 + } + }, + "expression": { + "type": "Identifier", + "start": 19, + "end": 20, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 3 + }, + "identifierName": "d" + }, + "name": "d" + } + } + ], + "directives": [], + "extra": { + "curly": false + } + }, + "alternate": { + "type": "IfStatement", + "start": 21, + "end": 32, + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "test": { + "type": "Identifier", + "start": 26, + "end": 27, + "loc": { + "start": { + "line": 5, + "column": 5 + }, + "end": { + "line": 5, + "column": 6 + }, + "identifierName": "e" + }, + "name": "e" + }, + "consequent": { + "type": "BlockStatement", + "start": 27, + "end": 32, + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 31, + "end": 32, + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "expression": { + "type": "Identifier", + "start": 31, + "end": 32, + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 3 + }, + "identifierName": "f" + }, + "name": "f" + } + } + ], + "directives": [], + "extra": { + "curly": false + } + }, + "alternate": null + } + } + ], + "directives": [], + "extra": { + "curly": true + } + }, + "alternate": { + "type": "BlockStatement", + "start": 40, + "end": 47, + "loc": { + "start": { + "line": 7, + "column": 7 + }, + "end": { + "line": 9, + "column": 1 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 44, + "end": 45, + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 3 + } + }, + "expression": { + "type": "Identifier", + "start": 44, + "end": 45, + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 3 + }, + "identifierName": "g" + }, + "name": "g" + } + } + ], + "directives": [], + "extra": { + "curly": true + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/whitespace/nested-if-then-elif-expr/actual.js b/test/fixtures/lightscript/whitespace/nested-if-then-elif-expr/actual.js new file mode 100644 index 0000000000..b53e8cc5ef --- /dev/null +++ b/test/fixtures/lightscript/whitespace/nested-if-then-elif-expr/actual.js @@ -0,0 +1,5 @@ +x = if a: + if b: c + elif d: e +else: + f diff --git a/test/fixtures/lightscript/whitespace/nested-if-then-elif-expr/expected.json b/test/fixtures/lightscript/whitespace/nested-if-then-elif-expr/expected.json new file mode 100644 index 0000000000..c84d52480d --- /dev/null +++ b/test/fixtures/lightscript/whitespace/nested-if-then-elif-expr/expected.json @@ -0,0 +1,322 @@ +{ + "type": "File", + "start": 0, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 3 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 3 + } + }, + "sourceType": "script", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 3 + } + }, + "kind": "const", + "extra": { + "implicit": true + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 0, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 3 + } + }, + "id": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "init": { + "type": "IfExpression", + "start": 4, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 5, + "column": 3 + } + }, + "test": { + "type": "Identifier", + "start": 7, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + }, + "identifierName": "a" + }, + "name": "a" + }, + "consequent": { + "type": "BlockStatement", + "start": 8, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "body": [ + { + "type": "IfStatement", + "start": 12, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "test": { + "type": "Identifier", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 6 + }, + "identifierName": "b" + }, + "name": "b" + }, + "consequent": { + "type": "ExpressionStatement", + "start": 18, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "expression": { + "type": "Identifier", + "start": 18, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 9 + }, + "identifierName": "c" + }, + "name": "c" + } + }, + "alternate": { + "type": "IfStatement", + "start": 22, + "end": 31, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "test": { + "type": "Identifier", + "start": 27, + "end": 28, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 8 + }, + "identifierName": "d" + }, + "name": "d" + }, + "consequent": { + "type": "ExpressionStatement", + "start": 30, + "end": 31, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "expression": { + "type": "Identifier", + "start": 30, + "end": 31, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + }, + "identifierName": "e" + }, + "name": "e" + } + }, + "alternate": null + } + } + ], + "directives": [], + "extra": { + "curly": false + } + }, + "alternate": { + "type": "BlockStatement", + "start": 36, + "end": 41, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 5, + "column": 3 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 40, + "end": 41, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 3 + } + }, + "expression": { + "type": "Identifier", + "start": 40, + "end": 41, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 3 + }, + "identifierName": "f" + }, + "name": "f" + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + } + ] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/whitespace/nested-if-then-elif-mixed/actual.js b/test/fixtures/lightscript/whitespace/nested-if-then-elif-mixed/actual.js new file mode 100644 index 0000000000..48a441d463 --- /dev/null +++ b/test/fixtures/lightscript/whitespace/nested-if-then-elif-mixed/actual.js @@ -0,0 +1,6 @@ +x = if a: + if (b) { + c + } +else: + d diff --git a/test/fixtures/lightscript/whitespace/nested-if-then-elif-mixed/expected.json b/test/fixtures/lightscript/whitespace/nested-if-then-elif-mixed/expected.json new file mode 100644 index 0000000000..7f6110493b --- /dev/null +++ b/test/fixtures/lightscript/whitespace/nested-if-then-elif-mixed/expected.json @@ -0,0 +1,280 @@ +{ + "type": "File", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "sourceType": "script", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "kind": "const", + "extra": { + "implicit": true + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "id": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "init": { + "type": "IfExpression", + "start": 4, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "test": { + "type": "Identifier", + "start": 7, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + }, + "identifierName": "a" + }, + "name": "a" + }, + "consequent": { + "type": "BlockStatement", + "start": 8, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 3 + } + }, + "body": [ + { + "type": "IfStatement", + "start": 12, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 4, + "column": 3 + } + }, + "test": { + "type": "Identifier", + "start": 16, + "end": 17, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 7 + }, + "identifierName": "b" + }, + "name": "b", + "extra": {} + }, + "consequent": { + "type": "BlockStatement", + "start": 19, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 4, + "column": 3 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 25, + "end": 26, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 5 + } + }, + "expression": { + "type": "Identifier", + "start": 25, + "end": 26, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 5 + }, + "identifierName": "c" + }, + "name": "c" + } + } + ], + "directives": [], + "extra": { + "curly": true + } + }, + "alternate": null + } + ], + "directives": [], + "extra": { + "curly": false + } + }, + "alternate": { + "type": "BlockStatement", + "start": 35, + "end": 40, + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 39, + "end": 40, + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "expression": { + "type": "Identifier", + "start": 39, + "end": 40, + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 3 + }, + "identifierName": "d" + }, + "name": "d" + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + } + ] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/whitespace/nested-if-then-else-expr/actual.js b/test/fixtures/lightscript/whitespace/nested-if-then-else-expr/actual.js new file mode 100644 index 0000000000..4ad3765a68 --- /dev/null +++ b/test/fixtures/lightscript/whitespace/nested-if-then-else-expr/actual.js @@ -0,0 +1,4 @@ +x = if a: + if b: c +else: + d diff --git a/test/fixtures/lightscript/whitespace/nested-if-then-else-expr/expected.json b/test/fixtures/lightscript/whitespace/nested-if-then-else-expr/expected.json new file mode 100644 index 0000000000..45538a4060 --- /dev/null +++ b/test/fixtures/lightscript/whitespace/nested-if-then-else-expr/expected.json @@ -0,0 +1,258 @@ +{ + "type": "File", + "start": 0, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 3 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 3 + } + }, + "sourceType": "script", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 3 + } + }, + "kind": "const", + "extra": { + "implicit": true + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 0, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 3 + } + }, + "id": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "init": { + "type": "IfExpression", + "start": 4, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 4, + "column": 3 + } + }, + "test": { + "type": "Identifier", + "start": 7, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + }, + "identifierName": "a" + }, + "name": "a" + }, + "consequent": { + "type": "BlockStatement", + "start": 8, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "body": [ + { + "type": "IfStatement", + "start": 12, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "test": { + "type": "Identifier", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 6 + }, + "identifierName": "b" + }, + "name": "b" + }, + "consequent": { + "type": "ExpressionStatement", + "start": 18, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "expression": { + "type": "Identifier", + "start": 18, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 9 + }, + "identifierName": "c" + }, + "name": "c" + } + }, + "alternate": null + } + ], + "directives": [], + "extra": { + "curly": false + } + }, + "alternate": { + "type": "BlockStatement", + "start": 24, + "end": 29, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 4, + "column": 3 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 28, + "end": 29, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 3 + } + }, + "expression": { + "type": "Identifier", + "start": 28, + "end": 29, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 3 + }, + "identifierName": "d" + }, + "name": "d" + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + } + ] + } + ], + "directives": [] + } +} \ No newline at end of file