diff --git a/src/parser/statement.js b/src/parser/statement.js index 32a682f389..bd795c95a8 100644 --- a/src/parser/statement.js +++ b/src/parser/statement.js @@ -439,10 +439,23 @@ const empty = []; pp.parseTryStatement = function (node) { this.next(); + let indentLevel, isColon; + if (this.hasPlugin("lightscript")) { + indentLevel = this.state.indentLevel; + isColon = this.match(tt.colon); + if (isColon) this.pushBlockState("try", indentLevel); + } + node.block = this.parseBlock(); node.handler = null; - if (this.match(tt._catch)) { + const shouldParseCatch = this.match(tt._catch) && ( + !this.hasPlugin("lightscript") || + indentLevel === this.state.indentLevel || + (!isColon && !this.matchBlockState("try", this.state.indentLevel)) + ); + + if (shouldParseCatch) { const clause = this.startNode(); this.next(); @@ -457,6 +470,11 @@ pp.parseTryStatement = function (node) { this.checkLVal(clause.param, true, Object.create(null), "catch clause"); if (this.hasPlugin("lightscript")) { this.expectParenFreeBlockStart(clause); + if (isColon) { + this.check(tt.colon); + } else { + this.check(tt.braceL); + } } else { this.expect(tt.parenR); } @@ -465,12 +483,34 @@ pp.parseTryStatement = function (node) { } node.guardedHandlers = empty; - node.finalizer = this.eat(tt._finally) ? this.parseBlock() : null; + + + if (this.hasPlugin("lightscript")) { + const shouldParseFinally = this.match(tt._finally) && ( + indentLevel === this.state.indentLevel || + (!isColon && !this.matchBlockState("try", this.state.indentLevel)) + ); + if (shouldParseFinally) { + this.next(); + if (isColon) { + this.check(tt.colon); + } else { + this.check(tt.braceL); + } + node.finalizer = this.parseBlock(); + } else { + node.finalizer = null; + } + } else { + node.finalizer = this.eat(tt._finally) ? this.parseBlock() : null; + } if (!node.handler && !node.finalizer) { this.raise(node.start, "Missing catch or finally clause"); } + if (this.hasPlugin("lightscript") && isColon) this.popBlockState(); + return this.finishNode(node, "TryStatement"); }; diff --git a/src/plugins/lightscript.js b/src/plugins/lightscript.js index fd8d18656c..a43850674d 100644 --- a/src/plugins/lightscript.js +++ b/src/plugins/lightscript.js @@ -155,8 +155,7 @@ pp.parseMultilineWhiteBlock = function(node, indentLevel) { pp.parseWhiteBlock = function (isExpression?) { const node = this.startNode(), indentLevel = this.state.indentLevel; - - if (!this.eat(tt.colon)) this.unexpected(null, "Whitespace Block must start with a colon or arrow"); + if (!this.eat(tt.colon)) this.unexpected(this.state.lastTokEnd, tt.colon); // Oneline whiteblock if (!this.isLineBreak()) { @@ -383,12 +382,18 @@ pp.popBlockState = function() { // c/p parseIfStatement -pp.parseIf = function (node, isExpression) { +pp.parseIf = function (node, isExpression, requireColon = null) { const indentLevel = this.state.indentLevel; this.next(); node.test = this.parseParenExpression(); - const isColon = this.match(tt.colon); + const isColon = requireColon + ? this.check(tt.colon) + : this.match(tt.colon); + + // colon not allowed, parent `if` didn't use one. + if (isColon && requireColon === false) this.expect(tt.braceL); + if (isColon) this.pushBlockState("if", indentLevel); if (isExpression) { @@ -425,7 +430,7 @@ pp.parseIfAlternate = function (node, isExpression, ifIsWhiteBlock, ifIndentLeve } if (this.match(tt._elif)) { - return this.parseIf(this.startNode(), isExpression); + return this.parseIf(this.startNode(), isExpression, ifIsWhiteBlock); } if (this.eat(tt._else)) { @@ -433,20 +438,20 @@ pp.parseIfAlternate = function (node, isExpression, ifIsWhiteBlock, ifIndentLeve if (this.isLineBreak()) { this.unexpected(this.state.lastTokEnd, "Illegal newline."); } - return this.parseIf(this.startNode(), isExpression); + return this.parseIf(this.startNode(), isExpression, ifIsWhiteBlock); } - if (this.isLineBreak()) { - this.unexpected(this.state.lastTokEnd, tt.colon); + if (ifIsWhiteBlock) { + return this.parseWhiteBlock(isExpression); + } else if (this.match(tt.colon)) { + this.expect(tt.braceL); } if (isExpression) { if (this.match(tt.braceL)) { return this.parseBlock(false); - } else if (!this.match(tt.colon)) { - return this.parseMaybeAssign(); } else { - return this.parseWhiteBlock(true); + return this.parseMaybeAssign(); } } diff --git a/src/tokenizer/index.js b/src/tokenizer/index.js index adcb63e204..6c5d4765ec 100644 --- a/src/tokenizer/index.js +++ b/src/tokenizer/index.js @@ -202,7 +202,7 @@ export default class Tokenizer { // whitespace and comments, and. skipSpace() { - let isNewLine = false; // for lightscript + let isNewLine = this.state.pos === 0; // for lightscript loop: while (this.state.pos < this.input.length) { const ch = this.input.charCodeAt(this.state.pos); switch (ch) { diff --git a/test/fixtures/lightscript/if-expression/colon-oneline/expected.json b/test/fixtures/lightscript/if-expression/braces-no-colon/expected.json similarity index 86% rename from test/fixtures/lightscript/if-expression/colon-oneline/expected.json rename to test/fixtures/lightscript/if-expression/braces-no-colon/expected.json index 7165b02f7f..2426c0dfe3 100644 --- a/test/fixtures/lightscript/if-expression/colon-oneline/expected.json +++ b/test/fixtures/lightscript/if-expression/braces-no-colon/expected.json @@ -1,29 +1,29 @@ { "type": "File", "start": 0, - "end": 28, + "end": 33, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 3, - "column": 8 + "line": 4, + "column": 5 } }, "program": { "type": "Program", "start": 0, - "end": 28, + "end": 33, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 3, - "column": 8 + "line": 4, + "column": 5 } }, "sourceType": "script", @@ -31,15 +31,15 @@ { "type": "VariableDeclaration", "start": 0, - "end": 28, + "end": 33, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 3, - "column": 8 + "line": 4, + "column": 5 } }, "kind": "const", @@ -50,15 +50,15 @@ { "type": "VariableDeclarator", "start": 0, - "end": 28, + "end": 33, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 3, - "column": 8 + "line": 4, + "column": 5 } }, "id": { @@ -81,15 +81,15 @@ "init": { "type": "IfExpression", "start": 4, - "end": 28, + "end": 33, "loc": { "start": { "line": 1, "column": 4 }, "end": { - "line": 3, - "column": 8 + "line": 4, + "column": 5 } }, "test": { @@ -147,23 +147,23 @@ }, "consequent": { "type": "BlockStatement", - "start": 12, - "end": 19, + "start": 13, + "end": 22, "loc": { "start": { "line": 1, - "column": 12 + "column": 13 }, "end": { - "line": 2, - "column": 5 + "line": 3, + "column": 1 } }, "body": [ { "type": "ExpressionStatement", - "start": 16, - "end": 19, + "start": 17, + "end": 20, "loc": { "start": { "line": 2, @@ -176,8 +176,8 @@ }, "expression": { "type": "StringLiteral", - "start": 16, - "end": 19, + "start": 17, + "end": 20, "loc": { "start": { "line": 2, @@ -198,21 +198,21 @@ ], "directives": [], "extra": { - "curly": false + "curly": true } }, "alternate": { "type": "StringLiteral", - "start": 25, - "end": 28, + "start": 30, + "end": 33, "loc": { "start": { - "line": 3, - "column": 5 + "line": 4, + "column": 2 }, "end": { - "line": 3, - "column": 8 + "line": 4, + "column": 5 } }, "extra": { diff --git a/test/fixtures/lightscript/if-expression/braces-no-colon/options.json b/test/fixtures/lightscript/if-expression/braces-no-colon/options.json deleted file mode 100644 index ee2ec78cf1..0000000000 --- a/test/fixtures/lightscript/if-expression/braces-no-colon/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token, expected : (3:6)" -} diff --git a/test/fixtures/lightscript/if-expression/colon-braces/expected.json b/test/fixtures/lightscript/if-expression/colon-braces/expected.json deleted file mode 100644 index bfc596cc84..0000000000 --- a/test/fixtures/lightscript/if-expression/colon-braces/expected.json +++ /dev/null @@ -1,267 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 34, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 5, - "column": 1 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 34, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 5, - "column": 1 - } - }, - "sourceType": "script", - "body": [ - { - "type": "VariableDeclaration", - "start": 0, - "end": 34, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 5, - "column": 1 - } - }, - "kind": "const", - "extra": { - "implicit": true - }, - "declarations": [ - { - "type": "VariableDeclarator", - "start": 0, - "end": 34, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 5, - "column": 1 - } - }, - "id": { - "type": "Identifier", - "start": 0, - "end": 1, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 1 - }, - "identifierName": "y" - }, - "name": "y" - }, - "init": { - "type": "IfExpression", - "start": 4, - "end": 34, - "loc": { - "start": { - "line": 1, - "column": 4 - }, - "end": { - "line": 5, - "column": 1 - } - }, - "test": { - "type": "BinaryExpression", - "start": 7, - "end": 12, - "loc": { - "start": { - "line": 1, - "column": 7 - }, - "end": { - "line": 1, - "column": 12 - } - }, - "left": { - "type": "Identifier", - "start": 7, - "end": 8, - "loc": { - "start": { - "line": 1, - "column": 7 - }, - "end": { - "line": 1, - "column": 8 - }, - "identifierName": "x" - }, - "name": "x" - }, - "operator": ">", - "right": { - "type": "NumericLiteral", - "start": 11, - "end": 12, - "loc": { - "start": { - "line": 1, - "column": 11 - }, - "end": { - "line": 1, - "column": 12 - } - }, - "extra": { - "rawValue": 1, - "raw": "1" - }, - "value": 1 - } - }, - "consequent": { - "type": "BlockStatement", - "start": 12, - "end": 19, - "loc": { - "start": { - "line": 1, - "column": 12 - }, - "end": { - "line": 2, - "column": 5 - } - }, - "body": [ - { - "type": "ExpressionStatement", - "start": 16, - "end": 19, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 5 - } - }, - "expression": { - "type": "StringLiteral", - "start": 16, - "end": 19, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 5 - } - }, - "extra": { - "rawValue": "a", - "raw": "'a'" - }, - "value": "a" - } - } - ], - "directives": [], - "extra": { - "curly": false - } - }, - "alternate": { - "type": "BlockStatement", - "start": 25, - "end": 34, - "loc": { - "start": { - "line": 3, - "column": 5 - }, - "end": { - "line": 5, - "column": 1 - } - }, - "body": [ - { - "type": "ExpressionStatement", - "start": 29, - "end": 32, - "loc": { - "start": { - "line": 4, - "column": 2 - }, - "end": { - "line": 4, - "column": 5 - } - }, - "expression": { - "type": "StringLiteral", - "start": 29, - "end": 32, - "loc": { - "start": { - "line": 4, - "column": 2 - }, - "end": { - "line": 4, - "column": 5 - } - }, - "extra": { - "rawValue": "b", - "raw": "'b'" - }, - "value": "b" - } - } - ], - "directives": [], - "extra": { - "curly": true - } - } - } - } - ] - } - ], - "directives": [] - } -} \ No newline at end of file diff --git a/test/fixtures/lightscript/if-expression/colon-braces/options.json b/test/fixtures/lightscript/if-expression/colon-braces/options.json new file mode 100644 index 0000000000..4252ad09b1 --- /dev/null +++ b/test/fixtures/lightscript/if-expression/colon-braces/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected : (3:4)" +} diff --git a/test/fixtures/lightscript/if-expression/colon-oneline/options.json b/test/fixtures/lightscript/if-expression/colon-oneline/options.json new file mode 100644 index 0000000000..4252ad09b1 --- /dev/null +++ b/test/fixtures/lightscript/if-expression/colon-oneline/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected : (3:4)" +} diff --git a/test/fixtures/lightscript/if-expression/elseif-mismatch/expected.json b/test/fixtures/lightscript/if-expression/elseif-mismatch/expected.json deleted file mode 100644 index aa4addc2e4..0000000000 --- a/test/fixtures/lightscript/if-expression/elseif-mismatch/expected.json +++ /dev/null @@ -1,356 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 44, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 5, - "column": 1 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 44, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 5, - "column": 1 - } - }, - "sourceType": "script", - "body": [ - { - "type": "VariableDeclaration", - "start": 0, - "end": 44, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 5, - "column": 1 - } - }, - "kind": "const", - "extra": { - "implicit": true - }, - "declarations": [ - { - "type": "VariableDeclarator", - "start": 0, - "end": 44, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 5, - "column": 1 - } - }, - "id": { - "type": "Identifier", - "start": 0, - "end": 1, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 1 - }, - "identifierName": "y" - }, - "name": "y" - }, - "init": { - "type": "IfExpression", - "start": 4, - "end": 44, - "loc": { - "start": { - "line": 1, - "column": 4 - }, - "end": { - "line": 5, - "column": 1 - } - }, - "test": { - "type": "BinaryExpression", - "start": 7, - "end": 12, - "loc": { - "start": { - "line": 1, - "column": 7 - }, - "end": { - "line": 1, - "column": 12 - } - }, - "left": { - "type": "Identifier", - "start": 7, - "end": 8, - "loc": { - "start": { - "line": 1, - "column": 7 - }, - "end": { - "line": 1, - "column": 8 - }, - "identifierName": "x" - }, - "name": "x" - }, - "operator": ">", - "right": { - "type": "NumericLiteral", - "start": 11, - "end": 12, - "loc": { - "start": { - "line": 1, - "column": 11 - }, - "end": { - "line": 1, - "column": 12 - } - }, - "extra": { - "rawValue": 1, - "raw": "1" - }, - "value": 1 - } - }, - "consequent": { - "type": "BlockStatement", - "start": 12, - "end": 19, - "loc": { - "start": { - "line": 1, - "column": 12 - }, - "end": { - "line": 2, - "column": 5 - } - }, - "body": [ - { - "type": "ExpressionStatement", - "start": 16, - "end": 19, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 5 - } - }, - "expression": { - "type": "StringLiteral", - "start": 16, - "end": 19, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 5 - } - }, - "extra": { - "rawValue": "a", - "raw": "'a'" - }, - "value": "a" - } - } - ], - "directives": [], - "extra": { - "curly": false - } - }, - "alternate": { - "type": "IfExpression", - "start": 25, - "end": 44, - "loc": { - "start": { - "line": 3, - "column": 5 - }, - "end": { - "line": 5, - "column": 1 - } - }, - "test": { - "type": "BinaryExpression", - "start": 28, - "end": 34, - "loc": { - "start": { - "line": 3, - "column": 8 - }, - "end": { - "line": 3, - "column": 14 - } - }, - "left": { - "type": "Identifier", - "start": 28, - "end": 29, - "loc": { - "start": { - "line": 3, - "column": 8 - }, - "end": { - "line": 3, - "column": 9 - }, - "identifierName": "x" - }, - "name": "x" - }, - "operator": "<", - "right": { - "type": "UnaryExpression", - "start": 32, - "end": 34, - "loc": { - "start": { - "line": 3, - "column": 12 - }, - "end": { - "line": 3, - "column": 14 - } - }, - "operator": "-", - "prefix": true, - "argument": { - "type": "NumericLiteral", - "start": 33, - "end": 34, - "loc": { - "start": { - "line": 3, - "column": 13 - }, - "end": { - "line": 3, - "column": 14 - } - }, - "extra": { - "rawValue": 1, - "raw": "1" - }, - "value": 1 - }, - "extra": { - "parenthesizedArgument": false - } - } - }, - "consequent": { - "type": "BlockStatement", - "start": 35, - "end": 44, - "loc": { - "start": { - "line": 3, - "column": 15 - }, - "end": { - "line": 5, - "column": 1 - } - }, - "body": [ - { - "type": "ExpressionStatement", - "start": 39, - "end": 42, - "loc": { - "start": { - "line": 4, - "column": 2 - }, - "end": { - "line": 4, - "column": 5 - } - }, - "expression": { - "type": "StringLiteral", - "start": 39, - "end": 42, - "loc": { - "start": { - "line": 4, - "column": 2 - }, - "end": { - "line": 4, - "column": 5 - } - }, - "extra": { - "rawValue": "b", - "raw": "'b'" - }, - "value": "b" - } - } - ], - "directives": [], - "extra": { - "curly": true - } - }, - "alternate": null - } - } - } - ] - } - ], - "directives": [] - } -} \ No newline at end of file diff --git a/test/fixtures/lightscript/if-expression/elseif-mismatch/options.json b/test/fixtures/lightscript/if-expression/elseif-mismatch/options.json new file mode 100644 index 0000000000..d4c511a6db --- /dev/null +++ b/test/fixtures/lightscript/if-expression/elseif-mismatch/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected : (3:15)" +} diff --git a/test/fixtures/lightscript/if-statement/braces-colon/actual.js b/test/fixtures/lightscript/if-statement/braces-colon/actual.js new file mode 100644 index 0000000000..f2d84f0ba5 --- /dev/null +++ b/test/fixtures/lightscript/if-statement/braces-colon/actual.js @@ -0,0 +1,4 @@ +if x > 1 { + 'a' +} else: + 'b' diff --git a/test/fixtures/lightscript/if-statement/braces-colon/options.json b/test/fixtures/lightscript/if-statement/braces-colon/options.json new file mode 100644 index 0000000000..3aea067619 --- /dev/null +++ b/test/fixtures/lightscript/if-statement/braces-colon/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected { (3:6)" +} diff --git a/test/fixtures/lightscript/if-statement/braces-elif-colon-2/actual.js b/test/fixtures/lightscript/if-statement/braces-elif-colon-2/actual.js new file mode 100644 index 0000000000..907bbd9d53 --- /dev/null +++ b/test/fixtures/lightscript/if-statement/braces-elif-colon-2/actual.js @@ -0,0 +1,6 @@ +if x > 1 { + 'a' +} elif 1 { + 'b' +} else if 1: + 'c' diff --git a/test/fixtures/lightscript/if-statement/braces-elif-colon-2/options.json b/test/fixtures/lightscript/if-statement/braces-elif-colon-2/options.json new file mode 100644 index 0000000000..afa194f93a --- /dev/null +++ b/test/fixtures/lightscript/if-statement/braces-elif-colon-2/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected { (5:11)" +} diff --git a/test/fixtures/lightscript/if-statement/braces-elif-colon/actual.js b/test/fixtures/lightscript/if-statement/braces-elif-colon/actual.js new file mode 100644 index 0000000000..43402c99d2 --- /dev/null +++ b/test/fixtures/lightscript/if-statement/braces-elif-colon/actual.js @@ -0,0 +1,4 @@ +if x > 1 { + 'a' +} elif 1: + 'b' diff --git a/test/fixtures/lightscript/if-statement/braces-elif-colon/options.json b/test/fixtures/lightscript/if-statement/braces-elif-colon/options.json new file mode 100644 index 0000000000..8f07dfc5f2 --- /dev/null +++ b/test/fixtures/lightscript/if-statement/braces-elif-colon/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected { (3:8)" +} diff --git a/test/fixtures/lightscript/if-statement/colon-oneline/expected.json b/test/fixtures/lightscript/if-statement/braces-no-colon/expected.json similarity index 84% rename from test/fixtures/lightscript/if-statement/colon-oneline/expected.json rename to test/fixtures/lightscript/if-statement/braces-no-colon/expected.json index c3b5072618..fe49aac225 100644 --- a/test/fixtures/lightscript/if-statement/colon-oneline/expected.json +++ b/test/fixtures/lightscript/if-statement/braces-no-colon/expected.json @@ -1,29 +1,29 @@ { "type": "File", "start": 0, - "end": 24, + "end": 29, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 3, - "column": 8 + "line": 4, + "column": 5 } }, "program": { "type": "Program", "start": 0, - "end": 24, + "end": 29, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 3, - "column": 8 + "line": 4, + "column": 5 } }, "sourceType": "script", @@ -31,15 +31,15 @@ { "type": "IfStatement", "start": 0, - "end": 24, + "end": 29, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 3, - "column": 8 + "line": 4, + "column": 5 } }, "test": { @@ -97,23 +97,23 @@ }, "consequent": { "type": "BlockStatement", - "start": 8, - "end": 15, + "start": 9, + "end": 18, "loc": { "start": { "line": 1, - "column": 8 + "column": 9 }, "end": { - "line": 2, - "column": 5 + "line": 3, + "column": 1 } }, "body": [ { "type": "ExpressionStatement", - "start": 12, - "end": 15, + "start": 13, + "end": 16, "loc": { "start": { "line": 2, @@ -126,8 +126,8 @@ }, "expression": { "type": "StringLiteral", - "start": 12, - "end": 15, + "start": 13, + "end": 16, "loc": { "start": { "line": 2, @@ -148,35 +148,35 @@ ], "directives": [], "extra": { - "curly": false + "curly": true } }, "alternate": { "type": "ExpressionStatement", - "start": 21, - "end": 24, + "start": 26, + "end": 29, "loc": { "start": { - "line": 3, - "column": 5 + "line": 4, + "column": 2 }, "end": { - "line": 3, - "column": 8 + "line": 4, + "column": 5 } }, "expression": { "type": "StringLiteral", - "start": 21, - "end": 24, + "start": 26, + "end": 29, "loc": { "start": { - "line": 3, - "column": 5 + "line": 4, + "column": 2 }, "end": { - "line": 3, - "column": 8 + "line": 4, + "column": 5 } }, "extra": { diff --git a/test/fixtures/lightscript/if-statement/braces-no-colon/options.json b/test/fixtures/lightscript/if-statement/braces-no-colon/options.json deleted file mode 100644 index ee2ec78cf1..0000000000 --- a/test/fixtures/lightscript/if-statement/braces-no-colon/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token, expected : (3:6)" -} diff --git a/test/fixtures/lightscript/if-statement/colon-braces/options.json b/test/fixtures/lightscript/if-statement/colon-braces/options.json new file mode 100644 index 0000000000..4252ad09b1 --- /dev/null +++ b/test/fixtures/lightscript/if-statement/colon-braces/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected : (3:4)" +} diff --git a/test/fixtures/lightscript/if-statement/colon-oneline/options.json b/test/fixtures/lightscript/if-statement/colon-oneline/options.json new file mode 100644 index 0000000000..4252ad09b1 --- /dev/null +++ b/test/fixtures/lightscript/if-statement/colon-oneline/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected : (3:4)" +} diff --git a/test/fixtures/lightscript/if-statement/elseif-mismatch/expected.json b/test/fixtures/lightscript/if-statement/elseif-mismatch/expected.json deleted file mode 100644 index 7f0b5e379e..0000000000 --- a/test/fixtures/lightscript/if-statement/elseif-mismatch/expected.json +++ /dev/null @@ -1,303 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 40, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 5, - "column": 1 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 40, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 5, - "column": 1 - } - }, - "sourceType": "script", - "body": [ - { - "type": "IfStatement", - "start": 0, - "end": 40, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 5, - "column": 1 - } - }, - "test": { - "type": "BinaryExpression", - "start": 3, - "end": 8, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 8 - } - }, - "left": { - "type": "Identifier", - "start": 3, - "end": 4, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 4 - }, - "identifierName": "x" - }, - "name": "x" - }, - "operator": ">", - "right": { - "type": "NumericLiteral", - "start": 7, - "end": 8, - "loc": { - "start": { - "line": 1, - "column": 7 - }, - "end": { - "line": 1, - "column": 8 - } - }, - "extra": { - "rawValue": 1, - "raw": "1" - }, - "value": 1 - } - }, - "consequent": { - "type": "BlockStatement", - "start": 8, - "end": 15, - "loc": { - "start": { - "line": 1, - "column": 8 - }, - "end": { - "line": 2, - "column": 5 - } - }, - "body": [ - { - "type": "ExpressionStatement", - "start": 12, - "end": 15, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 5 - } - }, - "expression": { - "type": "StringLiteral", - "start": 12, - "end": 15, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 5 - } - }, - "extra": { - "rawValue": "a", - "raw": "'a'" - }, - "value": "a" - } - } - ], - "directives": [], - "extra": { - "curly": false - } - }, - "alternate": { - "type": "IfStatement", - "start": 21, - "end": 40, - "loc": { - "start": { - "line": 3, - "column": 5 - }, - "end": { - "line": 5, - "column": 1 - } - }, - "test": { - "type": "BinaryExpression", - "start": 24, - "end": 30, - "loc": { - "start": { - "line": 3, - "column": 8 - }, - "end": { - "line": 3, - "column": 14 - } - }, - "left": { - "type": "Identifier", - "start": 24, - "end": 25, - "loc": { - "start": { - "line": 3, - "column": 8 - }, - "end": { - "line": 3, - "column": 9 - }, - "identifierName": "x" - }, - "name": "x" - }, - "operator": "<", - "right": { - "type": "UnaryExpression", - "start": 28, - "end": 30, - "loc": { - "start": { - "line": 3, - "column": 12 - }, - "end": { - "line": 3, - "column": 14 - } - }, - "operator": "-", - "prefix": true, - "argument": { - "type": "NumericLiteral", - "start": 29, - "end": 30, - "loc": { - "start": { - "line": 3, - "column": 13 - }, - "end": { - "line": 3, - "column": 14 - } - }, - "extra": { - "rawValue": 1, - "raw": "1" - }, - "value": 1 - }, - "extra": { - "parenthesizedArgument": false - } - } - }, - "consequent": { - "type": "BlockStatement", - "start": 31, - "end": 40, - "loc": { - "start": { - "line": 3, - "column": 15 - }, - "end": { - "line": 5, - "column": 1 - } - }, - "body": [ - { - "type": "ExpressionStatement", - "start": 35, - "end": 38, - "loc": { - "start": { - "line": 4, - "column": 2 - }, - "end": { - "line": 4, - "column": 5 - } - }, - "expression": { - "type": "StringLiteral", - "start": 35, - "end": 38, - "loc": { - "start": { - "line": 4, - "column": 2 - }, - "end": { - "line": 4, - "column": 5 - } - }, - "extra": { - "rawValue": "b", - "raw": "'b'" - }, - "value": "b" - } - } - ], - "directives": [], - "extra": { - "curly": true - } - }, - "alternate": null - } - } - ], - "directives": [] - } -} \ No newline at end of file diff --git a/test/fixtures/lightscript/if-statement/elseif-mismatch/options.json b/test/fixtures/lightscript/if-statement/elseif-mismatch/options.json new file mode 100644 index 0000000000..d4c511a6db --- /dev/null +++ b/test/fixtures/lightscript/if-statement/elseif-mismatch/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected : (3:15)" +} diff --git a/test/fixtures/lightscript/if-statement/threeline-return/expected.json b/test/fixtures/lightscript/if-statement/threeline-return/expected.json deleted file mode 100644 index b108f20647..0000000000 --- a/test/fixtures/lightscript/if-statement/threeline-return/expected.json +++ /dev/null @@ -1,214 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 46, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 4, - "column": 15 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 46, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 4, - "column": 15 - } - }, - "sourceType": "script", - "body": [ - { - "type": "NamedArrowDeclaration", - "start": 0, - "end": 46, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 4, - "column": 15 - } - }, - "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": 46, - "loc": { - "start": { - "line": 1, - "column": 4 - }, - "end": { - "line": 4, - "column": 15 - } - }, - "body": [ - { - "type": "IfStatement", - "start": 9, - "end": 46, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 4, - "column": 15 - } - }, - "test": { - "type": "BooleanLiteral", - "start": 12, - "end": 16, - "loc": { - "start": { - "line": 2, - "column": 5 - }, - "end": { - "line": 2, - "column": 9 - } - }, - "value": true - }, - "consequent": { - "type": "BlockStatement", - "start": 16, - "end": 30, - "loc": { - "start": { - "line": 2, - "column": 9 - }, - "end": { - "line": 3, - "column": 12 - } - }, - "body": [ - { - "type": "ReturnStatement", - "start": 22, - "end": 30, - "loc": { - "start": { - "line": 3, - "column": 4 - }, - "end": { - "line": 3, - "column": 12 - } - }, - "argument": { - "type": "NumericLiteral", - "start": 29, - "end": 30, - "loc": { - "start": { - "line": 3, - "column": 11 - }, - "end": { - "line": 3, - "column": 12 - } - }, - "extra": { - "rawValue": 1, - "raw": "1" - }, - "value": 1 - } - } - ], - "directives": [], - "extra": { - "curly": false - } - }, - "alternate": { - "type": "ReturnStatement", - "start": 38, - "end": 46, - "loc": { - "start": { - "line": 4, - "column": 7 - }, - "end": { - "line": 4, - "column": 15 - } - }, - "argument": { - "type": "NumericLiteral", - "start": 45, - "end": 46, - "loc": { - "start": { - "line": 4, - "column": 14 - }, - "end": { - "line": 4, - "column": 15 - } - }, - "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/threeline-return/options.json b/test/fixtures/lightscript/if-statement/threeline-return/options.json new file mode 100644 index 0000000000..5d4961fa0e --- /dev/null +++ b/test/fixtures/lightscript/if-statement/threeline-return/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected : (4:6)" +} diff --git a/test/fixtures/lightscript/whitespace/overindent-first-line/actual.js b/test/fixtures/lightscript/whitespace/overindent-first-line/actual.js new file mode 100644 index 0000000000..3aa41b9d91 --- /dev/null +++ b/test/fixtures/lightscript/whitespace/overindent-first-line/actual.js @@ -0,0 +1,4 @@ + if true: + 1 + else: + 2 diff --git a/test/fixtures/lightscript/if-statement/colon-braces/expected.json b/test/fixtures/lightscript/whitespace/overindent-first-line/expected.json similarity index 57% rename from test/fixtures/lightscript/if-statement/colon-braces/expected.json rename to test/fixtures/lightscript/whitespace/overindent-first-line/expected.json index 6055142b38..0d6caabbdf 100644 --- a/test/fixtures/lightscript/if-statement/colon-braces/expected.json +++ b/test/fixtures/lightscript/whitespace/overindent-first-line/expected.json @@ -8,8 +8,8 @@ "column": 0 }, "end": { - "line": 5, - "column": 1 + "line": 4, + "column": 5 } }, "program": { @@ -22,87 +22,50 @@ "column": 0 }, "end": { - "line": 5, - "column": 1 + "line": 4, + "column": 5 } }, "sourceType": "script", "body": [ { "type": "IfStatement", - "start": 0, + "start": 2, "end": 30, "loc": { "start": { "line": 1, - "column": 0 + "column": 2 }, "end": { - "line": 5, - "column": 1 + "line": 4, + "column": 5 } }, "test": { - "type": "BinaryExpression", - "start": 3, - "end": 8, + "type": "BooleanLiteral", + "start": 5, + "end": 9, "loc": { "start": { "line": 1, - "column": 3 + "column": 5 }, "end": { "line": 1, - "column": 8 + "column": 9 } }, - "left": { - "type": "Identifier", - "start": 3, - "end": 4, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 4 - }, - "identifierName": "x" - }, - "name": "x" - }, - "operator": ">", - "right": { - "type": "NumericLiteral", - "start": 7, - "end": 8, - "loc": { - "start": { - "line": 1, - "column": 7 - }, - "end": { - "line": 1, - "column": 8 - } - }, - "extra": { - "rawValue": 1, - "raw": "1" - }, - "value": 1 - } + "value": true }, "consequent": { "type": "BlockStatement", - "start": 8, - "end": 15, + "start": 9, + "end": 16, "loc": { "start": { "line": 1, - "column": 8 + "column": 9 }, "end": { "line": 2, @@ -112,12 +75,12 @@ "body": [ { "type": "ExpressionStatement", - "start": 12, - "end": 15, + "start": 15, + "end": 16, "loc": { "start": { "line": 2, - "column": 2 + "column": 4 }, "end": { "line": 2, @@ -125,13 +88,13 @@ } }, "expression": { - "type": "StringLiteral", - "start": 12, - "end": 15, + "type": "NumericLiteral", + "start": 15, + "end": 16, "loc": { "start": { "line": 2, - "column": 2 + "column": 4 }, "end": { "line": 2, @@ -139,10 +102,10 @@ } }, "extra": { - "rawValue": "a", - "raw": "'a'" + "rawValue": 1, + "raw": "1" }, - "value": "a" + "value": 1 } } ], @@ -153,27 +116,27 @@ }, "alternate": { "type": "BlockStatement", - "start": 21, + "start": 23, "end": 30, "loc": { "start": { "line": 3, - "column": 5 + "column": 6 }, "end": { - "line": 5, - "column": 1 + "line": 4, + "column": 5 } }, "body": [ { "type": "ExpressionStatement", - "start": 25, - "end": 28, + "start": 29, + "end": 30, "loc": { "start": { "line": 4, - "column": 2 + "column": 4 }, "end": { "line": 4, @@ -181,13 +144,13 @@ } }, "expression": { - "type": "StringLiteral", - "start": 25, - "end": 28, + "type": "NumericLiteral", + "start": 29, + "end": 30, "loc": { "start": { "line": 4, - "column": 2 + "column": 4 }, "end": { "line": 4, @@ -195,16 +158,16 @@ } }, "extra": { - "rawValue": "b", - "raw": "'b'" + "rawValue": 2, + "raw": "2" }, - "value": "b" + "value": 2 } } ], "directives": [], "extra": { - "curly": true + "curly": false } } } diff --git a/test/fixtures/lightscript/whitespace/try-catch-brace-then-colon/actual.js b/test/fixtures/lightscript/whitespace/try-catch-brace-then-colon/actual.js new file mode 100644 index 0000000000..1fc0c583a0 --- /dev/null +++ b/test/fixtures/lightscript/whitespace/try-catch-brace-then-colon/actual.js @@ -0,0 +1,4 @@ +try { + 1 +} catch err: + 2 diff --git a/test/fixtures/lightscript/whitespace/try-catch-brace-then-colon/options.json b/test/fixtures/lightscript/whitespace/try-catch-brace-then-colon/options.json new file mode 100644 index 0000000000..2421391133 --- /dev/null +++ b/test/fixtures/lightscript/whitespace/try-catch-brace-then-colon/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected { (3:11)" +} diff --git a/test/fixtures/lightscript/whitespace/try-catch-colon-then-brace/actual.js b/test/fixtures/lightscript/whitespace/try-catch-colon-then-brace/actual.js new file mode 100644 index 0000000000..29655d868a --- /dev/null +++ b/test/fixtures/lightscript/whitespace/try-catch-colon-then-brace/actual.js @@ -0,0 +1,5 @@ +try: + 1 +catch (err) { + 2 +} diff --git a/test/fixtures/lightscript/whitespace/try-catch-colon-then-brace/options.json b/test/fixtures/lightscript/whitespace/try-catch-colon-then-brace/options.json new file mode 100644 index 0000000000..9c2308cfb2 --- /dev/null +++ b/test/fixtures/lightscript/whitespace/try-catch-colon-then-brace/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected : (3:12)" +} diff --git a/test/fixtures/lightscript/whitespace/try-catch-curly-diff-indents/actual.js b/test/fixtures/lightscript/whitespace/try-catch-curly-diff-indents/actual.js new file mode 100644 index 0000000000..8e20a9afcf --- /dev/null +++ b/test/fixtures/lightscript/whitespace/try-catch-curly-diff-indents/actual.js @@ -0,0 +1,9 @@ + try { + 1 + } +catch err { + 2 +} + finally { + 3 + } diff --git a/test/fixtures/lightscript/whitespace/try-catch-curly-diff-indents/expected.json b/test/fixtures/lightscript/whitespace/try-catch-curly-diff-indents/expected.json new file mode 100644 index 0000000000..7012efb1f7 --- /dev/null +++ b/test/fixtures/lightscript/whitespace/try-catch-curly-diff-indents/expected.json @@ -0,0 +1,250 @@ +{ + "type": "File", + "start": 0, + "end": 63, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 9, + "column": 5 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 63, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 9, + "column": 5 + } + }, + "sourceType": "script", + "body": [ + { + "type": "TryStatement", + "start": 2, + "end": 63, + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 9, + "column": 5 + } + }, + "block": { + "type": "BlockStatement", + "start": 6, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 3, + "column": 3 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 12, + "end": 13, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 12, + "end": 13, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + ], + "directives": [], + "extra": { + "curly": true + } + }, + "handler": { + "type": "CatchClause", + "start": 18, + "end": 35, + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 6, + "column": 1 + } + }, + "param": { + "type": "Identifier", + "start": 24, + "end": 27, + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 9 + }, + "identifierName": "err" + }, + "name": "err" + }, + "body": { + "type": "BlockStatement", + "start": 28, + "end": 35, + "loc": { + "start": { + "line": 4, + "column": 10 + }, + "end": { + "line": 6, + "column": 1 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 32, + "end": 33, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 3 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 32, + "end": 33, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 3 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + } + ], + "directives": [], + "extra": { + "curly": true + } + } + }, + "guardedHandlers": [], + "finalizer": { + "type": "BlockStatement", + "start": 48, + "end": 63, + "loc": { + "start": { + "line": 7, + "column": 12 + }, + "end": { + "line": 9, + "column": 5 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 56, + "end": 57, + "loc": { + "start": { + "line": 8, + "column": 6 + }, + "end": { + "line": 8, + "column": 7 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 56, + "end": 57, + "loc": { + "start": { + "line": 8, + "column": 6 + }, + "end": { + "line": 8, + "column": 7 + } + }, + "extra": { + "rawValue": 3, + "raw": "3" + }, + "value": 3 + } + } + ], + "directives": [], + "extra": { + "curly": true + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/whitespace/try-catch-dedent/actual.js b/test/fixtures/lightscript/whitespace/try-catch-dedent/actual.js new file mode 100644 index 0000000000..f698279bac --- /dev/null +++ b/test/fixtures/lightscript/whitespace/try-catch-dedent/actual.js @@ -0,0 +1,4 @@ + try: + 1 +catch err: + 2 diff --git a/test/fixtures/lightscript/whitespace/try-catch-dedent/options.json b/test/fixtures/lightscript/whitespace/try-catch-dedent/options.json new file mode 100644 index 0000000000..d141c19616 --- /dev/null +++ b/test/fixtures/lightscript/whitespace/try-catch-dedent/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Missing catch or finally clause (1:2)" +} diff --git a/test/fixtures/lightscript/whitespace/try-catch-finally-dedent/actual.js b/test/fixtures/lightscript/whitespace/try-catch-finally-dedent/actual.js new file mode 100644 index 0000000000..5d3687357f --- /dev/null +++ b/test/fixtures/lightscript/whitespace/try-catch-finally-dedent/actual.js @@ -0,0 +1,6 @@ + try: + 1 + catch err: + 2 +finally: + 3 diff --git a/test/fixtures/lightscript/whitespace/try-catch-finally-dedent/options.json b/test/fixtures/lightscript/whitespace/try-catch-finally-dedent/options.json new file mode 100644 index 0000000000..ca47c17f5a --- /dev/null +++ b/test/fixtures/lightscript/whitespace/try-catch-finally-dedent/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token (5:0)" +} diff --git a/test/fixtures/lightscript/whitespace/try-catch-nested-mixed-2/actual.js b/test/fixtures/lightscript/whitespace/try-catch-nested-mixed-2/actual.js new file mode 100644 index 0000000000..3386daffdb --- /dev/null +++ b/test/fixtures/lightscript/whitespace/try-catch-nested-mixed-2/actual.js @@ -0,0 +1,9 @@ +try: + try { + 1 + } catch e { + 2 + } +finally { + 3 +} diff --git a/test/fixtures/lightscript/whitespace/try-catch-nested-mixed-2/options.json b/test/fixtures/lightscript/whitespace/try-catch-nested-mixed-2/options.json new file mode 100644 index 0000000000..daf899c4c9 --- /dev/null +++ b/test/fixtures/lightscript/whitespace/try-catch-nested-mixed-2/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected : (7:8)" +} diff --git a/test/fixtures/lightscript/whitespace/try-catch-nested-mixed/actual.js b/test/fixtures/lightscript/whitespace/try-catch-nested-mixed/actual.js new file mode 100644 index 0000000000..25b31a18ab --- /dev/null +++ b/test/fixtures/lightscript/whitespace/try-catch-nested-mixed/actual.js @@ -0,0 +1,8 @@ +try: + try { + 1 + } catch e { + 2 + } +finally: + 3 diff --git a/test/fixtures/lightscript/whitespace/try-catch-nested-mixed/expected.json b/test/fixtures/lightscript/whitespace/try-catch-nested-mixed/expected.json new file mode 100644 index 0000000000..5694638cea --- /dev/null +++ b/test/fixtures/lightscript/whitespace/try-catch-nested-mixed/expected.json @@ -0,0 +1,288 @@ +{ + "type": "File", + "start": 0, + "end": 55, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 8, + "column": 3 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 55, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 8, + "column": 3 + } + }, + "sourceType": "script", + "body": [ + { + "type": "TryStatement", + "start": 0, + "end": 55, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 8, + "column": 3 + } + }, + "block": { + "type": "BlockStatement", + "start": 3, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "body": [ + { + "type": "TryStatement", + "start": 7, + "end": 42, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "block": { + "type": "BlockStatement", + "start": 11, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 4, + "column": 3 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 5 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 5 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + ], + "directives": [], + "extra": { + "curly": true + } + }, + "handler": { + "type": "CatchClause", + "start": 23, + "end": 42, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "param": { + "type": "Identifier", + "start": 29, + "end": 30, + "loc": { + "start": { + "line": 4, + "column": 10 + }, + "end": { + "line": 4, + "column": 11 + }, + "identifierName": "e" + }, + "name": "e" + }, + "body": { + "type": "BlockStatement", + "start": 31, + "end": 42, + "loc": { + "start": { + "line": 4, + "column": 12 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 37, + "end": 38, + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 5 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 37, + "end": 38, + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 5 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + } + ], + "directives": [], + "extra": { + "curly": true + } + } + }, + "guardedHandlers": [] + } + ], + "directives": [], + "extra": { + "curly": false + } + }, + "handler": null, + "guardedHandlers": [], + "finalizer": { + "type": "BlockStatement", + "start": 50, + "end": 55, + "loc": { + "start": { + "line": 7, + "column": 7 + }, + "end": { + "line": 8, + "column": 3 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 54, + "end": 55, + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 3 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 54, + "end": 55, + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 3 + } + }, + "extra": { + "rawValue": 3, + "raw": "3" + }, + "value": 3 + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/whitespace/try-catch-nested-no-catch-2/actual.js b/test/fixtures/lightscript/whitespace/try-catch-nested-no-catch-2/actual.js new file mode 100644 index 0000000000..8de2b44945 --- /dev/null +++ b/test/fixtures/lightscript/whitespace/try-catch-nested-no-catch-2/actual.js @@ -0,0 +1,9 @@ +try: + try { + 1 + } +catch err { + 2 +} +finally: + 3 diff --git a/test/fixtures/lightscript/whitespace/try-catch-nested-no-catch-2/options.json b/test/fixtures/lightscript/whitespace/try-catch-nested-no-catch-2/options.json new file mode 100644 index 0000000000..bc22fedcc4 --- /dev/null +++ b/test/fixtures/lightscript/whitespace/try-catch-nested-no-catch-2/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Missing catch or finally clause (2:2)" +} diff --git a/test/fixtures/lightscript/whitespace/try-catch-nested-no-catch/actual.js b/test/fixtures/lightscript/whitespace/try-catch-nested-no-catch/actual.js new file mode 100644 index 0000000000..71ffc7eeb1 --- /dev/null +++ b/test/fixtures/lightscript/whitespace/try-catch-nested-no-catch/actual.js @@ -0,0 +1,8 @@ +try: + try { + 1 + } +catch err: + 2 +finally: + 3 diff --git a/test/fixtures/lightscript/whitespace/try-catch-nested-no-catch/options.json b/test/fixtures/lightscript/whitespace/try-catch-nested-no-catch/options.json new file mode 100644 index 0000000000..bc22fedcc4 --- /dev/null +++ b/test/fixtures/lightscript/whitespace/try-catch-nested-no-catch/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Missing catch or finally clause (2:2)" +} diff --git a/test/fixtures/lightscript/whitespace/try-catch-nested/actual.js b/test/fixtures/lightscript/whitespace/try-catch-nested/actual.js new file mode 100644 index 0000000000..d0d81bb9b1 --- /dev/null +++ b/test/fixtures/lightscript/whitespace/try-catch-nested/actual.js @@ -0,0 +1,7 @@ +try: + try: + a() + catch e: + b() +finally: + c() diff --git a/test/fixtures/lightscript/whitespace/try-catch-nested/expected.json b/test/fixtures/lightscript/whitespace/try-catch-nested/expected.json new file mode 100644 index 0000000000..a9abefcb0a --- /dev/null +++ b/test/fixtures/lightscript/whitespace/try-catch-nested/expected.json @@ -0,0 +1,328 @@ +{ + "type": "File", + "start": 0, + "end": 53, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 5 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 53, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 5 + } + }, + "sourceType": "script", + "body": [ + { + "type": "TryStatement", + "start": 0, + "end": 53, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 5 + } + }, + "block": { + "type": "BlockStatement", + "start": 3, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 5, + "column": 7 + } + }, + "body": [ + { + "type": "TryStatement", + "start": 7, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 5, + "column": 7 + } + }, + "block": { + "type": "BlockStatement", + "start": 10, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 3, + "column": 7 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 16, + "end": 19, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 7 + } + }, + "expression": { + "type": "CallExpression", + "start": 16, + "end": 19, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 7 + } + }, + "callee": { + "type": "Identifier", + "start": 16, + "end": 17, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 5 + }, + "identifierName": "a" + }, + "name": "a" + }, + "arguments": [] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + }, + "handler": { + "type": "CatchClause", + "start": 22, + "end": 38, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 5, + "column": 7 + } + }, + "param": { + "type": "Identifier", + "start": 28, + "end": 29, + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 9 + }, + "identifierName": "e" + }, + "name": "e" + }, + "body": { + "type": "BlockStatement", + "start": 29, + "end": 38, + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 5, + "column": 7 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 35, + "end": 38, + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 7 + } + }, + "expression": { + "type": "CallExpression", + "start": 35, + "end": 38, + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 7 + } + }, + "callee": { + "type": "Identifier", + "start": 35, + "end": 36, + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 5 + }, + "identifierName": "b" + }, + "name": "b" + }, + "arguments": [] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + }, + "guardedHandlers": [], + "finalizer": null + } + ], + "directives": [], + "extra": { + "curly": false + } + }, + "handler": null, + "guardedHandlers": [], + "finalizer": { + "type": "BlockStatement", + "start": 46, + "end": 53, + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 7, + "column": 5 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 50, + "end": 53, + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 5 + } + }, + "expression": { + "type": "CallExpression", + "start": 50, + "end": 53, + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 5 + } + }, + "callee": { + "type": "Identifier", + "start": 50, + "end": 51, + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 3 + }, + "identifierName": "c" + }, + "name": "c" + }, + "arguments": [] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/whitespace/try-finally-brace-then-colon/actual.js b/test/fixtures/lightscript/whitespace/try-finally-brace-then-colon/actual.js new file mode 100644 index 0000000000..bb73ed72b2 --- /dev/null +++ b/test/fixtures/lightscript/whitespace/try-finally-brace-then-colon/actual.js @@ -0,0 +1,4 @@ +try { + 1 +} finally: + 2 diff --git a/test/fixtures/lightscript/whitespace/try-finally-brace-then-colon/options.json b/test/fixtures/lightscript/whitespace/try-finally-brace-then-colon/options.json new file mode 100644 index 0000000000..c8bccb764b --- /dev/null +++ b/test/fixtures/lightscript/whitespace/try-finally-brace-then-colon/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected { (3:9)" +} diff --git a/test/fixtures/lightscript/whitespace/try-finally-colon-then-brace/actual.js b/test/fixtures/lightscript/whitespace/try-finally-colon-then-brace/actual.js new file mode 100644 index 0000000000..ac33b26d97 --- /dev/null +++ b/test/fixtures/lightscript/whitespace/try-finally-colon-then-brace/actual.js @@ -0,0 +1,5 @@ +try: + 1 +finally { + 2 +} diff --git a/test/fixtures/lightscript/whitespace/try-finally-colon-then-brace/options.json b/test/fixtures/lightscript/whitespace/try-finally-colon-then-brace/options.json new file mode 100644 index 0000000000..8b108e2695 --- /dev/null +++ b/test/fixtures/lightscript/whitespace/try-finally-colon-then-brace/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected : (3:8)" +}