diff --git a/src/parser/statement.js b/src/parser/statement.js index 3c03720b31..ec5ff529d7 100644 --- a/src/parser/statement.js +++ b/src/parser/statement.js @@ -236,15 +236,14 @@ pp.parseDoStatement = function (node) { // b/c it expects a trailing colon or brace, which you don't have here. if (this.hasPlugin("lightscript")) { - // allow parens; if not used, enforce semicolon or newline. - if (this.eat(tt.parenL)) { - node.test = this.parseExpression(); - this.expect(tt.parenR); - this.eat(tt.semi); - } else { - node.test = this.parseExpression(); - this.semicolon(); + // allow parens; enforce semicolon or newline whether they're used or not. + node.test = this.parseExpression(); + if (node.test.extra && node.test.extra.parenthesized) { + delete node.test.extra.parenthesized; + delete node.test.extra.parenStart; + this.addExtra(node, "hasParens", true); } + this.semicolon(); } else { node.test = this.parseParenExpression(); this.eat(tt.semi); @@ -272,8 +271,9 @@ pp.parseForStatement = function (node) { } if (this.hasPlugin("lightscript")) { - // TODO: check that closing paren is/isnt there to match - this.eat(tt.parenL); + if (this.eat(tt.parenL)) { + this.addExtra(node, "hasParens", true); + } } else { this.expect(tt.parenL); } @@ -450,14 +450,16 @@ pp.parseTryStatement = function (node) { this.next(); if (this.hasPlugin("lightscript")) { - this.eat(tt.parenL); + if (this.eat(tt.parenL)) { + this.addExtra(clause, "hasParens", true); + } } else { this.expect(tt.parenL); } clause.param = this.parseBindingAtom(); this.checkLVal(clause.param, true, Object.create(null), "catch clause"); if (this.hasPlugin("lightscript")) { - this.eat(tt.parenR); + this.expectParenFreeBlockStart(clause); } else { this.expect(tt.parenR); } @@ -617,7 +619,7 @@ pp.parseFor = function (node, init) { node.update = this.match(tt.parenR) ? null : this.parseExpression(); if (this.hasPlugin("lightscript")) { - this.expectParenFreeBlockStart(); + this.expectParenFreeBlockStart(node); } else { this.expect(tt.parenR); } @@ -643,7 +645,7 @@ pp.parseForIn = function (node, init, forAwait) { node.right = this.parseExpression(); if (this.hasPlugin("lightscript")) { - this.expectParenFreeBlockStart(); + this.expectParenFreeBlockStart(node); } else { this.expect(tt.parenR); } diff --git a/src/plugins/lightscript.js b/src/plugins/lightscript.js index 242b5d4852..b0358a6f16 100644 --- a/src/plugins/lightscript.js +++ b/src/plugins/lightscript.js @@ -93,7 +93,7 @@ pp.parseEnhancedForIn = function (node) { const iterable = this.parseMaybeAssign(true); - this.expectParenFreeBlockStart(); + this.expectParenFreeBlockStart(node); node.body = this.parseStatement(false); if ((matchingIterationType === "idx") || (matchingIterationType === "elem")) { @@ -105,12 +105,13 @@ pp.parseEnhancedForIn = function (node) { } }; -pp.expectParenFreeBlockStart = function () { +pp.expectParenFreeBlockStart = function (node) { // if true: blah // if true { blah } // if (true) blah - // TODO: ensure matching parens, not just allowing one on either side - if (!(this.match(tt.colon) || this.match(tt.braceL) || this.eat(tt.parenR))) { + if (node && node.extra && node.extra.hasParens) { + this.expect(tt.parenR); + } else if (!(this.match(tt.colon) || this.match(tt.braceL))) { this.unexpected(null, "Paren-free test expressions must be followed by braces or a colon."); } }; @@ -483,7 +484,29 @@ export default function (instance) { instance.extend("parseParenExpression", function (inner) { return function () { - if (this.match(tt.parenL)) return inner.apply(this, arguments); + // parens are special here; they might be `if (x) -1` or `if (x < 1) and y: -1` + if (this.match(tt.parenL)) { + const state = this.state.clone(); + + // first, try paren-free style + try { + const val = this.parseExpression(); + if (this.match(tt.braceL) || this.match(tt.colon)) { + if (val.extra && val.extra.parenthesized) { + delete val.extra.parenthesized; + delete val.extra.parenStart; + } + return val; + } + } catch (_err) { + // fall-through, will re-raise if it's an error below + } + + // otherwise, try traditional parseParenExpression + this.state = state; + return inner.apply(this, arguments); + } + const val = this.parseExpression(); this.expectParenFreeBlockStart(); return val; diff --git a/test/fixtures/es2015/uncategorised/197/options.lightscript.json b/test/fixtures/es2015/uncategorised/197/options.lightscript.json new file mode 100644 index 0000000000..fa7318f54c --- /dev/null +++ b/test/fixtures/es2015/uncategorised/197/options.lightscript.json @@ -0,0 +1,4 @@ +{ + "ecmaVersion": 6, + "throws": "Unexpected token, expected ; (1:20)" +} diff --git a/test/fixtures/esprima/es2015-array-pattern/with-default-catch-param-fail/options.lightscript.json b/test/fixtures/esprima/es2015-array-pattern/with-default-catch-param-fail/options.lightscript.json deleted file mode 100644 index 62c2636574..0000000000 --- a/test/fixtures/esprima/es2015-array-pattern/with-default-catch-param-fail/options.lightscript.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token, expected { (1:19)" -} diff --git a/test/fixtures/esprima/invalid-syntax/migrated_0135/options.lightscript.json b/test/fixtures/esprima/invalid-syntax/migrated_0135/options.lightscript.json deleted file mode 100644 index 7cc6efa9be..0000000000 --- a/test/fixtures/esprima/invalid-syntax/migrated_0135/options.lightscript.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token, expected { (1:20)" -} diff --git a/test/fixtures/lightscript/paren-free/do-while-then-paren-unfortunate/actual.js b/test/fixtures/lightscript/paren-free/do-while-then-paren-unfortunate/actual.js new file mode 100644 index 0000000000..aec7fbe95b --- /dev/null +++ b/test/fixtures/lightscript/paren-free/do-while-then-paren-unfortunate/actual.js @@ -0,0 +1 @@ +do {} while (a) (b) diff --git a/test/fixtures/lightscript/paren-free/do-while-then-paren-unfortunate/expected.json b/test/fixtures/lightscript/paren-free/do-while-then-paren-unfortunate/expected.json new file mode 100644 index 0000000000..323c22311b --- /dev/null +++ b/test/fixtures/lightscript/paren-free/do-while-then-paren-unfortunate/expected.json @@ -0,0 +1,124 @@ +{ + "type": "File", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "sourceType": "script", + "body": [ + { + "type": "DoWhileStatement", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "body": { + "type": "BlockStatement", + "start": 3, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "body": [], + "directives": [], + "extra": { + "curly": true + } + }, + "test": { + "type": "CallExpression", + "start": 12, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "callee": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "a" + }, + "name": "a", + "extra": { + "parenthesized": true, + "parenStart": 12 + } + }, + "arguments": [ + { + "type": "Identifier", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 18 + }, + "identifierName": "b" + }, + "name": "b" + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/paren-free/for-mismatched-paren-left/actual.js b/test/fixtures/lightscript/paren-free/for-mismatched-paren-left/actual.js new file mode 100644 index 0000000000..3c2d97fb6d --- /dev/null +++ b/test/fixtures/lightscript/paren-free/for-mismatched-paren-left/actual.js @@ -0,0 +1 @@ +for (;; {} diff --git a/test/fixtures/lightscript/paren-free/for-mismatched-paren-left/options.json b/test/fixtures/lightscript/paren-free/for-mismatched-paren-left/options.json new file mode 100644 index 0000000000..a90d01d9f3 --- /dev/null +++ b/test/fixtures/lightscript/paren-free/for-mismatched-paren-left/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected ) (1:10)" +} diff --git a/test/fixtures/lightscript/paren-free/for-mismatched-paren-right/actual.js b/test/fixtures/lightscript/paren-free/for-mismatched-paren-right/actual.js new file mode 100644 index 0000000000..7641c90466 --- /dev/null +++ b/test/fixtures/lightscript/paren-free/for-mismatched-paren-right/actual.js @@ -0,0 +1 @@ +for ;;) {} diff --git a/test/fixtures/lightscript/paren-free/for-mismatched-paren-right/options.json b/test/fixtures/lightscript/paren-free/for-mismatched-paren-right/options.json new file mode 100644 index 0000000000..d75c9a4e85 --- /dev/null +++ b/test/fixtures/lightscript/paren-free/for-mismatched-paren-right/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Paren-free test expressions must be followed by braces or a colon. (1:6)" +} diff --git a/test/fixtures/lightscript/paren-free/for-of-mismatched-left/actual.js b/test/fixtures/lightscript/paren-free/for-of-mismatched-left/actual.js new file mode 100644 index 0000000000..a0f4ec7183 --- /dev/null +++ b/test/fixtures/lightscript/paren-free/for-of-mismatched-left/actual.js @@ -0,0 +1 @@ +for (let x of {a: 1} {} diff --git a/test/fixtures/lightscript/paren-free/for-of-mismatched-left/options.json b/test/fixtures/lightscript/paren-free/for-of-mismatched-left/options.json new file mode 100644 index 0000000000..5ceb74b6b9 --- /dev/null +++ b/test/fixtures/lightscript/paren-free/for-of-mismatched-left/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected ) (1:21)" +} diff --git a/test/fixtures/lightscript/paren-free/for-of-mismatched-right/actual.js b/test/fixtures/lightscript/paren-free/for-of-mismatched-right/actual.js new file mode 100644 index 0000000000..1556f642b0 --- /dev/null +++ b/test/fixtures/lightscript/paren-free/for-of-mismatched-right/actual.js @@ -0,0 +1 @@ +for let x of {a: 1}) {} diff --git a/test/fixtures/lightscript/paren-free/for-of-mismatched-right/options.json b/test/fixtures/lightscript/paren-free/for-of-mismatched-right/options.json new file mode 100644 index 0000000000..b9d084acb5 --- /dev/null +++ b/test/fixtures/lightscript/paren-free/for-of-mismatched-right/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Paren-free test expressions must be followed by braces or a colon. (1:19)" +} diff --git a/test/fixtures/lightscript/paren-free/paren-block-no-space/actual.js b/test/fixtures/lightscript/paren-free/paren-block-no-space/actual.js new file mode 100644 index 0000000000..28be2e8245 --- /dev/null +++ b/test/fixtures/lightscript/paren-free/paren-block-no-space/actual.js @@ -0,0 +1 @@ +if (a){} diff --git a/test/fixtures/lightscript/paren-free/paren-block-no-space/expected.json b/test/fixtures/lightscript/paren-free/paren-block-no-space/expected.json new file mode 100644 index 0000000000..adf7b67150 --- /dev/null +++ b/test/fixtures/lightscript/paren-free/paren-block-no-space/expected.json @@ -0,0 +1,87 @@ +{ + "type": "File", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "sourceType": "script", + "body": [ + { + "type": "IfStatement", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "test": { + "type": "Identifier", + "start": 4, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "a" + }, + "name": "a" + }, + "consequent": { + "type": "BlockStatement", + "start": 6, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "body": [], + "directives": [], + "extra": { + "curly": true + } + }, + "alternate": null + } + ], + "directives": [] + } +} diff --git a/test/fixtures/lightscript/paren-free/paren-identifier-body-no-space/actual.js b/test/fixtures/lightscript/paren-free/paren-identifier-body-no-space/actual.js new file mode 100644 index 0000000000..14d7c8eb8b --- /dev/null +++ b/test/fixtures/lightscript/paren-free/paren-identifier-body-no-space/actual.js @@ -0,0 +1 @@ +if (1)a; diff --git a/test/fixtures/lightscript/paren-free/paren-identifier-body-no-space/expected.json b/test/fixtures/lightscript/paren-free/paren-identifier-body-no-space/expected.json new file mode 100644 index 0000000000..ea08084671 --- /dev/null +++ b/test/fixtures/lightscript/paren-free/paren-identifier-body-no-space/expected.json @@ -0,0 +1,102 @@ +{ + "type": "File", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "sourceType": "script", + "body": [ + { + "type": "IfStatement", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "test": { + "type": "NumericLiteral", + "start": 4, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + }, + "consequent": { + "type": "ExpressionStatement", + "start": 6, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "expression": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "a" + }, + "name": "a" + } + }, + "alternate": null + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/paren-free/paren-member-expression-block/actual.js b/test/fixtures/lightscript/paren-free/paren-member-expression-block/actual.js new file mode 100644 index 0000000000..0256b20c02 --- /dev/null +++ b/test/fixtures/lightscript/paren-free/paren-member-expression-block/actual.js @@ -0,0 +1 @@ +if ('hi').indexOf('h') < 0 {} diff --git a/test/fixtures/lightscript/paren-free/paren-member-expression-block/expected.json b/test/fixtures/lightscript/paren-free/paren-member-expression-block/expected.json new file mode 100644 index 0000000000..fe69f7b532 --- /dev/null +++ b/test/fixtures/lightscript/paren-free/paren-member-expression-block/expected.json @@ -0,0 +1,198 @@ +{ + "type": "File", + "start": 0, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "sourceType": "script", + "body": [ + { + "type": "IfStatement", + "start": 0, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "test": { + "type": "BinaryExpression", + "start": 3, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "left": { + "type": "CallExpression", + "start": 3, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "callee": { + "type": "MemberExpression", + "start": 3, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "object": { + "type": "StringLiteral", + "start": 4, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "extra": { + "rawValue": "hi", + "raw": "'hi'", + "parenthesized": true, + "parenStart": 3 + }, + "value": "hi" + }, + "property": { + "type": "Identifier", + "start": 10, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 17 + }, + "identifierName": "indexOf" + }, + "name": "indexOf" + }, + "computed": false + }, + "arguments": [ + { + "type": "StringLiteral", + "start": 18, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "extra": { + "rawValue": "h", + "raw": "'h'" + }, + "value": "h" + } + ] + }, + "operator": "<", + "right": { + "type": "NumericLiteral", + "start": 25, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + }, + "consequent": { + "type": "BlockStatement", + "start": 27, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 27 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "body": [], + "directives": [], + "extra": { + "curly": true + } + }, + "alternate": null + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/paren-free/paren-member-expression-invalid/actual.js b/test/fixtures/lightscript/paren-free/paren-member-expression-invalid/actual.js new file mode 100644 index 0000000000..1e4583e2ea --- /dev/null +++ b/test/fixtures/lightscript/paren-free/paren-member-expression-invalid/actual.js @@ -0,0 +1 @@ +if ('hi').indexOf('h') hi diff --git a/test/fixtures/lightscript/paren-free/paren-member-expression-invalid/options.json b/test/fixtures/lightscript/paren-free/paren-member-expression-invalid/options.json new file mode 100644 index 0000000000..2a28555f76 --- /dev/null +++ b/test/fixtures/lightscript/paren-free/paren-member-expression-invalid/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token (1:9)" +} diff --git a/test/fixtures/lightscript/paren-free/paren-semi-body-no-space/actual.js b/test/fixtures/lightscript/paren-free/paren-semi-body-no-space/actual.js new file mode 100644 index 0000000000..114343c3b7 --- /dev/null +++ b/test/fixtures/lightscript/paren-free/paren-semi-body-no-space/actual.js @@ -0,0 +1 @@ +if (a); diff --git a/test/fixtures/lightscript/paren-free/paren-semi-body-no-space/expected.json b/test/fixtures/lightscript/paren-free/paren-semi-body-no-space/expected.json new file mode 100644 index 0000000000..81ba49a7ea --- /dev/null +++ b/test/fixtures/lightscript/paren-free/paren-semi-body-no-space/expected.json @@ -0,0 +1,82 @@ +{ + "type": "File", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "sourceType": "script", + "body": [ + { + "type": "IfStatement", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "test": { + "type": "Identifier", + "start": 4, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "a" + }, + "name": "a" + }, + "consequent": { + "type": "EmptyStatement", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + } + }, + "alternate": null + } + ], + "directives": [] + } +} diff --git a/test/fixtures/lightscript/paren-free/paren-then-decimal/actual.js b/test/fixtures/lightscript/paren-free/paren-then-decimal/actual.js new file mode 100644 index 0000000000..b65d78cffd --- /dev/null +++ b/test/fixtures/lightscript/paren-free/paren-then-decimal/actual.js @@ -0,0 +1 @@ +if (x) .1 {} diff --git a/test/fixtures/lightscript/paren-free/paren-then-decimal/expected.json b/test/fixtures/lightscript/paren-free/paren-then-decimal/expected.json new file mode 100644 index 0000000000..9de0f75391 --- /dev/null +++ b/test/fixtures/lightscript/paren-free/paren-then-decimal/expected.json @@ -0,0 +1,127 @@ +{ + "type": "File", + "start": 0, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "sourceType": "script", + "body": [ + { + "type": "IfStatement", + "start": 0, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "test": { + "type": "MemberExpression", + "start": 3, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "object": { + "type": "Identifier", + "start": 4, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "x" + }, + "name": "x", + "extra": { + "parenthesized": true, + "parenStart": 3 + } + }, + "property": { + "type": "NumericLiteral", + "start": 7, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + }, + "computed": true + }, + "consequent": { + "type": "BlockStatement", + "start": 10, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "body": [], + "directives": [], + "extra": { + "curly": true + } + }, + "alternate": null + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/paren-free/paren-then-numeric-member-no-space/actual.js b/test/fixtures/lightscript/paren-free/paren-then-numeric-member-no-space/actual.js new file mode 100644 index 0000000000..4d0768dacf --- /dev/null +++ b/test/fixtures/lightscript/paren-free/paren-then-numeric-member-no-space/actual.js @@ -0,0 +1 @@ +if (x).1 {} diff --git a/test/fixtures/lightscript/paren-free/paren-then-numeric-member-no-space/expected.json b/test/fixtures/lightscript/paren-free/paren-then-numeric-member-no-space/expected.json new file mode 100644 index 0000000000..ffac4d874a --- /dev/null +++ b/test/fixtures/lightscript/paren-free/paren-then-numeric-member-no-space/expected.json @@ -0,0 +1,127 @@ +{ + "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": "IfStatement", + "start": 0, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "test": { + "type": "MemberExpression", + "start": 3, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "object": { + "type": "Identifier", + "start": 4, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "x" + }, + "name": "x", + "extra": { + "parenthesized": true, + "parenStart": 3 + } + }, + "property": { + "type": "NumericLiteral", + "start": 6, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + }, + "computed": true + }, + "consequent": { + "type": "BlockStatement", + "start": 9, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "body": [], + "directives": [], + "extra": { + "curly": true + } + }, + "alternate": null + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/paren-free/paren-then-numeric-member/actual.js b/test/fixtures/lightscript/paren-free/paren-then-numeric-member/actual.js new file mode 100644 index 0000000000..fc6944b683 --- /dev/null +++ b/test/fixtures/lightscript/paren-free/paren-then-numeric-member/actual.js @@ -0,0 +1 @@ +if (x) .1 diff --git a/test/fixtures/lightscript/paren-free/paren-then-numeric-member/expected.json b/test/fixtures/lightscript/paren-free/paren-then-numeric-member/expected.json new file mode 100644 index 0000000000..81cc25320d --- /dev/null +++ b/test/fixtures/lightscript/paren-free/paren-then-numeric-member/expected.json @@ -0,0 +1,102 @@ +{ + "type": "File", + "start": 0, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "sourceType": "script", + "body": [ + { + "type": "IfStatement", + "start": 0, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "test": { + "type": "Identifier", + "start": 4, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "x" + }, + "name": "x" + }, + "consequent": { + "type": "ExpressionStatement", + "start": 7, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 7, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "extra": { + "rawValue": 0.1, + "raw": ".1" + }, + "value": 0.1 + } + }, + "alternate": null + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/paren-free/paren-then-paren/actual.js b/test/fixtures/lightscript/paren-free/paren-then-paren/actual.js new file mode 100644 index 0000000000..74ac17403e --- /dev/null +++ b/test/fixtures/lightscript/paren-free/paren-then-paren/actual.js @@ -0,0 +1 @@ +if (x)(y) diff --git a/test/fixtures/lightscript/paren-free/paren-then-paren/expected.json b/test/fixtures/lightscript/paren-free/paren-then-paren/expected.json new file mode 100644 index 0000000000..7202d9c916 --- /dev/null +++ b/test/fixtures/lightscript/paren-free/paren-then-paren/expected.json @@ -0,0 +1,103 @@ +{ + "type": "File", + "start": 0, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "sourceType": "script", + "body": [ + { + "type": "IfStatement", + "start": 0, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "test": { + "type": "Identifier", + "start": 4, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "x" + }, + "name": "x" + }, + "consequent": { + "type": "ExpressionStatement", + "start": 6, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "expression": { + "type": "Identifier", + "start": 7, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + }, + "identifierName": "y" + }, + "name": "y", + "extra": { + "parenthesized": true, + "parenStart": 6 + } + } + }, + "alternate": null + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/paren-free/paren-then-update-expression/actual.js b/test/fixtures/lightscript/paren-free/paren-then-update-expression/actual.js new file mode 100644 index 0000000000..7f1ffd2d19 --- /dev/null +++ b/test/fixtures/lightscript/paren-free/paren-then-update-expression/actual.js @@ -0,0 +1 @@ +while (x)-- > 0 {} diff --git a/test/fixtures/lightscript/paren-free/paren-then-update-expression/expected.json b/test/fixtures/lightscript/paren-free/paren-then-update-expression/expected.json new file mode 100644 index 0000000000..6a964fb501 --- /dev/null +++ b/test/fixtures/lightscript/paren-free/paren-then-update-expression/expected.json @@ -0,0 +1,143 @@ +{ + "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": "WhileStatement", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "test": { + "type": "BinaryExpression", + "start": 6, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "left": { + "type": "UpdateExpression", + "start": 6, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "operator": "--", + "prefix": false, + "argument": { + "type": "Identifier", + "start": 7, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + }, + "identifierName": "x" + }, + "name": "x", + "extra": { + "parenthesized": true, + "parenStart": 6 + } + } + }, + "operator": ">", + "right": { + "type": "NumericLiteral", + "start": 14, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + }, + "body": { + "type": "BlockStatement", + "start": 16, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "body": [], + "directives": [], + "extra": { + "curly": true + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/paren-free/try-catch-mismatch-left/actual.js b/test/fixtures/lightscript/paren-free/try-catch-mismatch-left/actual.js new file mode 100644 index 0000000000..c080051eed --- /dev/null +++ b/test/fixtures/lightscript/paren-free/try-catch-mismatch-left/actual.js @@ -0,0 +1,5 @@ +try { + +} catch (err { + +} diff --git a/test/fixtures/lightscript/paren-free/try-catch-mismatch-left/options.json b/test/fixtures/lightscript/paren-free/try-catch-mismatch-left/options.json new file mode 100644 index 0000000000..d5f970007a --- /dev/null +++ b/test/fixtures/lightscript/paren-free/try-catch-mismatch-left/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected ) (3:13)" +} diff --git a/test/fixtures/lightscript/paren-free/try-catch-mismatch-right/actual.js b/test/fixtures/lightscript/paren-free/try-catch-mismatch-right/actual.js new file mode 100644 index 0000000000..01287e7399 --- /dev/null +++ b/test/fixtures/lightscript/paren-free/try-catch-mismatch-right/actual.js @@ -0,0 +1,5 @@ +try { + +} catch err) { + +} diff --git a/test/fixtures/lightscript/paren-free/try-catch-mismatch-right/options.json b/test/fixtures/lightscript/paren-free/try-catch-mismatch-right/options.json new file mode 100644 index 0000000000..e0bf7718c3 --- /dev/null +++ b/test/fixtures/lightscript/paren-free/try-catch-mismatch-right/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Paren-free test expressions must be followed by braces or a colon. (3:11)" +} diff --git a/test/fixtures/lightscript/paren-free/try-catch-no-block-or-paren/actual.js b/test/fixtures/lightscript/paren-free/try-catch-no-block-or-paren/actual.js new file mode 100644 index 0000000000..c24a86e044 --- /dev/null +++ b/test/fixtures/lightscript/paren-free/try-catch-no-block-or-paren/actual.js @@ -0,0 +1,3 @@ +try { + +} catch err 1 diff --git a/test/fixtures/lightscript/paren-free/try-catch-no-block-or-paren/options.json b/test/fixtures/lightscript/paren-free/try-catch-no-block-or-paren/options.json new file mode 100644 index 0000000000..d79d39adb4 --- /dev/null +++ b/test/fixtures/lightscript/paren-free/try-catch-no-block-or-paren/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Paren-free test expressions must be followed by braces or a colon. (3:12)" +} diff --git a/test/fixtures/lightscript/paren-free/while-mismatched-paren-left/actual.js b/test/fixtures/lightscript/paren-free/while-mismatched-paren-left/actual.js new file mode 100644 index 0000000000..b086eb8036 --- /dev/null +++ b/test/fixtures/lightscript/paren-free/while-mismatched-paren-left/actual.js @@ -0,0 +1 @@ +while (0 {} diff --git a/test/fixtures/lightscript/paren-free/while-mismatched-paren-left/options.json b/test/fixtures/lightscript/paren-free/while-mismatched-paren-left/options.json new file mode 100644 index 0000000000..60368e5bc9 --- /dev/null +++ b/test/fixtures/lightscript/paren-free/while-mismatched-paren-left/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected ) (1:9)" +} diff --git a/test/fixtures/lightscript/paren-free/while-mismatched-paren-right/actual.js b/test/fixtures/lightscript/paren-free/while-mismatched-paren-right/actual.js new file mode 100644 index 0000000000..a0bb4913bd --- /dev/null +++ b/test/fixtures/lightscript/paren-free/while-mismatched-paren-right/actual.js @@ -0,0 +1 @@ +while 0) {} diff --git a/test/fixtures/lightscript/paren-free/while-mismatched-paren-right/options.json b/test/fixtures/lightscript/paren-free/while-mismatched-paren-right/options.json new file mode 100644 index 0000000000..54d200b06a --- /dev/null +++ b/test/fixtures/lightscript/paren-free/while-mismatched-paren-right/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Paren-free test expressions must be followed by braces or a colon. (1:7)" +} diff --git a/test/fixtures/lightscript/whitespace/do-while/actual.js b/test/fixtures/lightscript/whitespace/do-while/actual.js new file mode 100644 index 0000000000..03075c7bb5 --- /dev/null +++ b/test/fixtures/lightscript/whitespace/do-while/actual.js @@ -0,0 +1,3 @@ +do: + x() +while false diff --git a/test/fixtures/lightscript/whitespace/do-while/expected.json b/test/fixtures/lightscript/whitespace/do-while/expected.json new file mode 100644 index 0000000000..3e0dc15b94 --- /dev/null +++ b/test/fixtures/lightscript/whitespace/do-while/expected.json @@ -0,0 +1,134 @@ +{ + "type": "File", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "sourceType": "script", + "body": [ + { + "type": "DoWhileStatement", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "body": { + "type": "BlockStatement", + "start": 2, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 2, + "column": 5 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 6, + "end": 9, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 5 + } + }, + "expression": { + "type": "CallExpression", + "start": 6, + "end": 9, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 5 + } + }, + "callee": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + }, + "identifierName": "x" + }, + "name": "x" + }, + "arguments": [] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + }, + "test": { + "type": "BooleanLiteral", + "start": 16, + "end": 21, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "value": false + } + } + ], + "directives": [] + } +} \ No newline at end of file