diff --git a/src/parser/statement.js b/src/parser/statement.js index 5c9d27145e..6b534ba232 100644 --- a/src/parser/statement.js +++ b/src/parser/statement.js @@ -60,6 +60,11 @@ pp.parseStatement = function (declaration, topLevel) { const starttype = this.state.type; const node = this.startNode(); + let expr = null; + let objParseError = null; + + const isBlock = this.state.nextBraceIsBlock; + if (this.state.nextBraceIsBlock !== undefined) delete this.state.nextBraceIsBlock; // Most types of statements are recognized by the keyword they // start with. Many are trivial to parse, some require a bit of @@ -94,10 +99,32 @@ pp.parseStatement = function (declaration, topLevel) { case tt._while: return this.parseWhileStatement(node); case tt._with: return this.parseWithStatement(node); case tt.braceL: - // in lightscript, allow line-starting `{` to be parsed as obj or obj pattern - if (this.hasPlugin("lightscript") && this.isLineBreak()) { + if (this.hasPlugin("whiteblockOnly")) { + // whiteblockOnly = what follows must be an ObjectExpression/Pattern break; - } else if (this.hasPlugin("whiteblockOnly")) { + } else if (this.hasPlugin("whiteblockPreferred") && !isBlock) { + // whiteblockPreferred = try to parse as obj, otherwise rewind and parse as block + const state = this.state.clone(); + try { + expr = this.parseExpression(); + break; + } catch (err) { + this.state = state; + objParseError = err; + } + + try { + return this.parseBlock(); + } catch (err) { + if (objParseError && objParseError.pos >= err.pos) { + throw objParseError; + } else { + throw err; + } + } + } else if (this.hasPlugin("lightscript") && this.isLineBreak() && !isBlock) { + // legacy lsc behavior + // allow line-starting `{` to be parsed as obj or obj pattern break; } else { return this.parseBlock(); @@ -141,7 +168,7 @@ pp.parseStatement = function (declaration, topLevel) { // next token is a colon and the expression was a simple // Identifier node, we switch to interpreting it as a label. const maybeName = this.state.value; - const expr = this.parseExpression(); + if (!expr) expr = this.parseExpression(); // rewrite `x = val` and `x: type = val` if (this.hasPlugin("lightscript") && this.isColonConstAssign(expr)) { @@ -238,6 +265,8 @@ pp.parseDoStatement = function (node) { isWhiteBlock = true; indentLevel = this.state.indentLevel; } + + this.state.nextBraceIsBlock = true; node.body = this.parseStatement(false); this.state.labels.pop(); if (this.hasPlugin("lightscript") && isWhiteBlock && this.state.indentLevel !== indentLevel) { @@ -530,6 +559,7 @@ pp.parseWhileStatement = function (node) { this.next(); node.test = this.parseParenExpression(); this.state.labels.push(loopLabel); + this.state.nextBraceIsBlock = true; node.body = this.parseStatement(false); this.state.labels.pop(); return this.finishNode(node, "WhileStatement"); @@ -673,6 +703,7 @@ pp.parseFor = function (node, init) { this.expect(tt.parenR); } + this.state.nextBraceIsBlock = true; node.body = this.parseStatement(false); this.state.labels.pop(); return this.finishNode(node, "ForStatement"); @@ -699,6 +730,7 @@ pp.parseForIn = function (node, init, forAwait) { this.expect(tt.parenR); } + this.state.nextBraceIsBlock = true; node.body = this.parseStatement(false); this.state.labels.pop(); return this.finishNode(node, type); diff --git a/src/plugins/lightscript.js b/src/plugins/lightscript.js index 9a61cea3b8..aae45f8d83 100644 --- a/src/plugins/lightscript.js +++ b/src/plugins/lightscript.js @@ -96,6 +96,7 @@ pp.parseEnhancedForIn = function (node) { const iterable = this.parseMaybeAssign(true); this.expectParenFreeBlockStart(node); + this.state.nextBraceIsBlock = true; node.body = this.parseStatement(false); if ((matchingIterationType === "idx") || (matchingIterationType === "elem")) { @@ -460,6 +461,7 @@ pp.parseIf = function (node, isExpression, requireColon = null) { this.state.inFunction = oldInFunction; this.state.labels = oldLabels; } else { + this.state.nextBraceIsBlock = true; node.consequent = this.parseStatement(false); } @@ -510,6 +512,7 @@ pp.parseIfAlternate = function (node, isExpression, ifIsWhiteBlock, ifIndentLeve } } + this.state.nextBraceIsBlock = true; return this.parseStatement(false); } @@ -689,6 +692,7 @@ export default function (instance) { instance.extend("parseStatement", function (inner) { return function () { if (this.match(tt.colon)) { + delete this.state.nextBraceIsBlock; return this.parseWhiteBlock(); } return inner.apply(this, arguments); diff --git a/test/fixtures/core/categorized/label-kind-switch/options.lightscript.json b/test/fixtures/core/categorized/label-kind-switch/options.lightscript.json deleted file mode 100644 index 43de8d051d..0000000000 --- a/test/fixtures/core/categorized/label-kind-switch/options.lightscript.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (2:5)" -} \ No newline at end of file diff --git a/test/fixtures/core/uncategorised/214/options.lightscript.json b/test/fixtures/core/uncategorised/214/options.lightscript.json deleted file mode 100644 index 779ebfe878..0000000000 --- a/test/fixtures/core/uncategorised/214/options.lightscript.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token, expected { (1:10)" -} \ No newline at end of file diff --git a/test/fixtures/core/uncategorised/235/options.lightscript.json b/test/fixtures/core/uncategorised/235/options.lightscript.json deleted file mode 100644 index 78b21c5363..0000000000 --- a/test/fixtures/core/uncategorised/235/options.lightscript.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token, expected , (1:5)" -} \ No newline at end of file diff --git a/test/fixtures/core/uncategorised/300/options.lightscript.json b/test/fixtures/core/uncategorised/300/options.lightscript.json deleted file mode 100644 index 0361d7c7d2..0000000000 --- a/test/fixtures/core/uncategorised/300/options.lightscript.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (2:0)" -} \ No newline at end of file diff --git a/test/fixtures/core/uncategorised/301/options.lightscript.json b/test/fixtures/core/uncategorised/301/options.lightscript.json deleted file mode 100644 index 0361d7c7d2..0000000000 --- a/test/fixtures/core/uncategorised/301/options.lightscript.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (2:0)" -} \ No newline at end of file diff --git a/test/fixtures/core/uncategorised/303/options.lightscript.json b/test/fixtures/core/uncategorised/303/options.lightscript.json deleted file mode 100644 index 5a91ab8f84..0000000000 --- a/test/fixtures/core/uncategorised/303/options.lightscript.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token, expected , (1:6)" -} \ No newline at end of file diff --git a/test/fixtures/core/uncategorised/313/options.lightscript.json b/test/fixtures/core/uncategorised/313/options.lightscript.json deleted file mode 100644 index 930a14478b..0000000000 --- a/test/fixtures/core/uncategorised/313/options.lightscript.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token, expected , (1:8)" -} \ No newline at end of file diff --git a/test/fixtures/core/uncategorised/314/options.lightscript.json b/test/fixtures/core/uncategorised/314/options.lightscript.json deleted file mode 100644 index 930a14478b..0000000000 --- a/test/fixtures/core/uncategorised/314/options.lightscript.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token, expected , (1:8)" -} \ No newline at end of file diff --git a/test/fixtures/core/uncategorised/315/options.lightscript.json b/test/fixtures/core/uncategorised/315/options.lightscript.json deleted file mode 100644 index 930a14478b..0000000000 --- a/test/fixtures/core/uncategorised/315/options.lightscript.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token, expected , (1:8)" -} \ No newline at end of file diff --git a/test/fixtures/core/uncategorised/332/options.lightscript.json b/test/fixtures/core/uncategorised/332/options.lightscript.json deleted file mode 100644 index 04b967a2ee..0000000000 --- a/test/fixtures/core/uncategorised/332/options.lightscript.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (1:1)" -} \ No newline at end of file diff --git a/test/fixtures/core/uncategorised/336/options.lightscript.json b/test/fixtures/core/uncategorised/336/options.lightscript.json deleted file mode 100644 index 9f7910a413..0000000000 --- a/test/fixtures/core/uncategorised/336/options.lightscript.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (1:4)" -} \ No newline at end of file diff --git a/test/fixtures/esprima/automatic-semicolon-insertion/migrated_0000/options.lightscript.json b/test/fixtures/esprima/automatic-semicolon-insertion/migrated_0000/options.lightscript.json deleted file mode 100644 index 0361d7c7d2..0000000000 --- a/test/fixtures/esprima/automatic-semicolon-insertion/migrated_0000/options.lightscript.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (2:0)" -} \ No newline at end of file diff --git a/test/fixtures/esprima/automatic-semicolon-insertion/migrated_0001/options.lightscript.json b/test/fixtures/esprima/automatic-semicolon-insertion/migrated_0001/options.lightscript.json deleted file mode 100644 index 0361d7c7d2..0000000000 --- a/test/fixtures/esprima/automatic-semicolon-insertion/migrated_0001/options.lightscript.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (2:0)" -} \ No newline at end of file diff --git a/test/fixtures/esprima/automatic-semicolon-insertion/migrated_0003/options.lightscript.json b/test/fixtures/esprima/automatic-semicolon-insertion/migrated_0003/options.lightscript.json deleted file mode 100644 index 5a91ab8f84..0000000000 --- a/test/fixtures/esprima/automatic-semicolon-insertion/migrated_0003/options.lightscript.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token, expected , (1:6)" -} \ No newline at end of file diff --git a/test/fixtures/esprima/automatic-semicolon-insertion/migrated_0013/options.lightscript.json b/test/fixtures/esprima/automatic-semicolon-insertion/migrated_0013/options.lightscript.json deleted file mode 100644 index 930a14478b..0000000000 --- a/test/fixtures/esprima/automatic-semicolon-insertion/migrated_0013/options.lightscript.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token, expected , (1:8)" -} \ No newline at end of file diff --git a/test/fixtures/esprima/automatic-semicolon-insertion/migrated_0014/options.lightscript.json b/test/fixtures/esprima/automatic-semicolon-insertion/migrated_0014/options.lightscript.json deleted file mode 100644 index 930a14478b..0000000000 --- a/test/fixtures/esprima/automatic-semicolon-insertion/migrated_0014/options.lightscript.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token, expected , (1:8)" -} \ No newline at end of file diff --git a/test/fixtures/esprima/automatic-semicolon-insertion/migrated_0015/options.lightscript.json b/test/fixtures/esprima/automatic-semicolon-insertion/migrated_0015/options.lightscript.json deleted file mode 100644 index 930a14478b..0000000000 --- a/test/fixtures/esprima/automatic-semicolon-insertion/migrated_0015/options.lightscript.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token, expected , (1:8)" -} \ No newline at end of file diff --git a/test/fixtures/esprima/declaration-const/migrated_0001/options.lightscript.json b/test/fixtures/esprima/declaration-const/migrated_0001/options.lightscript.json deleted file mode 100644 index 930a14478b..0000000000 --- a/test/fixtures/esprima/declaration-const/migrated_0001/options.lightscript.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token, expected , (1:8)" -} \ No newline at end of file diff --git a/test/fixtures/esprima/declaration-const/migrated_0002/options.lightscript.json b/test/fixtures/esprima/declaration-const/migrated_0002/options.lightscript.json deleted file mode 100644 index 930a14478b..0000000000 --- a/test/fixtures/esprima/declaration-const/migrated_0002/options.lightscript.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token, expected , (1:8)" -} \ No newline at end of file diff --git a/test/fixtures/esprima/declaration-let/migrated_0001/options.lightscript.json b/test/fixtures/esprima/declaration-let/migrated_0001/options.lightscript.json deleted file mode 100644 index 5a91ab8f84..0000000000 --- a/test/fixtures/esprima/declaration-let/migrated_0001/options.lightscript.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token, expected , (1:6)" -} \ No newline at end of file diff --git a/test/fixtures/esprima/declaration-let/migrated_0002/options.lightscript.json b/test/fixtures/esprima/declaration-let/migrated_0002/options.lightscript.json deleted file mode 100644 index 5a91ab8f84..0000000000 --- a/test/fixtures/esprima/declaration-let/migrated_0002/options.lightscript.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token, expected , (1:6)" -} \ No newline at end of file diff --git a/test/fixtures/esprima/declaration-let/migrated_0003/options.lightscript.json b/test/fixtures/esprima/declaration-let/migrated_0003/options.lightscript.json deleted file mode 100644 index 5a91ab8f84..0000000000 --- a/test/fixtures/esprima/declaration-let/migrated_0003/options.lightscript.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token, expected , (1:6)" -} \ No newline at end of file diff --git a/test/fixtures/esprima/invalid-syntax/migrated_0255/options.lightscript.json b/test/fixtures/esprima/invalid-syntax/migrated_0255/options.lightscript.json deleted file mode 100644 index e68fbb6aec..0000000000 --- a/test/fixtures/esprima/invalid-syntax/migrated_0255/options.lightscript.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (1:2)" -} \ No newline at end of file diff --git a/test/fixtures/esprima/statement-block/migrated_0001/options.lightscript.json b/test/fixtures/esprima/statement-block/migrated_0001/options.lightscript.json deleted file mode 100644 index 678798b61e..0000000000 --- a/test/fixtures/esprima/statement-block/migrated_0001/options.lightscript.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token, expected { (1:10)" -} diff --git a/test/fixtures/esprima/statement-iteration/migrated_0003/options.lightscript.json b/test/fixtures/esprima/statement-iteration/migrated_0003/options.lightscript.json index 2d4f18af3e..bdd84a6c76 100644 --- a/test/fixtures/esprima/statement-iteration/migrated_0003/options.lightscript.json +++ b/test/fixtures/esprima/statement-iteration/migrated_0003/options.lightscript.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token, expected , (1:5)" + "throws": "Unexpected token, expected ; (1:23)" } diff --git a/test/fixtures/lightscript/auto-const/not-newline-object-malformed-unfortunate/expected.json b/test/fixtures/lightscript/auto-const/not-newline-object-malformed-unfortunate/expected.json new file mode 100644 index 0000000000..e060b1e68f --- /dev/null +++ b/test/fixtures/lightscript/auto-const/not-newline-object-malformed-unfortunate/expected.json @@ -0,0 +1,245 @@ +{ + "type": "File", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 2, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 2 + } + }, + "expression": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + { + "type": "VariableDeclaration", + "start": 3, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "kind": "const", + "extra": { + "implicit": true + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 3, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "id": { + "type": "ObjectPattern", + "start": 3, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 4, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 4, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "a" + }, + "name": "a" + }, + "value": { + "type": "Identifier", + "start": 4, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "a" + }, + "name": "a" + }, + "extra": { + "shorthand": true + } + }, + { + "type": "ObjectProperty", + "start": 7, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 7, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + }, + "identifierName": "b" + }, + "name": "b" + }, + "value": { + "type": "Identifier", + "start": 7, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + }, + "identifierName": "b" + }, + "name": "b" + }, + "extra": { + "shorthand": true + } + } + ] + }, + "init": { + "type": "ObjectExpression", + "start": 12, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "properties": [] + } + } + ] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/auto-const/not-newline-object-malformed-unfortunate/options.json b/test/fixtures/lightscript/auto-const/not-newline-object-malformed-unfortunate/options.json index ec40224464..ddde482277 100644 --- a/test/fixtures/lightscript/auto-const/not-newline-object-malformed-unfortunate/options.json +++ b/test/fixtures/lightscript/auto-const/not-newline-object-malformed-unfortunate/options.json @@ -1,8 +1,5 @@ { "alternatives": { - "all": { - "throws": "Unexpected token (1:5)" - }, "noSeqExprParens": { "allPlugins": true, "excludePlugins": ["existentialExpression", "safeCallExpression", "splatComprehension", "seqExprRequiresParen", "bangCall", "whiteblockOnly", "whiteblockPreferred"], diff --git a/test/fixtures/lightscript/blocks/anonymous-blocks-no-semi/actual.js b/test/fixtures/lightscript/blocks/anonymous-blocks-no-semi/actual.js new file mode 100644 index 0000000000..ed5e62d6fe --- /dev/null +++ b/test/fixtures/lightscript/blocks/anonymous-blocks-no-semi/actual.js @@ -0,0 +1,6 @@ +fn() -> + a = 1 + { + a = 2 + } + a diff --git a/test/fixtures/lightscript/blocks/anonymous-blocks-no-semi/expected.json b/test/fixtures/lightscript/blocks/anonymous-blocks-no-semi/expected.json new file mode 100644 index 0000000000..3edda41ae2 --- /dev/null +++ b/test/fixtures/lightscript/blocks/anonymous-blocks-no-semi/expected.json @@ -0,0 +1,291 @@ +{ + "type": "File", + "start": 0, + "end": 37, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 37, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "sourceType": "script", + "body": [ + { + "type": "NamedArrowDeclaration", + "start": 0, + "end": 37, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "id": { + "type": "Identifier", + "start": 0, + "end": 2, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 2 + }, + "identifierName": "fn" + }, + "name": "fn" + }, + "generator": false, + "expression": false, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "BlockStatement", + "start": 5, + "end": 37, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "body": [ + { + "type": "VariableDeclaration", + "start": 10, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "kind": "const", + "extra": { + "implicit": true + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 10, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "id": { + "type": "Identifier", + "start": 10, + "end": 11, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + }, + "identifierName": "a" + }, + "name": "a" + }, + "init": { + "type": "NumericLiteral", + "start": 14, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + ] + }, + { + "type": "BlockStatement", + "start": 18, + "end": 33, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 5, + "column": 3 + } + }, + "body": [ + { + "type": "VariableDeclaration", + "start": 24, + "end": 29, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 9 + } + }, + "kind": "const", + "extra": { + "implicit": true + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 24, + "end": 29, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 9 + } + }, + "id": { + "type": "Identifier", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 5 + }, + "identifierName": "a" + }, + "name": "a" + }, + "init": { + "type": "NumericLiteral", + "start": 28, + "end": 29, + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 9 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + } + ] + } + ], + "directives": [], + "extra": { + "curly": true + } + }, + { + "type": "ExpressionStatement", + "start": 36, + "end": 37, + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "expression": { + "type": "Identifier", + "start": 36, + "end": 37, + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 3 + }, + "identifierName": "a" + }, + "name": "a" + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/blocks/broken-curly-blocks/expected.json b/test/fixtures/lightscript/blocks/broken-curly-blocks/expected.json new file mode 100644 index 0000000000..a843df051e --- /dev/null +++ b/test/fixtures/lightscript/blocks/broken-curly-blocks/expected.json @@ -0,0 +1,159 @@ +{ + "type": "File", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "body": [ + { + "type": "IfStatement", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "test": { + "type": "BooleanLiteral", + "start": 4, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "value": true, + "extra": {} + }, + "consequent": { + "type": "BlockStatement", + "start": 10, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 14, + "end": 19, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 7 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 14, + "end": 19, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 7 + } + }, + "left": { + "type": "NumericLiteral", + "start": 14, + "end": 15, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 3 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + }, + "operator": "+", + "right": { + "type": "NumericLiteral", + "start": 18, + "end": 19, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 7 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + } + ], + "directives": [], + "extra": { + "curly": true + } + }, + "alternate": null + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/blocks/broken-curly-blocks/options.json b/test/fixtures/lightscript/blocks/broken-curly-blocks/options.json deleted file mode 100644 index 951efd6fb4..0000000000 --- a/test/fixtures/lightscript/blocks/broken-curly-blocks/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (3:4)" -} diff --git a/test/fixtures/lightscript/object-block-ambiguity/semi-assignment-pattern/actual.js b/test/fixtures/lightscript/object-block-ambiguity/semi-assignment-pattern/actual.js new file mode 100644 index 0000000000..09f6a16f5c --- /dev/null +++ b/test/fixtures/lightscript/object-block-ambiguity/semi-assignment-pattern/actual.js @@ -0,0 +1 @@ +a; { b } = c diff --git a/test/fixtures/lightscript/object-block-ambiguity/semi-assignment-pattern/expected.json b/test/fixtures/lightscript/object-block-ambiguity/semi-assignment-pattern/expected.json new file mode 100644 index 0000000000..b279456b0e --- /dev/null +++ b/test/fixtures/lightscript/object-block-ambiguity/semi-assignment-pattern/expected.json @@ -0,0 +1,191 @@ +{ + "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": "ExpressionStatement", + "start": 0, + "end": 2, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 2 + } + }, + "expression": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "a" + }, + "name": "a" + } + }, + { + "type": "VariableDeclaration", + "start": 3, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "kind": "const", + "extra": { + "implicit": true + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 3, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "id": { + "type": "ObjectPattern", + "start": 3, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 5, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 5, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + }, + "identifierName": "b" + }, + "name": "b" + }, + "value": { + "type": "Identifier", + "start": 5, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + }, + "identifierName": "b" + }, + "name": "b" + }, + "extra": { + "shorthand": true + } + } + ] + }, + "init": { + "type": "Identifier", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "c" + }, + "name": "c" + } + } + ] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/object-block-ambiguity/semi-assignment-pattern/expected.whiteblockOnly.json b/test/fixtures/lightscript/object-block-ambiguity/semi-assignment-pattern/expected.whiteblockOnly.json new file mode 100644 index 0000000000..b279456b0e --- /dev/null +++ b/test/fixtures/lightscript/object-block-ambiguity/semi-assignment-pattern/expected.whiteblockOnly.json @@ -0,0 +1,191 @@ +{ + "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": "ExpressionStatement", + "start": 0, + "end": 2, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 2 + } + }, + "expression": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "a" + }, + "name": "a" + } + }, + { + "type": "VariableDeclaration", + "start": 3, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "kind": "const", + "extra": { + "implicit": true + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 3, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "id": { + "type": "ObjectPattern", + "start": 3, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 5, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 5, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + }, + "identifierName": "b" + }, + "name": "b" + }, + "value": { + "type": "Identifier", + "start": 5, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + }, + "identifierName": "b" + }, + "name": "b" + }, + "extra": { + "shorthand": true + } + } + ] + }, + "init": { + "type": "Identifier", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "c" + }, + "name": "c" + } + } + ] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/object-block-ambiguity/semi-assignment-pattern/options.json b/test/fixtures/lightscript/object-block-ambiguity/semi-assignment-pattern/options.json new file mode 100644 index 0000000000..fdc47aacf1 --- /dev/null +++ b/test/fixtures/lightscript/object-block-ambiguity/semi-assignment-pattern/options.json @@ -0,0 +1,7 @@ +{ + "alternatives": { + "braceblock": { + "throws": "Unexpected token (1:9)" + } + } +}