diff --git a/src/parser/expression.js b/src/parser/expression.js index 1c075315f2..f55c378fbd 100644 --- a/src/parser/expression.js +++ b/src/parser/expression.js @@ -239,11 +239,14 @@ pp.parseExprOps = function (noIn, refShorthandDefaultPos) { pp.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, noIn) { // correct ASI failures. if (this.hasPlugin("lightscript") && this.isLineBreak()) { - // if it's a newline followed by a unary +/-, bail so it can be parsed separately. if (this.match(tt.plusMin) && !this.isNextCharWhitespace()) { return left; } + // for match/case + if (this.match(tt.bitwiseOR)) { + return left; + } } if (this.hasPlugin("lightscript") && this.isBitwiseOp()) { @@ -716,6 +719,12 @@ pp.parseExprAtom = function (refShorthandDefaultPos) { return this.parseIfExpression(node); } + case tt._match: + if (this.hasPlugin("lightscript")) { + node = this.startNode(); + return this.parseMatchExpression(node); + } + case tt.arrow: if (this.hasPlugin("lightscript")) { node = this.startNode(); @@ -1151,6 +1160,9 @@ pp.parsePropertyName = function (prop) { // Initialize empty function node. pp.initFunction = function (node, isAsync) { + if (this.hasPlugin("lightscript") && this.state.inMatchCaseTest) { + this.unexpected(node.start, "Cannot match on functions."); + } node.id = null; node.generator = false; node.expression = false; diff --git a/src/parser/statement.js b/src/parser/statement.js index bd795c95a8..840ec217eb 100644 --- a/src/parser/statement.js +++ b/src/parser/statement.js @@ -116,6 +116,9 @@ pp.parseStatement = function (declaration, topLevel) { } return starttype === tt._import ? this.parseImport(node) : this.parseExport(node); + case tt._match: + if (this.hasPlugin("lightscript")) return this.parseMatchStatement(node); + case tt.name: if (this.state.value === "async") { // peek ahead and see if next token is a function diff --git a/src/plugins/jsx/index.js b/src/plugins/jsx/index.js index de13289e38..dd620edac1 100644 --- a/src/plugins/jsx/index.js +++ b/src/plugins/jsx/index.js @@ -434,6 +434,11 @@ export default function(instance) { return function(code) { if (this.state.inPropertyName) return inner.call(this, code); + // don't allow jsx inside match case tests + if (this.hasPlugin("lightscript") && this.state.inMatchCaseTest) { + return inner.call(this, code); + } + const context = this.curContext(); if (this.hasPlugin("lightscript") && code === 60) { diff --git a/src/plugins/lightscript.js b/src/plugins/lightscript.js index 521183172f..13b0e39955 100644 --- a/src/plugins/lightscript.js +++ b/src/plugins/lightscript.js @@ -111,9 +111,10 @@ pp.expectParenFreeBlockStart = function (node) { // if true: blah // if true { blah } // if (true) blah + // match (foo) as bar: if (node && node.extra && node.extra.hasParens) { this.expect(tt.parenR); - } else if (!(this.match(tt.colon) || this.match(tt.braceL))) { + } else if (!(this.match(tt.colon) || this.match(tt.braceL) || this.isContextual("as"))) { this.unexpected(null, "Paren-free test expressions must be followed by braces or a colon."); } }; @@ -550,6 +551,112 @@ pp.isBitwiseOp = function () { ); }; +pp.parseMatchExpression = function (node) { + return this.parseMatch(node, true); +}; + +pp.parseMatchStatement = function (node) { + return this.parseMatch(node, false); +}; + +pp.parseMatch = function (node, isExpression) { + if (this.state.inMatchCaseTest) this.unexpected(); + this.expect(tt._match); + + node.discriminant = this.parseParenExpression(); + if (this.eatContextual("as")) { + node.alias = this.parseIdentifier(); + } + + const isColon = this.match(tt.colon); + let isEnd; + if (isColon) { + const indentLevel = this.state.indentLevel; + this.next(); + isEnd = () => this.state.indentLevel <= indentLevel || this.match(tt.eof); + } else { + this.expect(tt.braceL); + isEnd = () => this.eat(tt.braceR); + } + + node.cases = []; + const caseIndentLevel = this.state.indentLevel; + let hasUsedElse = false; + while (!isEnd()) { + if (hasUsedElse) { + this.unexpected(null, "`else` must be last case."); + } + if (isColon && this.state.indentLevel !== caseIndentLevel) { + this.unexpected(null, "Mismatched indent."); + } + + const matchCase = this.parseMatchCase(isExpression); + if (matchCase.test && matchCase.test.type === "MatchElse") { + hasUsedElse = true; + } + node.cases.push(matchCase); + } + + if (!node.cases.length) { + this.unexpected(null, tt.bitwiseOR); + } + + return this.finishNode(node, isExpression ? "MatchExpression" : "MatchStatement"); +}; + +pp.parseMatchCase = function (isExpression) { + const node = this.startNode(); + + this.parseMatchCaseTest(node); + + if (isExpression) { + // disallow return/continue/break, etc. c/p doExpression + const oldInFunction = this.state.inFunction; + const oldLabels = this.state.labels; + this.state.labels = []; + this.state.inFunction = false; + + node.consequent = this.parseBlock(false); + + this.state.inFunction = oldInFunction; + this.state.labels = oldLabels; + } else { + node.consequent = this.parseBlock(false); + } + + return this.finishNode(node, "MatchCase"); +}; + +pp.parseMatchCaseTest = function (node) { + // can't be nested so no need to read/restore old value + this.state.inMatchCaseTest = true; + + this.expect(tt.bitwiseOR); + if (this.isLineBreak()) this.unexpected(this.state.lastTokEnd, "Illegal newline."); + + if (this.match(tt._else)) { + const elseNode = this.startNode(); + this.next(); + node.test = this.finishNode(elseNode, "MatchElse"); + } else if (this.eat(tt._with)) { + this.parseMatchCaseBinding(node); + } else { + node.test = this.parseExprOps(); + } + + if (this.eat(tt._with)) { + this.parseMatchCaseBinding(node); + } + + this.state.inMatchCaseTest = false; +}; + +pp.parseMatchCaseBinding = function (node) { + if (node.binding) this.unexpected(this.state.lastTokStart, "Cannot destructure twice."); + if (!(this.match(tt.braceL) || this.match(tt.bracketL))) this.unexpected(); + node.binding = this.parseBindingAtom(); +}; + export default function (instance) { @@ -568,7 +675,8 @@ export default function (instance) { // first, try paren-free style try { const val = this.parseExpression(); - if (this.match(tt.braceL) || this.match(tt.colon)) { + // "as" for `match (foo) as bar:`, bit dirty to allow for all but not a problem + if (this.match(tt.braceL) || this.match(tt.colon) || this.isContextual("as")) { if (val.extra && val.extra.parenthesized) { delete val.extra.parenthesized; delete val.extra.parenStart; diff --git a/src/tokenizer/state.js b/src/tokenizer/state.js index e69f12055f..9e19e9f21c 100644 --- a/src/tokenizer/state.js +++ b/src/tokenizer/state.js @@ -38,7 +38,9 @@ export default class State { this.pos = this.lineStart = 0; this.curLine = options.startLine; + // for lightscript this.indentLevel = 0; + this.inMatchCaseTest = false; this.type = tt.eof; this.value = null; diff --git a/src/tokenizer/types.js b/src/tokenizer/types.js index 8e0d0a3807..af32a0f747 100644 --- a/src/tokenizer/types.js +++ b/src/tokenizer/types.js @@ -127,6 +127,7 @@ export const keywords = { "or": types.logicalOR, "and": types.logicalAND, "not": new KeywordTokenType("not", { beforeExpr, prefix, startsExpr }), + "match": new KeywordTokenType("match", { beforeExpr, startsExpr }), "break": new KeywordTokenType("break"), "case": new KeywordTokenType("case", { beforeExpr }), diff --git a/src/util/identifier.js b/src/util/identifier.js index 25bbc28d50..704efe54b1 100644 --- a/src/util/identifier.js +++ b/src/util/identifier.js @@ -26,7 +26,7 @@ export const reservedWords = { // And the keywords -export const isKeyword = makePredicate("break case catch continue debugger default do else finally for function if return switch throw try var while with null true false instanceof typeof void delete new in this let const class extends export import yield super or and not elif now"); +export const isKeyword = makePredicate("break case catch continue debugger default do else finally for function if return switch throw try var while with null true false instanceof typeof void delete new in this let const class extends export import yield super or and not elif now match"); // ## Character categories diff --git a/test/fixtures/lightscript/commaless/obj-pattern/actual.js b/test/fixtures/lightscript/commaless/obj-pattern/actual.js index 2fecf2a794..c03b9a709b 100644 --- a/test/fixtures/lightscript/commaless/obj-pattern/actual.js +++ b/test/fixtures/lightscript/commaless/obj-pattern/actual.js @@ -2,7 +2,9 @@ a b: { c - d + d = 1 + e } - e -} = f + f + ...g +} = h diff --git a/test/fixtures/lightscript/commaless/obj-pattern/expected.json b/test/fixtures/lightscript/commaless/obj-pattern/expected.json index 628943a027..2f4e4e5e68 100644 --- a/test/fixtures/lightscript/commaless/obj-pattern/expected.json +++ b/test/fixtures/lightscript/commaless/obj-pattern/expected.json @@ -1,28 +1,28 @@ { "type": "File", "start": 0, - "end": 38, + "end": 55, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 8, + "line": 10, "column": 5 } }, "program": { "type": "Program", "start": 0, - "end": 38, + "end": 55, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 8, + "line": 10, "column": 5 } }, @@ -31,14 +31,14 @@ { "type": "VariableDeclaration", "start": 0, - "end": 38, + "end": 55, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 8, + "line": 10, "column": 5 } }, @@ -50,28 +50,28 @@ { "type": "VariableDeclarator", "start": 0, - "end": 38, + "end": 55, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 8, + "line": 10, "column": 5 } }, "id": { "type": "ObjectPattern", "start": 0, - "end": 34, + "end": 51, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 8, + "line": 10, "column": 1 } }, @@ -134,14 +134,14 @@ { "type": "ObjectProperty", "start": 8, - "end": 28, + "end": 38, "loc": { "start": { "line": 3, "column": 2 }, "end": { - "line": 6, + "line": 7, "column": 3 } }, @@ -168,14 +168,14 @@ "value": { "type": "ObjectPattern", "start": 11, - "end": 28, + "end": 38, "loc": { "start": { "line": 3, "column": 5 }, "end": { - "line": 6, + "line": 7, "column": 3 } }, @@ -238,7 +238,7 @@ { "type": "ObjectProperty", "start": 23, - "end": 24, + "end": 28, "loc": { "start": { "line": 5, @@ -246,7 +246,7 @@ }, "end": { "line": 5, - "column": 5 + "column": 9 } }, "method": false, @@ -270,9 +270,9 @@ "name": "d" }, "value": { - "type": "Identifier", + "type": "AssignmentPattern", "start": 23, - "end": 24, + "end": 28, "loc": { "start": { "line": 5, @@ -280,11 +280,101 @@ }, "end": { "line": 5, + "column": 9 + } + }, + "left": { + "type": "Identifier", + "start": 23, + "end": 24, + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 5 + }, + "identifierName": "d" + }, + "name": "d" + }, + "right": { + "type": "NumericLiteral", + "start": 27, + "end": 28, + "loc": { + "start": { + "line": 5, + "column": 8 + }, + "end": { + "line": 5, + "column": 9 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + }, + "extra": { + "shorthand": true + } + }, + { + "type": "ObjectProperty", + "start": 33, + "end": 34, + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 5 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 33, + "end": 34, + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, "column": 5 }, - "identifierName": "d" + "identifierName": "e" }, - "name": "d" + "name": "e" + }, + "value": { + "type": "Identifier", + "start": 33, + "end": 34, + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 5 + }, + "identifierName": "e" + }, + "name": "e" }, "extra": { "shorthand": true @@ -295,15 +385,15 @@ }, { "type": "ObjectProperty", - "start": 31, - "end": 32, + "start": 41, + "end": 42, "loc": { "start": { - "line": 7, + "line": 8, "column": 2 }, "end": { - "line": 7, + "line": 8, "column": 3 } }, @@ -312,60 +402,92 @@ "computed": false, "key": { "type": "Identifier", - "start": 31, - "end": 32, + "start": 41, + "end": 42, "loc": { "start": { - "line": 7, + "line": 8, "column": 2 }, "end": { - "line": 7, + "line": 8, "column": 3 }, - "identifierName": "e" + "identifierName": "f" }, - "name": "e" + "name": "f" }, "value": { "type": "Identifier", - "start": 31, - "end": 32, + "start": 41, + "end": 42, "loc": { "start": { - "line": 7, + "line": 8, "column": 2 }, "end": { - "line": 7, + "line": 8, "column": 3 }, - "identifierName": "e" + "identifierName": "f" }, - "name": "e" + "name": "f" }, "extra": { "shorthand": true } + }, + { + "type": "RestProperty", + "start": 45, + "end": 49, + "loc": { + "start": { + "line": 9, + "column": 2 + }, + "end": { + "line": 9, + "column": 6 + } + }, + "argument": { + "type": "Identifier", + "start": 48, + "end": 49, + "loc": { + "start": { + "line": 9, + "column": 5 + }, + "end": { + "line": 9, + "column": 6 + }, + "identifierName": "g" + }, + "name": "g" + } } ] }, "init": { "type": "Identifier", - "start": 37, - "end": 38, + "start": 54, + "end": 55, "loc": { "start": { - "line": 8, + "line": 10, "column": 4 }, "end": { - "line": 8, + "line": 10, "column": 5 }, - "identifierName": "f" + "identifierName": "h" }, - "name": "f" + "name": "h" } } ] diff --git a/test/fixtures/lightscript/commaless/obj-pattern/options.json b/test/fixtures/lightscript/commaless/obj-pattern/options.json new file mode 100644 index 0000000000..3ebf2619d6 --- /dev/null +++ b/test/fixtures/lightscript/commaless/obj-pattern/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["objectRestSpread", "lightscript", "jsx", "flow"] +} diff --git a/test/fixtures/lightscript/match/as-parens/actual.js b/test/fixtures/lightscript/match/as-parens/actual.js new file mode 100644 index 0000000000..e8e0c5011b --- /dev/null +++ b/test/fixtures/lightscript/match/as-parens/actual.js @@ -0,0 +1,2 @@ +match (x) as foo: + | foo.bar: foo + 1 diff --git a/test/fixtures/lightscript/match/as-parens/expected.json b/test/fixtures/lightscript/match/as-parens/expected.json new file mode 100644 index 0000000000..fd9037df26 --- /dev/null +++ b/test/fixtures/lightscript/match/as-parens/expected.json @@ -0,0 +1,219 @@ +{ + "type": "File", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "sourceType": "script", + "body": [ + { + "type": "MatchStatement", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "discriminant": { + "type": "Identifier", + "start": 7, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + }, + "identifierName": "x" + }, + "name": "x", + "extra": {} + }, + "alias": { + "type": "Identifier", + "start": 13, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 16 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "cases": [ + { + "type": "MatchCase", + "start": 20, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "test": { + "type": "MemberExpression", + "start": 22, + "end": 29, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "object": { + "type": "Identifier", + "start": 22, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 7 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "property": { + "type": "Identifier", + "start": 26, + "end": 29, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 11 + }, + "identifierName": "bar" + }, + "name": "bar" + }, + "computed": false + }, + "consequent": { + "type": "ExpressionStatement", + "start": 31, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 31, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "left": { + "type": "Identifier", + "start": 31, + "end": 34, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 16 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "operator": "+", + "right": { + "type": "NumericLiteral", + "start": 37, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + } + } + ] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/match/as/actual.js b/test/fixtures/lightscript/match/as/actual.js new file mode 100644 index 0000000000..ca74537788 --- /dev/null +++ b/test/fixtures/lightscript/match/as/actual.js @@ -0,0 +1,2 @@ +match x as foo: + | foo.bar: foo + 1 diff --git a/test/fixtures/lightscript/match/as/expected.json b/test/fixtures/lightscript/match/as/expected.json new file mode 100644 index 0000000000..128055b862 --- /dev/null +++ b/test/fixtures/lightscript/match/as/expected.json @@ -0,0 +1,218 @@ +{ + "type": "File", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "sourceType": "script", + "body": [ + { + "type": "MatchStatement", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "discriminant": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "x" + }, + "name": "x" + }, + "alias": { + "type": "Identifier", + "start": 11, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "cases": [ + { + "type": "MatchCase", + "start": 18, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "test": { + "type": "MemberExpression", + "start": 20, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "object": { + "type": "Identifier", + "start": 20, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 7 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "property": { + "type": "Identifier", + "start": 24, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 11 + }, + "identifierName": "bar" + }, + "name": "bar" + }, + "computed": false + }, + "consequent": { + "type": "ExpressionStatement", + "start": 29, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 29, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "left": { + "type": "Identifier", + "start": 29, + "end": 32, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 16 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "operator": "+", + "right": { + "type": "NumericLiteral", + "start": 35, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + } + } + ] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/match/await/actual.js b/test/fixtures/lightscript/match/await/actual.js new file mode 100644 index 0000000000..7885cf85d0 --- /dev/null +++ b/test/fixtures/lightscript/match/await/actual.js @@ -0,0 +1,6 @@ +f() -/> + <- match x: + | a: 1 + | b: <- z() + | c: + <- z() diff --git a/test/fixtures/lightscript/match/await/expected.json b/test/fixtures/lightscript/match/await/expected.json new file mode 100644 index 0000000000..8fb55a971e --- /dev/null +++ b/test/fixtures/lightscript/match/await/expected.json @@ -0,0 +1,434 @@ +{ + "type": "File", + "start": 0, + "end": 70, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 12 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 70, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 12 + } + }, + "sourceType": "script", + "body": [ + { + "type": "NamedArrowDeclaration", + "start": 0, + "end": 70, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 12 + } + }, + "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": true, + "params": [], + "skinny": true, + "body": { + "type": "BlockStatement", + "start": 4, + "end": 70, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 6, + "column": 12 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 10, + "end": 70, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 6, + "column": 12 + } + }, + "expression": { + "type": "AwaitExpression", + "start": 10, + "end": 70, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 6, + "column": 12 + } + }, + "argument": { + "type": "MatchExpression", + "start": 13, + "end": 70, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 6, + "column": 12 + } + }, + "discriminant": { + "type": "Identifier", + "start": 19, + "end": 20, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 12 + }, + "identifierName": "x" + }, + "name": "x" + }, + "cases": [ + { + "type": "MatchCase", + "start": 26, + "end": 32, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "test": { + "type": "Identifier", + "start": 28, + "end": 29, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 7 + }, + "identifierName": "a" + }, + "name": "a" + }, + "consequent": { + "type": "ExpressionStatement", + "start": 31, + "end": 32, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 31, + "end": 32, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + }, + { + "type": "MatchCase", + "start": 37, + "end": 48, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 15 + } + }, + "test": { + "type": "Identifier", + "start": 39, + "end": 40, + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 7 + }, + "identifierName": "b" + }, + "name": "b" + }, + "consequent": { + "type": "ExpressionStatement", + "start": 42, + "end": 48, + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 4, + "column": 15 + } + }, + "expression": { + "type": "AwaitExpression", + "start": 42, + "end": 48, + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 4, + "column": 15 + } + }, + "argument": { + "type": "CallExpression", + "start": 45, + "end": 48, + "loc": { + "start": { + "line": 4, + "column": 12 + }, + "end": { + "line": 4, + "column": 15 + } + }, + "callee": { + "type": "Identifier", + "start": 45, + "end": 46, + "loc": { + "start": { + "line": 4, + "column": 12 + }, + "end": { + "line": 4, + "column": 13 + }, + "identifierName": "z" + }, + "name": "z" + }, + "arguments": [] + } + } + } + }, + { + "type": "MatchCase", + "start": 53, + "end": 70, + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 6, + "column": 12 + } + }, + "test": { + "type": "Identifier", + "start": 55, + "end": 56, + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 5, + "column": 7 + }, + "identifierName": "c" + }, + "name": "c" + }, + "consequent": { + "type": "BlockStatement", + "start": 56, + "end": 70, + "loc": { + "start": { + "line": 5, + "column": 7 + }, + "end": { + "line": 6, + "column": 12 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 64, + "end": 70, + "loc": { + "start": { + "line": 6, + "column": 6 + }, + "end": { + "line": 6, + "column": 12 + } + }, + "expression": { + "type": "AwaitExpression", + "start": 64, + "end": 70, + "loc": { + "start": { + "line": 6, + "column": 6 + }, + "end": { + "line": 6, + "column": 12 + } + }, + "argument": { + "type": "CallExpression", + "start": 67, + "end": 70, + "loc": { + "start": { + "line": 6, + "column": 9 + }, + "end": { + "line": 6, + "column": 12 + } + }, + "callee": { + "type": "Identifier", + "start": 67, + "end": 68, + "loc": { + "start": { + "line": 6, + "column": 9 + }, + "end": { + "line": 6, + "column": 10 + }, + "identifierName": "z" + }, + "name": "z" + }, + "arguments": [] + } + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + ] + } + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/match/bitwise-or-consequent-inline/actual.js b/test/fixtures/lightscript/match/bitwise-or-consequent-inline/actual.js new file mode 100644 index 0000000000..409f1d0dbf --- /dev/null +++ b/test/fixtures/lightscript/match/bitwise-or-consequent-inline/actual.js @@ -0,0 +1,2 @@ +a = match x: + | 3: x | 1 diff --git a/test/fixtures/lightscript/match/bitwise-or-consequent-inline/options.json b/test/fixtures/lightscript/match/bitwise-or-consequent-inline/options.json new file mode 100644 index 0000000000..3f733ee931 --- /dev/null +++ b/test/fixtures/lightscript/match/bitwise-or-consequent-inline/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Bitwise operators have been disabled in LightScript. Use the stdlib functions instead (eg; `bitwiseAnd(a, b)`). (2:9)" +} diff --git a/test/fixtures/lightscript/match/bitwise-or-consequent-newline-illegal/actual.js b/test/fixtures/lightscript/match/bitwise-or-consequent-newline-illegal/actual.js new file mode 100644 index 0000000000..3574a28285 --- /dev/null +++ b/test/fixtures/lightscript/match/bitwise-or-consequent-newline-illegal/actual.js @@ -0,0 +1,4 @@ +a = match x: + | 3: + x + | 1 diff --git a/test/fixtures/lightscript/match/bitwise-or-consequent-newline-illegal/options.json b/test/fixtures/lightscript/match/bitwise-or-consequent-newline-illegal/options.json new file mode 100644 index 0000000000..dc3c665ff0 --- /dev/null +++ b/test/fixtures/lightscript/match/bitwise-or-consequent-newline-illegal/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token (4:4)" +} diff --git a/test/fixtures/lightscript/match/bitwise-or-test-explicit/actual.js b/test/fixtures/lightscript/match/bitwise-or-test-explicit/actual.js new file mode 100644 index 0000000000..c18bd88ffe --- /dev/null +++ b/test/fixtures/lightscript/match/bitwise-or-test-explicit/actual.js @@ -0,0 +1,2 @@ +a = match x: + | x | 3, -> "bitwise or 3" diff --git a/test/fixtures/lightscript/match/bitwise-or-test-explicit/options.json b/test/fixtures/lightscript/match/bitwise-or-test-explicit/options.json new file mode 100644 index 0000000000..0d6e3333f1 --- /dev/null +++ b/test/fixtures/lightscript/match/bitwise-or-test-explicit/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Bitwise operators have been disabled in LightScript. Use the stdlib functions instead (eg; `bitwiseAnd(a, b)`). (2:6)" +} diff --git a/test/fixtures/lightscript/match/bitwise-or-test-implicit-illegal/actual.js b/test/fixtures/lightscript/match/bitwise-or-test-implicit-illegal/actual.js new file mode 100644 index 0000000000..a87cf5cdde --- /dev/null +++ b/test/fixtures/lightscript/match/bitwise-or-test-implicit-illegal/actual.js @@ -0,0 +1,2 @@ +a = match x: + | | 3, -> "bitwise or 3" diff --git a/test/fixtures/lightscript/match/bitwise-or-test-implicit-illegal/options.json b/test/fixtures/lightscript/match/bitwise-or-test-implicit-illegal/options.json new file mode 100644 index 0000000000..b2f4797ad8 --- /dev/null +++ b/test/fixtures/lightscript/match/bitwise-or-test-implicit-illegal/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token (2:4)" +} diff --git a/test/fixtures/lightscript/match/curlies-parens/actual.js b/test/fixtures/lightscript/match/curlies-parens/actual.js new file mode 100644 index 0000000000..4493dca9ce --- /dev/null +++ b/test/fixtures/lightscript/match/curlies-parens/actual.js @@ -0,0 +1,4 @@ +a = match (x) { +| 2: "eq two" +| else: "some other thing" +} diff --git a/test/fixtures/lightscript/match/curlies-parens/expected.json b/test/fixtures/lightscript/match/curlies-parens/expected.json new file mode 100644 index 0000000000..e8af002e3c --- /dev/null +++ b/test/fixtures/lightscript/match/curlies-parens/expected.json @@ -0,0 +1,257 @@ +{ + "type": "File", + "start": 0, + "end": 58, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 58, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 58, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "kind": "const", + "extra": { + "implicit": true + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 0, + "end": 58, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "a" + }, + "name": "a" + }, + "init": { + "type": "MatchExpression", + "start": 4, + "end": 58, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "discriminant": { + "type": "Identifier", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "x" + }, + "name": "x", + "extra": {} + }, + "cases": [ + { + "type": "MatchCase", + "start": 16, + "end": 29, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "test": { + "type": "NumericLiteral", + "start": 18, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + }, + "consequent": { + "type": "ExpressionStatement", + "start": 21, + "end": 29, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "expression": { + "type": "StringLiteral", + "start": 21, + "end": 29, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "extra": { + "rawValue": "eq two", + "raw": "\"eq two\"" + }, + "value": "eq two" + } + } + }, + { + "type": "MatchCase", + "start": 30, + "end": 56, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 26 + } + }, + "test": { + "type": "MatchElse", + "start": 32, + "end": 36, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 6 + } + } + }, + "consequent": { + "type": "ExpressionStatement", + "start": 38, + "end": 56, + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 26 + } + }, + "expression": { + "type": "StringLiteral", + "start": 38, + "end": 56, + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 26 + } + }, + "extra": { + "rawValue": "some other thing", + "raw": "\"some other thing\"" + }, + "value": "some other thing" + } + } + } + ] + } + } + ] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/match/curlies/actual.js b/test/fixtures/lightscript/match/curlies/actual.js new file mode 100644 index 0000000000..f2b35475f7 --- /dev/null +++ b/test/fixtures/lightscript/match/curlies/actual.js @@ -0,0 +1,4 @@ +a = match x { +| 2: "eq two" +| else: "some other thing" +} diff --git a/test/fixtures/lightscript/match/curlies/expected.json b/test/fixtures/lightscript/match/curlies/expected.json new file mode 100644 index 0000000000..f1139a3a48 --- /dev/null +++ b/test/fixtures/lightscript/match/curlies/expected.json @@ -0,0 +1,256 @@ +{ + "type": "File", + "start": 0, + "end": 56, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 56, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 56, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "kind": "const", + "extra": { + "implicit": true + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 0, + "end": 56, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "a" + }, + "name": "a" + }, + "init": { + "type": "MatchExpression", + "start": 4, + "end": 56, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "discriminant": { + "type": "Identifier", + "start": 10, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + }, + "cases": [ + { + "type": "MatchCase", + "start": 14, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "test": { + "type": "NumericLiteral", + "start": 16, + "end": 17, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + }, + "consequent": { + "type": "ExpressionStatement", + "start": 19, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "expression": { + "type": "StringLiteral", + "start": 19, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "extra": { + "rawValue": "eq two", + "raw": "\"eq two\"" + }, + "value": "eq two" + } + } + }, + { + "type": "MatchCase", + "start": 28, + "end": 54, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 26 + } + }, + "test": { + "type": "MatchElse", + "start": 30, + "end": 34, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 6 + } + } + }, + "consequent": { + "type": "ExpressionStatement", + "start": 36, + "end": 54, + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 26 + } + }, + "expression": { + "type": "StringLiteral", + "start": 36, + "end": 54, + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 26 + } + }, + "extra": { + "rawValue": "some other thing", + "raw": "\"some other thing\"" + }, + "value": "some other thing" + } + } + } + ] + } + } + ] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/match/curly-consequent/actual.js b/test/fixtures/lightscript/match/curly-consequent/actual.js new file mode 100644 index 0000000000..70c9b33348 --- /dev/null +++ b/test/fixtures/lightscript/match/curly-consequent/actual.js @@ -0,0 +1,12 @@ +a = match x: + | y { "y" } + | z { + "z" + } + | a with { b } { + b + b + } + | (c) { + d + } diff --git a/test/fixtures/lightscript/match/curly-consequent/expected.json b/test/fixtures/lightscript/match/curly-consequent/expected.json new file mode 100644 index 0000000000..359b3f2051 --- /dev/null +++ b/test/fixtures/lightscript/match/curly-consequent/expected.json @@ -0,0 +1,575 @@ +{ + "type": "File", + "start": 0, + "end": 101, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 12, + "column": 3 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 101, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 12, + "column": 3 + } + }, + "sourceType": "script", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 101, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 12, + "column": 3 + } + }, + "kind": "const", + "extra": { + "implicit": true + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 0, + "end": 101, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 12, + "column": 3 + } + }, + "id": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "a" + }, + "name": "a" + }, + "init": { + "type": "MatchExpression", + "start": 4, + "end": 101, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 12, + "column": 3 + } + }, + "discriminant": { + "type": "Identifier", + "start": 10, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + }, + "cases": [ + { + "type": "MatchCase", + "start": 15, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "test": { + "type": "Identifier", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + }, + "identifierName": "y" + }, + "name": "y" + }, + "consequent": { + "type": "BlockStatement", + "start": 19, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 21, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "expression": { + "type": "StringLiteral", + "start": 21, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "extra": { + "rawValue": "y", + "raw": "\"y\"" + }, + "value": "y" + } + } + ], + "directives": [], + "extra": { + "curly": true + } + } + }, + { + "type": "MatchCase", + "start": 29, + "end": 46, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 5, + "column": 3 + } + }, + "test": { + "type": "Identifier", + "start": 31, + "end": 32, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 5 + }, + "identifierName": "z" + }, + "name": "z" + }, + "consequent": { + "type": "BlockStatement", + "start": 33, + "end": 46, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 5, + "column": 3 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 39, + "end": 42, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 7 + } + }, + "expression": { + "type": "StringLiteral", + "start": 39, + "end": 42, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 7 + } + }, + "extra": { + "rawValue": "z", + "raw": "\"z\"" + }, + "value": "z" + } + } + ], + "directives": [], + "extra": { + "curly": true + } + } + }, + { + "type": "MatchCase", + "start": 49, + "end": 81, + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 9, + "column": 3 + } + }, + "test": { + "type": "Identifier", + "start": 51, + "end": 52, + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 5 + }, + "identifierName": "a" + }, + "name": "a" + }, + "binding": { + "type": "ObjectPattern", + "start": 58, + "end": 63, + "loc": { + "start": { + "line": 6, + "column": 11 + }, + "end": { + "line": 6, + "column": 16 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 60, + "end": 61, + "loc": { + "start": { + "line": 6, + "column": 13 + }, + "end": { + "line": 6, + "column": 14 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 60, + "end": 61, + "loc": { + "start": { + "line": 6, + "column": 13 + }, + "end": { + "line": 6, + "column": 14 + }, + "identifierName": "b" + }, + "name": "b" + }, + "value": { + "type": "Identifier", + "start": 60, + "end": 61, + "loc": { + "start": { + "line": 6, + "column": 13 + }, + "end": { + "line": 6, + "column": 14 + }, + "identifierName": "b" + }, + "name": "b" + }, + "extra": { + "shorthand": true + } + } + ] + }, + "consequent": { + "type": "BlockStatement", + "start": 64, + "end": 81, + "loc": { + "start": { + "line": 6, + "column": 17 + }, + "end": { + "line": 9, + "column": 3 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 70, + "end": 71, + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 5 + } + }, + "expression": { + "type": "Identifier", + "start": 70, + "end": 71, + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 5 + }, + "identifierName": "b" + }, + "name": "b" + } + }, + { + "type": "ExpressionStatement", + "start": 76, + "end": 77, + "loc": { + "start": { + "line": 8, + "column": 4 + }, + "end": { + "line": 8, + "column": 5 + } + }, + "expression": { + "type": "Identifier", + "start": 76, + "end": 77, + "loc": { + "start": { + "line": 8, + "column": 4 + }, + "end": { + "line": 8, + "column": 5 + }, + "identifierName": "b" + }, + "name": "b" + } + } + ], + "directives": [], + "extra": { + "curly": true + } + } + }, + { + "type": "MatchCase", + "start": 84, + "end": 101, + "loc": { + "start": { + "line": 10, + "column": 2 + }, + "end": { + "line": 12, + "column": 3 + } + }, + "test": { + "type": "Identifier", + "start": 87, + "end": 88, + "loc": { + "start": { + "line": 10, + "column": 5 + }, + "end": { + "line": 10, + "column": 6 + }, + "identifierName": "c" + }, + "name": "c", + "extra": { + "parenthesized": true, + "parenStart": 86 + } + }, + "consequent": { + "type": "BlockStatement", + "start": 90, + "end": 101, + "loc": { + "start": { + "line": 10, + "column": 8 + }, + "end": { + "line": 12, + "column": 3 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 96, + "end": 97, + "loc": { + "start": { + "line": 11, + "column": 4 + }, + "end": { + "line": 11, + "column": 5 + } + }, + "expression": { + "type": "Identifier", + "start": 96, + "end": 97, + "loc": { + "start": { + "line": 11, + "column": 4 + }, + "end": { + "line": 11, + "column": 5 + }, + "identifierName": "d" + }, + "name": "d" + } + } + ], + "directives": [], + "extra": { + "curly": true + } + } + } + ] + } + } + ] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/match/destructured-renaming/actual.js b/test/fixtures/lightscript/match/destructured-renaming/actual.js new file mode 100644 index 0000000000..34f6b78509 --- /dev/null +++ b/test/fixtures/lightscript/match/destructured-renaming/actual.js @@ -0,0 +1,3 @@ +match x: + | x.a with { a, b = 1 }: a + b + | x.0 and x.1 with [ a, b ]: a + b diff --git a/test/fixtures/lightscript/match/destructured-renaming/expected.json b/test/fixtures/lightscript/match/destructured-renaming/expected.json new file mode 100644 index 0000000000..5e790e10bc --- /dev/null +++ b/test/fixtures/lightscript/match/destructured-renaming/expected.json @@ -0,0 +1,613 @@ +{ + "type": "File", + "start": 0, + "end": 78, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 36 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 78, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 36 + } + }, + "sourceType": "script", + "body": [ + { + "type": "MatchStatement", + "start": 0, + "end": 78, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 36 + } + }, + "discriminant": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "x" + }, + "name": "x" + }, + "cases": [ + { + "type": "MatchCase", + "start": 11, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 32 + } + }, + "test": { + "type": "MemberExpression", + "start": 13, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "object": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + }, + "identifierName": "x" + }, + "name": "x" + }, + "property": { + "type": "Identifier", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 7 + }, + "identifierName": "a" + }, + "name": "a" + }, + "computed": false + }, + "binding": { + "type": "ObjectPattern", + "start": 22, + "end": 34, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 16 + }, + "identifierName": "a" + }, + "name": "a" + }, + "value": { + "type": "Identifier", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 16 + }, + "identifierName": "a" + }, + "name": "a" + }, + "extra": { + "shorthand": true + } + }, + { + "type": "ObjectProperty", + "start": 27, + "end": 32, + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 27, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 19 + }, + "identifierName": "b" + }, + "name": "b" + }, + "value": { + "type": "AssignmentPattern", + "start": 27, + "end": 32, + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "left": { + "type": "Identifier", + "start": 27, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 19 + }, + "identifierName": "b" + }, + "name": "b" + }, + "right": { + "type": "NumericLiteral", + "start": 31, + "end": 32, + "loc": { + "start": { + "line": 2, + "column": 22 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + }, + "extra": { + "shorthand": true + } + } + ] + }, + "consequent": { + "type": "ExpressionStatement", + "start": 36, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 27 + }, + "end": { + "line": 2, + "column": 32 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 36, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 27 + }, + "end": { + "line": 2, + "column": 32 + } + }, + "left": { + "type": "Identifier", + "start": 36, + "end": 37, + "loc": { + "start": { + "line": 2, + "column": 27 + }, + "end": { + "line": 2, + "column": 28 + }, + "identifierName": "a" + }, + "name": "a" + }, + "operator": "+", + "right": { + "type": "Identifier", + "start": 40, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 31 + }, + "end": { + "line": 2, + "column": 32 + }, + "identifierName": "b" + }, + "name": "b" + } + } + } + }, + { + "type": "MatchCase", + "start": 44, + "end": 78, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 36 + } + }, + "test": { + "type": "LogicalExpression", + "start": 46, + "end": 57, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "left": { + "type": "MemberExpression", + "start": 46, + "end": 49, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 7 + } + }, + "object": { + "type": "Identifier", + "start": 46, + "end": 47, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 5 + }, + "identifierName": "x" + }, + "name": "x" + }, + "property": { + "type": "NumericLiteral", + "start": 48, + "end": 49, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 7 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + }, + "computed": true + }, + "operator": "&&", + "right": { + "type": "MemberExpression", + "start": 54, + "end": 57, + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "object": { + "type": "Identifier", + "start": 54, + "end": 55, + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 13 + }, + "identifierName": "x" + }, + "name": "x" + }, + "property": { + "type": "NumericLiteral", + "start": 56, + "end": 57, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + }, + "computed": true + } + }, + "binding": { + "type": "ArrayPattern", + "start": 63, + "end": 71, + "loc": { + "start": { + "line": 3, + "column": 21 + }, + "end": { + "line": 3, + "column": 29 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 65, + "end": 66, + "loc": { + "start": { + "line": 3, + "column": 23 + }, + "end": { + "line": 3, + "column": 24 + }, + "identifierName": "a" + }, + "name": "a" + }, + { + "type": "Identifier", + "start": 68, + "end": 69, + "loc": { + "start": { + "line": 3, + "column": 26 + }, + "end": { + "line": 3, + "column": 27 + }, + "identifierName": "b" + }, + "name": "b" + } + ] + }, + "consequent": { + "type": "ExpressionStatement", + "start": 73, + "end": 78, + "loc": { + "start": { + "line": 3, + "column": 31 + }, + "end": { + "line": 3, + "column": 36 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 73, + "end": 78, + "loc": { + "start": { + "line": 3, + "column": 31 + }, + "end": { + "line": 3, + "column": 36 + } + }, + "left": { + "type": "Identifier", + "start": 73, + "end": 74, + "loc": { + "start": { + "line": 3, + "column": 31 + }, + "end": { + "line": 3, + "column": 32 + }, + "identifierName": "a" + }, + "name": "a" + }, + "operator": "+", + "right": { + "type": "Identifier", + "start": 77, + "end": 78, + "loc": { + "start": { + "line": 3, + "column": 35 + }, + "end": { + "line": 3, + "column": 36 + }, + "identifierName": "b" + }, + "name": "b" + } + } + } + } + ] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/match/destructuring-arr/actual.js b/test/fixtures/lightscript/match/destructuring-arr/actual.js new file mode 100644 index 0000000000..18fcad17f3 --- /dev/null +++ b/test/fixtures/lightscript/match/destructuring-arr/actual.js @@ -0,0 +1,18 @@ +match x: + | with [ a, b ]: a - b + | with [ a, b = 2 ]: a + b - 2 + | with [ a, ...b ]: b.concat(a) + | with [ + [ + b + d = 'e' + ] + [ g, , h ] + ...j + ]: + [b, d, g, ...j].join('') + | foo with [ a, b ]: a - b + | foo with [ a, b = 2 ]: a + b - 2 + | foo with [ a, ...b ]: b.concat(a) + | foo with [[b, d = 'e'], [g,,h], ...j ]: + [b, d, g, ...j].join('') diff --git a/test/fixtures/lightscript/match/destructuring-arr/expected.json b/test/fixtures/lightscript/match/destructuring-arr/expected.json new file mode 100644 index 0000000000..4e1f7c5fec --- /dev/null +++ b/test/fixtures/lightscript/match/destructuring-arr/expected.json @@ -0,0 +1,1978 @@ +{ + "type": "File", + "start": 0, + "end": 392, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 18, + "column": 28 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 392, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 18, + "column": 28 + } + }, + "sourceType": "script", + "body": [ + { + "type": "MatchStatement", + "start": 0, + "end": 392, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 18, + "column": 28 + } + }, + "discriminant": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "x" + }, + "name": "x" + }, + "cases": [ + { + "type": "MatchCase", + "start": 11, + "end": 33, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "binding": { + "type": "ArrayPattern", + "start": 18, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 12 + }, + "identifierName": "a" + }, + "name": "a" + }, + { + "type": "Identifier", + "start": 23, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + }, + "identifierName": "b" + }, + "name": "b" + } + ] + }, + "consequent": { + "type": "ExpressionStatement", + "start": 28, + "end": 33, + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 28, + "end": 33, + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "left": { + "type": "Identifier", + "start": 28, + "end": 29, + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 20 + }, + "identifierName": "a" + }, + "name": "a" + }, + "operator": "-", + "right": { + "type": "Identifier", + "start": 32, + "end": 33, + "loc": { + "start": { + "line": 2, + "column": 23 + }, + "end": { + "line": 2, + "column": 24 + }, + "identifierName": "b" + }, + "name": "b" + } + } + } + }, + { + "type": "MatchCase", + "start": 36, + "end": 66, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 32 + } + }, + "binding": { + "type": "ArrayPattern", + "start": 43, + "end": 55, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 21 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 45, + "end": 46, + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 12 + }, + "identifierName": "a" + }, + "name": "a" + }, + { + "type": "AssignmentPattern", + "start": 48, + "end": 53, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 19 + } + }, + "left": { + "type": "Identifier", + "start": 48, + "end": 49, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + }, + "identifierName": "b" + }, + "name": "b" + }, + "right": { + "type": "NumericLiteral", + "start": 52, + "end": 53, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 19 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + } + ] + }, + "consequent": { + "type": "ExpressionStatement", + "start": 57, + "end": 66, + "loc": { + "start": { + "line": 3, + "column": 23 + }, + "end": { + "line": 3, + "column": 32 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 57, + "end": 66, + "loc": { + "start": { + "line": 3, + "column": 23 + }, + "end": { + "line": 3, + "column": 32 + } + }, + "left": { + "type": "BinaryExpression", + "start": 57, + "end": 62, + "loc": { + "start": { + "line": 3, + "column": 23 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "left": { + "type": "Identifier", + "start": 57, + "end": 58, + "loc": { + "start": { + "line": 3, + "column": 23 + }, + "end": { + "line": 3, + "column": 24 + }, + "identifierName": "a" + }, + "name": "a" + }, + "operator": "+", + "right": { + "type": "Identifier", + "start": 61, + "end": 62, + "loc": { + "start": { + "line": 3, + "column": 27 + }, + "end": { + "line": 3, + "column": 28 + }, + "identifierName": "b" + }, + "name": "b" + } + }, + "operator": "-", + "right": { + "type": "NumericLiteral", + "start": 65, + "end": 66, + "loc": { + "start": { + "line": 3, + "column": 31 + }, + "end": { + "line": 3, + "column": 32 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + } + } + }, + { + "type": "MatchCase", + "start": 69, + "end": 100, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 33 + } + }, + "binding": { + "type": "ArrayPattern", + "start": 76, + "end": 87, + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 4, + "column": 20 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 78, + "end": 79, + "loc": { + "start": { + "line": 4, + "column": 11 + }, + "end": { + "line": 4, + "column": 12 + }, + "identifierName": "a" + }, + "name": "a" + }, + { + "type": "RestElement", + "start": 81, + "end": 85, + "loc": { + "start": { + "line": 4, + "column": 14 + }, + "end": { + "line": 4, + "column": 18 + } + }, + "argument": { + "type": "Identifier", + "start": 84, + "end": 85, + "loc": { + "start": { + "line": 4, + "column": 17 + }, + "end": { + "line": 4, + "column": 18 + }, + "identifierName": "b" + }, + "name": "b" + } + } + ] + }, + "consequent": { + "type": "ExpressionStatement", + "start": 89, + "end": 100, + "loc": { + "start": { + "line": 4, + "column": 22 + }, + "end": { + "line": 4, + "column": 33 + } + }, + "expression": { + "type": "CallExpression", + "start": 89, + "end": 100, + "loc": { + "start": { + "line": 4, + "column": 22 + }, + "end": { + "line": 4, + "column": 33 + } + }, + "callee": { + "type": "MemberExpression", + "start": 89, + "end": 97, + "loc": { + "start": { + "line": 4, + "column": 22 + }, + "end": { + "line": 4, + "column": 30 + } + }, + "object": { + "type": "Identifier", + "start": 89, + "end": 90, + "loc": { + "start": { + "line": 4, + "column": 22 + }, + "end": { + "line": 4, + "column": 23 + }, + "identifierName": "b" + }, + "name": "b" + }, + "property": { + "type": "Identifier", + "start": 91, + "end": 97, + "loc": { + "start": { + "line": 4, + "column": 24 + }, + "end": { + "line": 4, + "column": 30 + }, + "identifierName": "concat" + }, + "name": "concat" + }, + "computed": false + }, + "arguments": [ + { + "type": "Identifier", + "start": 98, + "end": 99, + "loc": { + "start": { + "line": 4, + "column": 31 + }, + "end": { + "line": 4, + "column": 32 + }, + "identifierName": "a" + }, + "name": "a" + } + ] + } + } + }, + { + "type": "MatchCase", + "start": 103, + "end": 215, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 13, + "column": 28 + } + }, + "binding": { + "type": "ArrayPattern", + "start": 110, + "end": 185, + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 12, + "column": 3 + } + }, + "elements": [ + { + "type": "ArrayPattern", + "start": 118, + "end": 153, + "loc": { + "start": { + "line": 6, + "column": 6 + }, + "end": { + "line": 9, + "column": 7 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 128, + "end": 129, + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 9 + }, + "identifierName": "b" + }, + "name": "b" + }, + { + "type": "AssignmentPattern", + "start": 138, + "end": 145, + "loc": { + "start": { + "line": 8, + "column": 8 + }, + "end": { + "line": 8, + "column": 15 + } + }, + "left": { + "type": "Identifier", + "start": 138, + "end": 139, + "loc": { + "start": { + "line": 8, + "column": 8 + }, + "end": { + "line": 8, + "column": 9 + }, + "identifierName": "d" + }, + "name": "d" + }, + "right": { + "type": "StringLiteral", + "start": 142, + "end": 145, + "loc": { + "start": { + "line": 8, + "column": 12 + }, + "end": { + "line": 8, + "column": 15 + } + }, + "extra": { + "rawValue": "e", + "raw": "'e'" + }, + "value": "e" + } + } + ] + }, + { + "type": "ArrayPattern", + "start": 160, + "end": 170, + "loc": { + "start": { + "line": 10, + "column": 6 + }, + "end": { + "line": 10, + "column": 16 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 162, + "end": 163, + "loc": { + "start": { + "line": 10, + "column": 8 + }, + "end": { + "line": 10, + "column": 9 + }, + "identifierName": "g" + }, + "name": "g" + }, + null, + { + "type": "Identifier", + "start": 167, + "end": 168, + "loc": { + "start": { + "line": 10, + "column": 13 + }, + "end": { + "line": 10, + "column": 14 + }, + "identifierName": "h" + }, + "name": "h" + } + ] + }, + { + "type": "RestElement", + "start": 177, + "end": 181, + "loc": { + "start": { + "line": 11, + "column": 6 + }, + "end": { + "line": 11, + "column": 10 + } + }, + "argument": { + "type": "Identifier", + "start": 180, + "end": 181, + "loc": { + "start": { + "line": 11, + "column": 9 + }, + "end": { + "line": 11, + "column": 10 + }, + "identifierName": "j" + }, + "name": "j" + } + } + ] + }, + "consequent": { + "type": "BlockStatement", + "start": 185, + "end": 215, + "loc": { + "start": { + "line": 12, + "column": 3 + }, + "end": { + "line": 13, + "column": 28 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 191, + "end": 215, + "loc": { + "start": { + "line": 13, + "column": 4 + }, + "end": { + "line": 13, + "column": 28 + } + }, + "expression": { + "type": "CallExpression", + "start": 191, + "end": 215, + "loc": { + "start": { + "line": 13, + "column": 4 + }, + "end": { + "line": 13, + "column": 28 + } + }, + "callee": { + "type": "MemberExpression", + "start": 191, + "end": 211, + "loc": { + "start": { + "line": 13, + "column": 4 + }, + "end": { + "line": 13, + "column": 24 + } + }, + "object": { + "type": "ArrayExpression", + "start": 191, + "end": 206, + "loc": { + "start": { + "line": 13, + "column": 4 + }, + "end": { + "line": 13, + "column": 19 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 192, + "end": 193, + "loc": { + "start": { + "line": 13, + "column": 5 + }, + "end": { + "line": 13, + "column": 6 + }, + "identifierName": "b" + }, + "name": "b" + }, + { + "type": "Identifier", + "start": 195, + "end": 196, + "loc": { + "start": { + "line": 13, + "column": 8 + }, + "end": { + "line": 13, + "column": 9 + }, + "identifierName": "d" + }, + "name": "d" + }, + { + "type": "Identifier", + "start": 198, + "end": 199, + "loc": { + "start": { + "line": 13, + "column": 11 + }, + "end": { + "line": 13, + "column": 12 + }, + "identifierName": "g" + }, + "name": "g" + }, + { + "type": "SpreadElement", + "start": 201, + "end": 205, + "loc": { + "start": { + "line": 13, + "column": 14 + }, + "end": { + "line": 13, + "column": 18 + } + }, + "argument": { + "type": "Identifier", + "start": 204, + "end": 205, + "loc": { + "start": { + "line": 13, + "column": 17 + }, + "end": { + "line": 13, + "column": 18 + }, + "identifierName": "j" + }, + "name": "j" + } + } + ] + }, + "property": { + "type": "Identifier", + "start": 207, + "end": 211, + "loc": { + "start": { + "line": 13, + "column": 20 + }, + "end": { + "line": 13, + "column": 24 + }, + "identifierName": "join" + }, + "name": "join" + }, + "computed": false + }, + "arguments": [ + { + "type": "StringLiteral", + "start": 212, + "end": 214, + "loc": { + "start": { + "line": 13, + "column": 25 + }, + "end": { + "line": 13, + "column": 27 + } + }, + "extra": { + "rawValue": "", + "raw": "''" + }, + "value": "" + } + ] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + }, + { + "type": "MatchCase", + "start": 218, + "end": 244, + "loc": { + "start": { + "line": 14, + "column": 2 + }, + "end": { + "line": 14, + "column": 28 + } + }, + "test": { + "type": "Identifier", + "start": 220, + "end": 223, + "loc": { + "start": { + "line": 14, + "column": 4 + }, + "end": { + "line": 14, + "column": 7 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "binding": { + "type": "ArrayPattern", + "start": 229, + "end": 237, + "loc": { + "start": { + "line": 14, + "column": 13 + }, + "end": { + "line": 14, + "column": 21 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 231, + "end": 232, + "loc": { + "start": { + "line": 14, + "column": 15 + }, + "end": { + "line": 14, + "column": 16 + }, + "identifierName": "a" + }, + "name": "a" + }, + { + "type": "Identifier", + "start": 234, + "end": 235, + "loc": { + "start": { + "line": 14, + "column": 18 + }, + "end": { + "line": 14, + "column": 19 + }, + "identifierName": "b" + }, + "name": "b" + } + ] + }, + "consequent": { + "type": "ExpressionStatement", + "start": 239, + "end": 244, + "loc": { + "start": { + "line": 14, + "column": 23 + }, + "end": { + "line": 14, + "column": 28 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 239, + "end": 244, + "loc": { + "start": { + "line": 14, + "column": 23 + }, + "end": { + "line": 14, + "column": 28 + } + }, + "left": { + "type": "Identifier", + "start": 239, + "end": 240, + "loc": { + "start": { + "line": 14, + "column": 23 + }, + "end": { + "line": 14, + "column": 24 + }, + "identifierName": "a" + }, + "name": "a" + }, + "operator": "-", + "right": { + "type": "Identifier", + "start": 243, + "end": 244, + "loc": { + "start": { + "line": 14, + "column": 27 + }, + "end": { + "line": 14, + "column": 28 + }, + "identifierName": "b" + }, + "name": "b" + } + } + } + }, + { + "type": "MatchCase", + "start": 247, + "end": 281, + "loc": { + "start": { + "line": 15, + "column": 2 + }, + "end": { + "line": 15, + "column": 36 + } + }, + "test": { + "type": "Identifier", + "start": 249, + "end": 252, + "loc": { + "start": { + "line": 15, + "column": 4 + }, + "end": { + "line": 15, + "column": 7 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "binding": { + "type": "ArrayPattern", + "start": 258, + "end": 270, + "loc": { + "start": { + "line": 15, + "column": 13 + }, + "end": { + "line": 15, + "column": 25 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 260, + "end": 261, + "loc": { + "start": { + "line": 15, + "column": 15 + }, + "end": { + "line": 15, + "column": 16 + }, + "identifierName": "a" + }, + "name": "a" + }, + { + "type": "AssignmentPattern", + "start": 263, + "end": 268, + "loc": { + "start": { + "line": 15, + "column": 18 + }, + "end": { + "line": 15, + "column": 23 + } + }, + "left": { + "type": "Identifier", + "start": 263, + "end": 264, + "loc": { + "start": { + "line": 15, + "column": 18 + }, + "end": { + "line": 15, + "column": 19 + }, + "identifierName": "b" + }, + "name": "b" + }, + "right": { + "type": "NumericLiteral", + "start": 267, + "end": 268, + "loc": { + "start": { + "line": 15, + "column": 22 + }, + "end": { + "line": 15, + "column": 23 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + } + ] + }, + "consequent": { + "type": "ExpressionStatement", + "start": 272, + "end": 281, + "loc": { + "start": { + "line": 15, + "column": 27 + }, + "end": { + "line": 15, + "column": 36 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 272, + "end": 281, + "loc": { + "start": { + "line": 15, + "column": 27 + }, + "end": { + "line": 15, + "column": 36 + } + }, + "left": { + "type": "BinaryExpression", + "start": 272, + "end": 277, + "loc": { + "start": { + "line": 15, + "column": 27 + }, + "end": { + "line": 15, + "column": 32 + } + }, + "left": { + "type": "Identifier", + "start": 272, + "end": 273, + "loc": { + "start": { + "line": 15, + "column": 27 + }, + "end": { + "line": 15, + "column": 28 + }, + "identifierName": "a" + }, + "name": "a" + }, + "operator": "+", + "right": { + "type": "Identifier", + "start": 276, + "end": 277, + "loc": { + "start": { + "line": 15, + "column": 31 + }, + "end": { + "line": 15, + "column": 32 + }, + "identifierName": "b" + }, + "name": "b" + } + }, + "operator": "-", + "right": { + "type": "NumericLiteral", + "start": 280, + "end": 281, + "loc": { + "start": { + "line": 15, + "column": 35 + }, + "end": { + "line": 15, + "column": 36 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + } + } + }, + { + "type": "MatchCase", + "start": 284, + "end": 319, + "loc": { + "start": { + "line": 16, + "column": 2 + }, + "end": { + "line": 16, + "column": 37 + } + }, + "test": { + "type": "Identifier", + "start": 286, + "end": 289, + "loc": { + "start": { + "line": 16, + "column": 4 + }, + "end": { + "line": 16, + "column": 7 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "binding": { + "type": "ArrayPattern", + "start": 295, + "end": 306, + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 24 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 297, + "end": 298, + "loc": { + "start": { + "line": 16, + "column": 15 + }, + "end": { + "line": 16, + "column": 16 + }, + "identifierName": "a" + }, + "name": "a" + }, + { + "type": "RestElement", + "start": 300, + "end": 304, + "loc": { + "start": { + "line": 16, + "column": 18 + }, + "end": { + "line": 16, + "column": 22 + } + }, + "argument": { + "type": "Identifier", + "start": 303, + "end": 304, + "loc": { + "start": { + "line": 16, + "column": 21 + }, + "end": { + "line": 16, + "column": 22 + }, + "identifierName": "b" + }, + "name": "b" + } + } + ] + }, + "consequent": { + "type": "ExpressionStatement", + "start": 308, + "end": 319, + "loc": { + "start": { + "line": 16, + "column": 26 + }, + "end": { + "line": 16, + "column": 37 + } + }, + "expression": { + "type": "CallExpression", + "start": 308, + "end": 319, + "loc": { + "start": { + "line": 16, + "column": 26 + }, + "end": { + "line": 16, + "column": 37 + } + }, + "callee": { + "type": "MemberExpression", + "start": 308, + "end": 316, + "loc": { + "start": { + "line": 16, + "column": 26 + }, + "end": { + "line": 16, + "column": 34 + } + }, + "object": { + "type": "Identifier", + "start": 308, + "end": 309, + "loc": { + "start": { + "line": 16, + "column": 26 + }, + "end": { + "line": 16, + "column": 27 + }, + "identifierName": "b" + }, + "name": "b" + }, + "property": { + "type": "Identifier", + "start": 310, + "end": 316, + "loc": { + "start": { + "line": 16, + "column": 28 + }, + "end": { + "line": 16, + "column": 34 + }, + "identifierName": "concat" + }, + "name": "concat" + }, + "computed": false + }, + "arguments": [ + { + "type": "Identifier", + "start": 317, + "end": 318, + "loc": { + "start": { + "line": 16, + "column": 35 + }, + "end": { + "line": 16, + "column": 36 + }, + "identifierName": "a" + }, + "name": "a" + } + ] + } + } + }, + { + "type": "MatchCase", + "start": 322, + "end": 392, + "loc": { + "start": { + "line": 17, + "column": 2 + }, + "end": { + "line": 18, + "column": 28 + } + }, + "test": { + "type": "Identifier", + "start": 324, + "end": 327, + "loc": { + "start": { + "line": 17, + "column": 4 + }, + "end": { + "line": 17, + "column": 7 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "binding": { + "type": "ArrayPattern", + "start": 333, + "end": 362, + "loc": { + "start": { + "line": 17, + "column": 13 + }, + "end": { + "line": 17, + "column": 42 + } + }, + "elements": [ + { + "type": "ArrayPattern", + "start": 334, + "end": 346, + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 17, + "column": 26 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 335, + "end": 336, + "loc": { + "start": { + "line": 17, + "column": 15 + }, + "end": { + "line": 17, + "column": 16 + }, + "identifierName": "b" + }, + "name": "b" + }, + { + "type": "AssignmentPattern", + "start": 338, + "end": 345, + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 25 + } + }, + "left": { + "type": "Identifier", + "start": 338, + "end": 339, + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 19 + }, + "identifierName": "d" + }, + "name": "d" + }, + "right": { + "type": "StringLiteral", + "start": 342, + "end": 345, + "loc": { + "start": { + "line": 17, + "column": 22 + }, + "end": { + "line": 17, + "column": 25 + } + }, + "extra": { + "rawValue": "e", + "raw": "'e'" + }, + "value": "e" + } + } + ] + }, + { + "type": "ArrayPattern", + "start": 348, + "end": 354, + "loc": { + "start": { + "line": 17, + "column": 28 + }, + "end": { + "line": 17, + "column": 34 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 349, + "end": 350, + "loc": { + "start": { + "line": 17, + "column": 29 + }, + "end": { + "line": 17, + "column": 30 + }, + "identifierName": "g" + }, + "name": "g" + }, + null, + { + "type": "Identifier", + "start": 352, + "end": 353, + "loc": { + "start": { + "line": 17, + "column": 32 + }, + "end": { + "line": 17, + "column": 33 + }, + "identifierName": "h" + }, + "name": "h" + } + ] + }, + { + "type": "RestElement", + "start": 356, + "end": 360, + "loc": { + "start": { + "line": 17, + "column": 36 + }, + "end": { + "line": 17, + "column": 40 + } + }, + "argument": { + "type": "Identifier", + "start": 359, + "end": 360, + "loc": { + "start": { + "line": 17, + "column": 39 + }, + "end": { + "line": 17, + "column": 40 + }, + "identifierName": "j" + }, + "name": "j" + } + } + ] + }, + "consequent": { + "type": "BlockStatement", + "start": 362, + "end": 392, + "loc": { + "start": { + "line": 17, + "column": 42 + }, + "end": { + "line": 18, + "column": 28 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 368, + "end": 392, + "loc": { + "start": { + "line": 18, + "column": 4 + }, + "end": { + "line": 18, + "column": 28 + } + }, + "expression": { + "type": "CallExpression", + "start": 368, + "end": 392, + "loc": { + "start": { + "line": 18, + "column": 4 + }, + "end": { + "line": 18, + "column": 28 + } + }, + "callee": { + "type": "MemberExpression", + "start": 368, + "end": 388, + "loc": { + "start": { + "line": 18, + "column": 4 + }, + "end": { + "line": 18, + "column": 24 + } + }, + "object": { + "type": "ArrayExpression", + "start": 368, + "end": 383, + "loc": { + "start": { + "line": 18, + "column": 4 + }, + "end": { + "line": 18, + "column": 19 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 369, + "end": 370, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 6 + }, + "identifierName": "b" + }, + "name": "b" + }, + { + "type": "Identifier", + "start": 372, + "end": 373, + "loc": { + "start": { + "line": 18, + "column": 8 + }, + "end": { + "line": 18, + "column": 9 + }, + "identifierName": "d" + }, + "name": "d" + }, + { + "type": "Identifier", + "start": 375, + "end": 376, + "loc": { + "start": { + "line": 18, + "column": 11 + }, + "end": { + "line": 18, + "column": 12 + }, + "identifierName": "g" + }, + "name": "g" + }, + { + "type": "SpreadElement", + "start": 378, + "end": 382, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 18, + "column": 18 + } + }, + "argument": { + "type": "Identifier", + "start": 381, + "end": 382, + "loc": { + "start": { + "line": 18, + "column": 17 + }, + "end": { + "line": 18, + "column": 18 + }, + "identifierName": "j" + }, + "name": "j" + } + } + ] + }, + "property": { + "type": "Identifier", + "start": 384, + "end": 388, + "loc": { + "start": { + "line": 18, + "column": 20 + }, + "end": { + "line": 18, + "column": 24 + }, + "identifierName": "join" + }, + "name": "join" + }, + "computed": false + }, + "arguments": [ + { + "type": "StringLiteral", + "start": 389, + "end": 391, + "loc": { + "start": { + "line": 18, + "column": 25 + }, + "end": { + "line": 18, + "column": 27 + } + }, + "extra": { + "rawValue": "", + "raw": "''" + }, + "value": "" + } + ] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + ] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/match/destructuring-obj-arr-mixed/actual.js b/test/fixtures/lightscript/match/destructuring-obj-arr-mixed/actual.js new file mode 100644 index 0000000000..83fc1aec6e --- /dev/null +++ b/test/fixtures/lightscript/match/destructuring-obj-arr-mixed/actual.js @@ -0,0 +1,15 @@ +match x: + | with { + a: [ + b + { + d + e = 1 + ...f + } + g + ] + h = 'h' + ...i + }: + [b, d, ...f, g, h, i].join('') diff --git a/test/fixtures/lightscript/match/destructuring-obj-arr-mixed/expected.json b/test/fixtures/lightscript/match/destructuring-obj-arr-mixed/expected.json new file mode 100644 index 0000000000..8cff8e545d --- /dev/null +++ b/test/fixtures/lightscript/match/destructuring-obj-arr-mixed/expected.json @@ -0,0 +1,742 @@ +{ + "type": "File", + "start": 0, + "end": 164, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 15, + "column": 34 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 164, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 15, + "column": 34 + } + }, + "sourceType": "script", + "body": [ + { + "type": "MatchStatement", + "start": 0, + "end": 164, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 15, + "column": 34 + } + }, + "discriminant": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "x" + }, + "name": "x" + }, + "cases": [ + { + "type": "MatchCase", + "start": 11, + "end": 164, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 15, + "column": 34 + } + }, + "binding": { + "type": "ObjectPattern", + "start": 18, + "end": 128, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 14, + "column": 3 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 24, + "end": 103, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 11, + "column": 5 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 5 + }, + "identifierName": "a" + }, + "name": "a" + }, + "value": { + "type": "ArrayPattern", + "start": 27, + "end": 103, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 11, + "column": 5 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 35, + "end": 36, + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 7 + }, + "identifierName": "b" + }, + "name": "b" + }, + { + "type": "ObjectPattern", + "start": 43, + "end": 89, + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 9, + "column": 7 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 53, + "end": 54, + "loc": { + "start": { + "line": 6, + "column": 8 + }, + "end": { + "line": 6, + "column": 9 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 53, + "end": 54, + "loc": { + "start": { + "line": 6, + "column": 8 + }, + "end": { + "line": 6, + "column": 9 + }, + "identifierName": "d" + }, + "name": "d" + }, + "value": { + "type": "Identifier", + "start": 53, + "end": 54, + "loc": { + "start": { + "line": 6, + "column": 8 + }, + "end": { + "line": 6, + "column": 9 + }, + "identifierName": "d" + }, + "name": "d" + }, + "extra": { + "shorthand": true + } + }, + { + "type": "ObjectProperty", + "start": 63, + "end": 68, + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 13 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 63, + "end": 64, + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 9 + }, + "identifierName": "e" + }, + "name": "e" + }, + "value": { + "type": "AssignmentPattern", + "start": 63, + "end": 68, + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 13 + } + }, + "left": { + "type": "Identifier", + "start": 63, + "end": 64, + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 9 + }, + "identifierName": "e" + }, + "name": "e" + }, + "right": { + "type": "NumericLiteral", + "start": 67, + "end": 68, + "loc": { + "start": { + "line": 7, + "column": 12 + }, + "end": { + "line": 7, + "column": 13 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + }, + "extra": { + "shorthand": true + } + }, + { + "type": "RestProperty", + "start": 77, + "end": 81, + "loc": { + "start": { + "line": 8, + "column": 8 + }, + "end": { + "line": 8, + "column": 12 + } + }, + "argument": { + "type": "Identifier", + "start": 80, + "end": 81, + "loc": { + "start": { + "line": 8, + "column": 11 + }, + "end": { + "line": 8, + "column": 12 + }, + "identifierName": "f" + }, + "name": "f" + } + } + ] + }, + { + "type": "Identifier", + "start": 96, + "end": 97, + "loc": { + "start": { + "line": 10, + "column": 6 + }, + "end": { + "line": 10, + "column": 7 + }, + "identifierName": "g" + }, + "name": "g" + } + ] + } + }, + { + "type": "ObjectProperty", + "start": 108, + "end": 115, + "loc": { + "start": { + "line": 12, + "column": 4 + }, + "end": { + "line": 12, + "column": 11 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 108, + "end": 109, + "loc": { + "start": { + "line": 12, + "column": 4 + }, + "end": { + "line": 12, + "column": 5 + }, + "identifierName": "h" + }, + "name": "h" + }, + "value": { + "type": "AssignmentPattern", + "start": 108, + "end": 115, + "loc": { + "start": { + "line": 12, + "column": 4 + }, + "end": { + "line": 12, + "column": 11 + } + }, + "left": { + "type": "Identifier", + "start": 108, + "end": 109, + "loc": { + "start": { + "line": 12, + "column": 4 + }, + "end": { + "line": 12, + "column": 5 + }, + "identifierName": "h" + }, + "name": "h" + }, + "right": { + "type": "StringLiteral", + "start": 112, + "end": 115, + "loc": { + "start": { + "line": 12, + "column": 8 + }, + "end": { + "line": 12, + "column": 11 + } + }, + "extra": { + "rawValue": "h", + "raw": "'h'" + }, + "value": "h" + } + }, + "extra": { + "shorthand": true + } + }, + { + "type": "RestProperty", + "start": 120, + "end": 124, + "loc": { + "start": { + "line": 13, + "column": 4 + }, + "end": { + "line": 13, + "column": 8 + } + }, + "argument": { + "type": "Identifier", + "start": 123, + "end": 124, + "loc": { + "start": { + "line": 13, + "column": 7 + }, + "end": { + "line": 13, + "column": 8 + }, + "identifierName": "i" + }, + "name": "i" + } + } + ] + }, + "consequent": { + "type": "BlockStatement", + "start": 128, + "end": 164, + "loc": { + "start": { + "line": 14, + "column": 3 + }, + "end": { + "line": 15, + "column": 34 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 134, + "end": 164, + "loc": { + "start": { + "line": 15, + "column": 4 + }, + "end": { + "line": 15, + "column": 34 + } + }, + "expression": { + "type": "CallExpression", + "start": 134, + "end": 164, + "loc": { + "start": { + "line": 15, + "column": 4 + }, + "end": { + "line": 15, + "column": 34 + } + }, + "callee": { + "type": "MemberExpression", + "start": 134, + "end": 160, + "loc": { + "start": { + "line": 15, + "column": 4 + }, + "end": { + "line": 15, + "column": 30 + } + }, + "object": { + "type": "ArrayExpression", + "start": 134, + "end": 155, + "loc": { + "start": { + "line": 15, + "column": 4 + }, + "end": { + "line": 15, + "column": 25 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 135, + "end": 136, + "loc": { + "start": { + "line": 15, + "column": 5 + }, + "end": { + "line": 15, + "column": 6 + }, + "identifierName": "b" + }, + "name": "b" + }, + { + "type": "Identifier", + "start": 138, + "end": 139, + "loc": { + "start": { + "line": 15, + "column": 8 + }, + "end": { + "line": 15, + "column": 9 + }, + "identifierName": "d" + }, + "name": "d" + }, + { + "type": "SpreadElement", + "start": 141, + "end": 145, + "loc": { + "start": { + "line": 15, + "column": 11 + }, + "end": { + "line": 15, + "column": 15 + } + }, + "argument": { + "type": "Identifier", + "start": 144, + "end": 145, + "loc": { + "start": { + "line": 15, + "column": 14 + }, + "end": { + "line": 15, + "column": 15 + }, + "identifierName": "f" + }, + "name": "f" + } + }, + { + "type": "Identifier", + "start": 147, + "end": 148, + "loc": { + "start": { + "line": 15, + "column": 17 + }, + "end": { + "line": 15, + "column": 18 + }, + "identifierName": "g" + }, + "name": "g" + }, + { + "type": "Identifier", + "start": 150, + "end": 151, + "loc": { + "start": { + "line": 15, + "column": 20 + }, + "end": { + "line": 15, + "column": 21 + }, + "identifierName": "h" + }, + "name": "h" + }, + { + "type": "Identifier", + "start": 153, + "end": 154, + "loc": { + "start": { + "line": 15, + "column": 23 + }, + "end": { + "line": 15, + "column": 24 + }, + "identifierName": "i" + }, + "name": "i" + } + ] + }, + "property": { + "type": "Identifier", + "start": 156, + "end": 160, + "loc": { + "start": { + "line": 15, + "column": 26 + }, + "end": { + "line": 15, + "column": 30 + }, + "identifierName": "join" + }, + "name": "join" + }, + "computed": false + }, + "arguments": [ + { + "type": "StringLiteral", + "start": 161, + "end": 163, + "loc": { + "start": { + "line": 15, + "column": 31 + }, + "end": { + "line": 15, + "column": 33 + } + }, + "extra": { + "rawValue": "", + "raw": "''" + }, + "value": "" + } + ] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + ] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/match/destructuring-obj-arr-mixed/options.json b/test/fixtures/lightscript/match/destructuring-obj-arr-mixed/options.json new file mode 100644 index 0000000000..3ebf2619d6 --- /dev/null +++ b/test/fixtures/lightscript/match/destructuring-obj-arr-mixed/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["objectRestSpread", "lightscript", "jsx", "flow"] +} diff --git a/test/fixtures/lightscript/match/destructuring-obj-basic/actual.js b/test/fixtures/lightscript/match/destructuring-obj-basic/actual.js new file mode 100644 index 0000000000..c6b4045abc --- /dev/null +++ b/test/fixtures/lightscript/match/destructuring-obj-basic/actual.js @@ -0,0 +1,2 @@ +match x: + | with { a, b }: a - b diff --git a/test/fixtures/lightscript/match/destructuring-obj-basic/expected.json b/test/fixtures/lightscript/match/destructuring-obj-basic/expected.json new file mode 100644 index 0000000000..f9dac0c614 --- /dev/null +++ b/test/fixtures/lightscript/match/destructuring-obj-basic/expected.json @@ -0,0 +1,275 @@ +{ + "type": "File", + "start": 0, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "sourceType": "script", + "body": [ + { + "type": "MatchStatement", + "start": 0, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "discriminant": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "x" + }, + "name": "x" + }, + "cases": [ + { + "type": "MatchCase", + "start": 11, + "end": 33, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "binding": { + "type": "ObjectPattern", + "start": 18, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 12 + }, + "identifierName": "a" + }, + "name": "a" + }, + "value": { + "type": "Identifier", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 12 + }, + "identifierName": "a" + }, + "name": "a" + }, + "extra": { + "shorthand": true + } + }, + { + "type": "ObjectProperty", + "start": 23, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 23, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + }, + "identifierName": "b" + }, + "name": "b" + }, + "value": { + "type": "Identifier", + "start": 23, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + }, + "identifierName": "b" + }, + "name": "b" + }, + "extra": { + "shorthand": true + } + } + ] + }, + "consequent": { + "type": "ExpressionStatement", + "start": 28, + "end": 33, + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 28, + "end": 33, + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "left": { + "type": "Identifier", + "start": 28, + "end": 29, + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 20 + }, + "identifierName": "a" + }, + "name": "a" + }, + "operator": "-", + "right": { + "type": "Identifier", + "start": 32, + "end": 33, + "loc": { + "start": { + "line": 2, + "column": 23 + }, + "end": { + "line": 2, + "column": 24 + }, + "identifierName": "b" + }, + "name": "b" + } + } + } + } + ] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/match/destructuring-obj-default/actual.js b/test/fixtures/lightscript/match/destructuring-obj-default/actual.js new file mode 100644 index 0000000000..e616f09a14 --- /dev/null +++ b/test/fixtures/lightscript/match/destructuring-obj-default/actual.js @@ -0,0 +1,2 @@ +match x: + | with { a, b = 1 }: a - b diff --git a/test/fixtures/lightscript/match/destructuring-obj-default/expected.json b/test/fixtures/lightscript/match/destructuring-obj-default/expected.json new file mode 100644 index 0000000000..e4cc9026a8 --- /dev/null +++ b/test/fixtures/lightscript/match/destructuring-obj-default/expected.json @@ -0,0 +1,310 @@ +{ + "type": "File", + "start": 0, + "end": 37, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 28 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 37, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 28 + } + }, + "sourceType": "script", + "body": [ + { + "type": "MatchStatement", + "start": 0, + "end": 37, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 28 + } + }, + "discriminant": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "x" + }, + "name": "x" + }, + "cases": [ + { + "type": "MatchCase", + "start": 11, + "end": 37, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 28 + } + }, + "binding": { + "type": "ObjectPattern", + "start": 18, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 12 + }, + "identifierName": "a" + }, + "name": "a" + }, + "value": { + "type": "Identifier", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 12 + }, + "identifierName": "a" + }, + "name": "a" + }, + "extra": { + "shorthand": true + } + }, + { + "type": "ObjectProperty", + "start": 23, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 23, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + }, + "identifierName": "b" + }, + "name": "b" + }, + "value": { + "type": "AssignmentPattern", + "start": 23, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "left": { + "type": "Identifier", + "start": 23, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + }, + "identifierName": "b" + }, + "name": "b" + }, + "right": { + "type": "NumericLiteral", + "start": 27, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + }, + "extra": { + "shorthand": true + } + } + ] + }, + "consequent": { + "type": "ExpressionStatement", + "start": 32, + "end": 37, + "loc": { + "start": { + "line": 2, + "column": 23 + }, + "end": { + "line": 2, + "column": 28 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 32, + "end": 37, + "loc": { + "start": { + "line": 2, + "column": 23 + }, + "end": { + "line": 2, + "column": 28 + } + }, + "left": { + "type": "Identifier", + "start": 32, + "end": 33, + "loc": { + "start": { + "line": 2, + "column": 23 + }, + "end": { + "line": 2, + "column": 24 + }, + "identifierName": "a" + }, + "name": "a" + }, + "operator": "-", + "right": { + "type": "Identifier", + "start": 36, + "end": 37, + "loc": { + "start": { + "line": 2, + "column": 27 + }, + "end": { + "line": 2, + "column": 28 + }, + "identifierName": "b" + }, + "name": "b" + } + } + } + } + ] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/match/destructuring-obj/actual.js b/test/fixtures/lightscript/match/destructuring-obj/actual.js new file mode 100644 index 0000000000..c629316e56 --- /dev/null +++ b/test/fixtures/lightscript/match/destructuring-obj/actual.js @@ -0,0 +1,17 @@ +match x: + | with { a, b }: a - b + | with { a, b = 2 }: a + b - 2 + | with { a, ...c }: [a, b, c].join('') + | with { + a: { + b + d = 'e' + } + f: { ...g } + }: + [b, d, g].join('') + | foo with { a, b }: a + b + | foo with { a, b = 2 }: a + b - 2 + | foo with { a, ...c }: [a, b, c].join('') + | foo with {a:{b,d = 'e'},f:{ ...g }}: + [b, d, g].join('') diff --git a/test/fixtures/lightscript/match/destructuring-obj/expected.json b/test/fixtures/lightscript/match/destructuring-obj/expected.json new file mode 100644 index 0000000000..021ab4f148 --- /dev/null +++ b/test/fixtures/lightscript/match/destructuring-obj/expected.json @@ -0,0 +1,2624 @@ +{ + "type": "File", + "start": 0, + "end": 374, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 17, + "column": 22 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 374, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 17, + "column": 22 + } + }, + "sourceType": "script", + "body": [ + { + "type": "MatchStatement", + "start": 0, + "end": 374, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 17, + "column": 22 + } + }, + "discriminant": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "x" + }, + "name": "x" + }, + "cases": [ + { + "type": "MatchCase", + "start": 11, + "end": 33, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "binding": { + "type": "ObjectPattern", + "start": 18, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 12 + }, + "identifierName": "a" + }, + "name": "a" + }, + "value": { + "type": "Identifier", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 12 + }, + "identifierName": "a" + }, + "name": "a" + }, + "extra": { + "shorthand": true + } + }, + { + "type": "ObjectProperty", + "start": 23, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 23, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + }, + "identifierName": "b" + }, + "name": "b" + }, + "value": { + "type": "Identifier", + "start": 23, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + }, + "identifierName": "b" + }, + "name": "b" + }, + "extra": { + "shorthand": true + } + } + ] + }, + "consequent": { + "type": "ExpressionStatement", + "start": 28, + "end": 33, + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 28, + "end": 33, + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "left": { + "type": "Identifier", + "start": 28, + "end": 29, + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 20 + }, + "identifierName": "a" + }, + "name": "a" + }, + "operator": "-", + "right": { + "type": "Identifier", + "start": 32, + "end": 33, + "loc": { + "start": { + "line": 2, + "column": 23 + }, + "end": { + "line": 2, + "column": 24 + }, + "identifierName": "b" + }, + "name": "b" + } + } + } + }, + { + "type": "MatchCase", + "start": 36, + "end": 66, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 32 + } + }, + "binding": { + "type": "ObjectPattern", + "start": 43, + "end": 55, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 21 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 45, + "end": 46, + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 12 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 45, + "end": 46, + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 12 + }, + "identifierName": "a" + }, + "name": "a" + }, + "value": { + "type": "Identifier", + "start": 45, + "end": 46, + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 12 + }, + "identifierName": "a" + }, + "name": "a" + }, + "extra": { + "shorthand": true + } + }, + { + "type": "ObjectProperty", + "start": 48, + "end": 53, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 19 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 48, + "end": 49, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + }, + "identifierName": "b" + }, + "name": "b" + }, + "value": { + "type": "AssignmentPattern", + "start": 48, + "end": 53, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 19 + } + }, + "left": { + "type": "Identifier", + "start": 48, + "end": 49, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + }, + "identifierName": "b" + }, + "name": "b" + }, + "right": { + "type": "NumericLiteral", + "start": 52, + "end": 53, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 19 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + }, + "extra": { + "shorthand": true + } + } + ] + }, + "consequent": { + "type": "ExpressionStatement", + "start": 57, + "end": 66, + "loc": { + "start": { + "line": 3, + "column": 23 + }, + "end": { + "line": 3, + "column": 32 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 57, + "end": 66, + "loc": { + "start": { + "line": 3, + "column": 23 + }, + "end": { + "line": 3, + "column": 32 + } + }, + "left": { + "type": "BinaryExpression", + "start": 57, + "end": 62, + "loc": { + "start": { + "line": 3, + "column": 23 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "left": { + "type": "Identifier", + "start": 57, + "end": 58, + "loc": { + "start": { + "line": 3, + "column": 23 + }, + "end": { + "line": 3, + "column": 24 + }, + "identifierName": "a" + }, + "name": "a" + }, + "operator": "+", + "right": { + "type": "Identifier", + "start": 61, + "end": 62, + "loc": { + "start": { + "line": 3, + "column": 27 + }, + "end": { + "line": 3, + "column": 28 + }, + "identifierName": "b" + }, + "name": "b" + } + }, + "operator": "-", + "right": { + "type": "NumericLiteral", + "start": 65, + "end": 66, + "loc": { + "start": { + "line": 3, + "column": 31 + }, + "end": { + "line": 3, + "column": 32 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + } + } + }, + { + "type": "MatchCase", + "start": 69, + "end": 107, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 40 + } + }, + "binding": { + "type": "ObjectPattern", + "start": 76, + "end": 87, + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 4, + "column": 20 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 78, + "end": 79, + "loc": { + "start": { + "line": 4, + "column": 11 + }, + "end": { + "line": 4, + "column": 12 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 78, + "end": 79, + "loc": { + "start": { + "line": 4, + "column": 11 + }, + "end": { + "line": 4, + "column": 12 + }, + "identifierName": "a" + }, + "name": "a" + }, + "value": { + "type": "Identifier", + "start": 78, + "end": 79, + "loc": { + "start": { + "line": 4, + "column": 11 + }, + "end": { + "line": 4, + "column": 12 + }, + "identifierName": "a" + }, + "name": "a" + }, + "extra": { + "shorthand": true + } + }, + { + "type": "RestProperty", + "start": 81, + "end": 85, + "loc": { + "start": { + "line": 4, + "column": 14 + }, + "end": { + "line": 4, + "column": 18 + } + }, + "argument": { + "type": "Identifier", + "start": 84, + "end": 85, + "loc": { + "start": { + "line": 4, + "column": 17 + }, + "end": { + "line": 4, + "column": 18 + }, + "identifierName": "c" + }, + "name": "c" + } + } + ] + }, + "consequent": { + "type": "ExpressionStatement", + "start": 89, + "end": 107, + "loc": { + "start": { + "line": 4, + "column": 22 + }, + "end": { + "line": 4, + "column": 40 + } + }, + "expression": { + "type": "CallExpression", + "start": 89, + "end": 107, + "loc": { + "start": { + "line": 4, + "column": 22 + }, + "end": { + "line": 4, + "column": 40 + } + }, + "callee": { + "type": "MemberExpression", + "start": 89, + "end": 103, + "loc": { + "start": { + "line": 4, + "column": 22 + }, + "end": { + "line": 4, + "column": 36 + } + }, + "object": { + "type": "ArrayExpression", + "start": 89, + "end": 98, + "loc": { + "start": { + "line": 4, + "column": 22 + }, + "end": { + "line": 4, + "column": 31 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 90, + "end": 91, + "loc": { + "start": { + "line": 4, + "column": 23 + }, + "end": { + "line": 4, + "column": 24 + }, + "identifierName": "a" + }, + "name": "a" + }, + { + "type": "Identifier", + "start": 93, + "end": 94, + "loc": { + "start": { + "line": 4, + "column": 26 + }, + "end": { + "line": 4, + "column": 27 + }, + "identifierName": "b" + }, + "name": "b" + }, + { + "type": "Identifier", + "start": 96, + "end": 97, + "loc": { + "start": { + "line": 4, + "column": 29 + }, + "end": { + "line": 4, + "column": 30 + }, + "identifierName": "c" + }, + "name": "c" + } + ] + }, + "property": { + "type": "Identifier", + "start": 99, + "end": 103, + "loc": { + "start": { + "line": 4, + "column": 32 + }, + "end": { + "line": 4, + "column": 36 + }, + "identifierName": "join" + }, + "name": "join" + }, + "computed": false + }, + "arguments": [ + { + "type": "StringLiteral", + "start": 104, + "end": 106, + "loc": { + "start": { + "line": 4, + "column": 37 + }, + "end": { + "line": 4, + "column": 39 + } + }, + "extra": { + "rawValue": "", + "raw": "''" + }, + "value": "" + } + ] + } + } + }, + { + "type": "MatchCase", + "start": 110, + "end": 199, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 12, + "column": 22 + } + }, + "binding": { + "type": "ObjectPattern", + "start": 117, + "end": 175, + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 11, + "column": 3 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 123, + "end": 155, + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 9, + "column": 5 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 123, + "end": 124, + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 5 + }, + "identifierName": "a" + }, + "name": "a" + }, + "value": { + "type": "ObjectPattern", + "start": 126, + "end": 155, + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 9, + "column": 5 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 134, + "end": 135, + "loc": { + "start": { + "line": 7, + "column": 6 + }, + "end": { + "line": 7, + "column": 7 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 134, + "end": 135, + "loc": { + "start": { + "line": 7, + "column": 6 + }, + "end": { + "line": 7, + "column": 7 + }, + "identifierName": "b" + }, + "name": "b" + }, + "value": { + "type": "Identifier", + "start": 134, + "end": 135, + "loc": { + "start": { + "line": 7, + "column": 6 + }, + "end": { + "line": 7, + "column": 7 + }, + "identifierName": "b" + }, + "name": "b" + }, + "extra": { + "shorthand": true + } + }, + { + "type": "ObjectProperty", + "start": 142, + "end": 149, + "loc": { + "start": { + "line": 8, + "column": 6 + }, + "end": { + "line": 8, + "column": 13 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 142, + "end": 143, + "loc": { + "start": { + "line": 8, + "column": 6 + }, + "end": { + "line": 8, + "column": 7 + }, + "identifierName": "d" + }, + "name": "d" + }, + "value": { + "type": "AssignmentPattern", + "start": 142, + "end": 149, + "loc": { + "start": { + "line": 8, + "column": 6 + }, + "end": { + "line": 8, + "column": 13 + } + }, + "left": { + "type": "Identifier", + "start": 142, + "end": 143, + "loc": { + "start": { + "line": 8, + "column": 6 + }, + "end": { + "line": 8, + "column": 7 + }, + "identifierName": "d" + }, + "name": "d" + }, + "right": { + "type": "StringLiteral", + "start": 146, + "end": 149, + "loc": { + "start": { + "line": 8, + "column": 10 + }, + "end": { + "line": 8, + "column": 13 + } + }, + "extra": { + "rawValue": "e", + "raw": "'e'" + }, + "value": "e" + } + }, + "extra": { + "shorthand": true + } + } + ] + } + }, + { + "type": "ObjectProperty", + "start": 160, + "end": 171, + "loc": { + "start": { + "line": 10, + "column": 4 + }, + "end": { + "line": 10, + "column": 15 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 160, + "end": 161, + "loc": { + "start": { + "line": 10, + "column": 4 + }, + "end": { + "line": 10, + "column": 5 + }, + "identifierName": "f" + }, + "name": "f" + }, + "value": { + "type": "ObjectPattern", + "start": 163, + "end": 171, + "loc": { + "start": { + "line": 10, + "column": 7 + }, + "end": { + "line": 10, + "column": 15 + } + }, + "properties": [ + { + "type": "RestProperty", + "start": 165, + "end": 169, + "loc": { + "start": { + "line": 10, + "column": 9 + }, + "end": { + "line": 10, + "column": 13 + } + }, + "argument": { + "type": "Identifier", + "start": 168, + "end": 169, + "loc": { + "start": { + "line": 10, + "column": 12 + }, + "end": { + "line": 10, + "column": 13 + }, + "identifierName": "g" + }, + "name": "g" + } + } + ] + } + } + ] + }, + "consequent": { + "type": "BlockStatement", + "start": 175, + "end": 199, + "loc": { + "start": { + "line": 11, + "column": 3 + }, + "end": { + "line": 12, + "column": 22 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 181, + "end": 199, + "loc": { + "start": { + "line": 12, + "column": 4 + }, + "end": { + "line": 12, + "column": 22 + } + }, + "expression": { + "type": "CallExpression", + "start": 181, + "end": 199, + "loc": { + "start": { + "line": 12, + "column": 4 + }, + "end": { + "line": 12, + "column": 22 + } + }, + "callee": { + "type": "MemberExpression", + "start": 181, + "end": 195, + "loc": { + "start": { + "line": 12, + "column": 4 + }, + "end": { + "line": 12, + "column": 18 + } + }, + "object": { + "type": "ArrayExpression", + "start": 181, + "end": 190, + "loc": { + "start": { + "line": 12, + "column": 4 + }, + "end": { + "line": 12, + "column": 13 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 182, + "end": 183, + "loc": { + "start": { + "line": 12, + "column": 5 + }, + "end": { + "line": 12, + "column": 6 + }, + "identifierName": "b" + }, + "name": "b" + }, + { + "type": "Identifier", + "start": 185, + "end": 186, + "loc": { + "start": { + "line": 12, + "column": 8 + }, + "end": { + "line": 12, + "column": 9 + }, + "identifierName": "d" + }, + "name": "d" + }, + { + "type": "Identifier", + "start": 188, + "end": 189, + "loc": { + "start": { + "line": 12, + "column": 11 + }, + "end": { + "line": 12, + "column": 12 + }, + "identifierName": "g" + }, + "name": "g" + } + ] + }, + "property": { + "type": "Identifier", + "start": 191, + "end": 195, + "loc": { + "start": { + "line": 12, + "column": 14 + }, + "end": { + "line": 12, + "column": 18 + }, + "identifierName": "join" + }, + "name": "join" + }, + "computed": false + }, + "arguments": [ + { + "type": "StringLiteral", + "start": 196, + "end": 198, + "loc": { + "start": { + "line": 12, + "column": 19 + }, + "end": { + "line": 12, + "column": 21 + } + }, + "extra": { + "rawValue": "", + "raw": "''" + }, + "value": "" + } + ] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + }, + { + "type": "MatchCase", + "start": 202, + "end": 228, + "loc": { + "start": { + "line": 13, + "column": 2 + }, + "end": { + "line": 13, + "column": 28 + } + }, + "test": { + "type": "Identifier", + "start": 204, + "end": 207, + "loc": { + "start": { + "line": 13, + "column": 4 + }, + "end": { + "line": 13, + "column": 7 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "binding": { + "type": "ObjectPattern", + "start": 213, + "end": 221, + "loc": { + "start": { + "line": 13, + "column": 13 + }, + "end": { + "line": 13, + "column": 21 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 215, + "end": 216, + "loc": { + "start": { + "line": 13, + "column": 15 + }, + "end": { + "line": 13, + "column": 16 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 215, + "end": 216, + "loc": { + "start": { + "line": 13, + "column": 15 + }, + "end": { + "line": 13, + "column": 16 + }, + "identifierName": "a" + }, + "name": "a" + }, + "value": { + "type": "Identifier", + "start": 215, + "end": 216, + "loc": { + "start": { + "line": 13, + "column": 15 + }, + "end": { + "line": 13, + "column": 16 + }, + "identifierName": "a" + }, + "name": "a" + }, + "extra": { + "shorthand": true + } + }, + { + "type": "ObjectProperty", + "start": 218, + "end": 219, + "loc": { + "start": { + "line": 13, + "column": 18 + }, + "end": { + "line": 13, + "column": 19 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 218, + "end": 219, + "loc": { + "start": { + "line": 13, + "column": 18 + }, + "end": { + "line": 13, + "column": 19 + }, + "identifierName": "b" + }, + "name": "b" + }, + "value": { + "type": "Identifier", + "start": 218, + "end": 219, + "loc": { + "start": { + "line": 13, + "column": 18 + }, + "end": { + "line": 13, + "column": 19 + }, + "identifierName": "b" + }, + "name": "b" + }, + "extra": { + "shorthand": true + } + } + ] + }, + "consequent": { + "type": "ExpressionStatement", + "start": 223, + "end": 228, + "loc": { + "start": { + "line": 13, + "column": 23 + }, + "end": { + "line": 13, + "column": 28 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 223, + "end": 228, + "loc": { + "start": { + "line": 13, + "column": 23 + }, + "end": { + "line": 13, + "column": 28 + } + }, + "left": { + "type": "Identifier", + "start": 223, + "end": 224, + "loc": { + "start": { + "line": 13, + "column": 23 + }, + "end": { + "line": 13, + "column": 24 + }, + "identifierName": "a" + }, + "name": "a" + }, + "operator": "+", + "right": { + "type": "Identifier", + "start": 227, + "end": 228, + "loc": { + "start": { + "line": 13, + "column": 27 + }, + "end": { + "line": 13, + "column": 28 + }, + "identifierName": "b" + }, + "name": "b" + } + } + } + }, + { + "type": "MatchCase", + "start": 231, + "end": 265, + "loc": { + "start": { + "line": 14, + "column": 2 + }, + "end": { + "line": 14, + "column": 36 + } + }, + "test": { + "type": "Identifier", + "start": 233, + "end": 236, + "loc": { + "start": { + "line": 14, + "column": 4 + }, + "end": { + "line": 14, + "column": 7 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "binding": { + "type": "ObjectPattern", + "start": 242, + "end": 254, + "loc": { + "start": { + "line": 14, + "column": 13 + }, + "end": { + "line": 14, + "column": 25 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 244, + "end": 245, + "loc": { + "start": { + "line": 14, + "column": 15 + }, + "end": { + "line": 14, + "column": 16 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 244, + "end": 245, + "loc": { + "start": { + "line": 14, + "column": 15 + }, + "end": { + "line": 14, + "column": 16 + }, + "identifierName": "a" + }, + "name": "a" + }, + "value": { + "type": "Identifier", + "start": 244, + "end": 245, + "loc": { + "start": { + "line": 14, + "column": 15 + }, + "end": { + "line": 14, + "column": 16 + }, + "identifierName": "a" + }, + "name": "a" + }, + "extra": { + "shorthand": true + } + }, + { + "type": "ObjectProperty", + "start": 247, + "end": 252, + "loc": { + "start": { + "line": 14, + "column": 18 + }, + "end": { + "line": 14, + "column": 23 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 247, + "end": 248, + "loc": { + "start": { + "line": 14, + "column": 18 + }, + "end": { + "line": 14, + "column": 19 + }, + "identifierName": "b" + }, + "name": "b" + }, + "value": { + "type": "AssignmentPattern", + "start": 247, + "end": 252, + "loc": { + "start": { + "line": 14, + "column": 18 + }, + "end": { + "line": 14, + "column": 23 + } + }, + "left": { + "type": "Identifier", + "start": 247, + "end": 248, + "loc": { + "start": { + "line": 14, + "column": 18 + }, + "end": { + "line": 14, + "column": 19 + }, + "identifierName": "b" + }, + "name": "b" + }, + "right": { + "type": "NumericLiteral", + "start": 251, + "end": 252, + "loc": { + "start": { + "line": 14, + "column": 22 + }, + "end": { + "line": 14, + "column": 23 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + }, + "extra": { + "shorthand": true + } + } + ] + }, + "consequent": { + "type": "ExpressionStatement", + "start": 256, + "end": 265, + "loc": { + "start": { + "line": 14, + "column": 27 + }, + "end": { + "line": 14, + "column": 36 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 256, + "end": 265, + "loc": { + "start": { + "line": 14, + "column": 27 + }, + "end": { + "line": 14, + "column": 36 + } + }, + "left": { + "type": "BinaryExpression", + "start": 256, + "end": 261, + "loc": { + "start": { + "line": 14, + "column": 27 + }, + "end": { + "line": 14, + "column": 32 + } + }, + "left": { + "type": "Identifier", + "start": 256, + "end": 257, + "loc": { + "start": { + "line": 14, + "column": 27 + }, + "end": { + "line": 14, + "column": 28 + }, + "identifierName": "a" + }, + "name": "a" + }, + "operator": "+", + "right": { + "type": "Identifier", + "start": 260, + "end": 261, + "loc": { + "start": { + "line": 14, + "column": 31 + }, + "end": { + "line": 14, + "column": 32 + }, + "identifierName": "b" + }, + "name": "b" + } + }, + "operator": "-", + "right": { + "type": "NumericLiteral", + "start": 264, + "end": 265, + "loc": { + "start": { + "line": 14, + "column": 35 + }, + "end": { + "line": 14, + "column": 36 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + } + } + }, + { + "type": "MatchCase", + "start": 268, + "end": 310, + "loc": { + "start": { + "line": 15, + "column": 2 + }, + "end": { + "line": 15, + "column": 44 + } + }, + "test": { + "type": "Identifier", + "start": 270, + "end": 273, + "loc": { + "start": { + "line": 15, + "column": 4 + }, + "end": { + "line": 15, + "column": 7 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "binding": { + "type": "ObjectPattern", + "start": 279, + "end": 290, + "loc": { + "start": { + "line": 15, + "column": 13 + }, + "end": { + "line": 15, + "column": 24 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 281, + "end": 282, + "loc": { + "start": { + "line": 15, + "column": 15 + }, + "end": { + "line": 15, + "column": 16 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 281, + "end": 282, + "loc": { + "start": { + "line": 15, + "column": 15 + }, + "end": { + "line": 15, + "column": 16 + }, + "identifierName": "a" + }, + "name": "a" + }, + "value": { + "type": "Identifier", + "start": 281, + "end": 282, + "loc": { + "start": { + "line": 15, + "column": 15 + }, + "end": { + "line": 15, + "column": 16 + }, + "identifierName": "a" + }, + "name": "a" + }, + "extra": { + "shorthand": true + } + }, + { + "type": "RestProperty", + "start": 284, + "end": 288, + "loc": { + "start": { + "line": 15, + "column": 18 + }, + "end": { + "line": 15, + "column": 22 + } + }, + "argument": { + "type": "Identifier", + "start": 287, + "end": 288, + "loc": { + "start": { + "line": 15, + "column": 21 + }, + "end": { + "line": 15, + "column": 22 + }, + "identifierName": "c" + }, + "name": "c" + } + } + ] + }, + "consequent": { + "type": "ExpressionStatement", + "start": 292, + "end": 310, + "loc": { + "start": { + "line": 15, + "column": 26 + }, + "end": { + "line": 15, + "column": 44 + } + }, + "expression": { + "type": "CallExpression", + "start": 292, + "end": 310, + "loc": { + "start": { + "line": 15, + "column": 26 + }, + "end": { + "line": 15, + "column": 44 + } + }, + "callee": { + "type": "MemberExpression", + "start": 292, + "end": 306, + "loc": { + "start": { + "line": 15, + "column": 26 + }, + "end": { + "line": 15, + "column": 40 + } + }, + "object": { + "type": "ArrayExpression", + "start": 292, + "end": 301, + "loc": { + "start": { + "line": 15, + "column": 26 + }, + "end": { + "line": 15, + "column": 35 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 293, + "end": 294, + "loc": { + "start": { + "line": 15, + "column": 27 + }, + "end": { + "line": 15, + "column": 28 + }, + "identifierName": "a" + }, + "name": "a" + }, + { + "type": "Identifier", + "start": 296, + "end": 297, + "loc": { + "start": { + "line": 15, + "column": 30 + }, + "end": { + "line": 15, + "column": 31 + }, + "identifierName": "b" + }, + "name": "b" + }, + { + "type": "Identifier", + "start": 299, + "end": 300, + "loc": { + "start": { + "line": 15, + "column": 33 + }, + "end": { + "line": 15, + "column": 34 + }, + "identifierName": "c" + }, + "name": "c" + } + ] + }, + "property": { + "type": "Identifier", + "start": 302, + "end": 306, + "loc": { + "start": { + "line": 15, + "column": 36 + }, + "end": { + "line": 15, + "column": 40 + }, + "identifierName": "join" + }, + "name": "join" + }, + "computed": false + }, + "arguments": [ + { + "type": "StringLiteral", + "start": 307, + "end": 309, + "loc": { + "start": { + "line": 15, + "column": 41 + }, + "end": { + "line": 15, + "column": 43 + } + }, + "extra": { + "rawValue": "", + "raw": "''" + }, + "value": "" + } + ] + } + } + }, + { + "type": "MatchCase", + "start": 313, + "end": 374, + "loc": { + "start": { + "line": 16, + "column": 2 + }, + "end": { + "line": 17, + "column": 22 + } + }, + "test": { + "type": "Identifier", + "start": 315, + "end": 318, + "loc": { + "start": { + "line": 16, + "column": 4 + }, + "end": { + "line": 16, + "column": 7 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "binding": { + "type": "ObjectPattern", + "start": 324, + "end": 350, + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 39 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 325, + "end": 338, + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 27 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 325, + "end": 326, + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 15 + }, + "identifierName": "a" + }, + "name": "a" + }, + "value": { + "type": "ObjectPattern", + "start": 327, + "end": 338, + "loc": { + "start": { + "line": 16, + "column": 16 + }, + "end": { + "line": 16, + "column": 27 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 328, + "end": 329, + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 18 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 328, + "end": 329, + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 18 + }, + "identifierName": "b" + }, + "name": "b" + }, + "value": { + "type": "Identifier", + "start": 328, + "end": 329, + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 18 + }, + "identifierName": "b" + }, + "name": "b" + }, + "extra": { + "shorthand": true + } + }, + { + "type": "ObjectProperty", + "start": 330, + "end": 337, + "loc": { + "start": { + "line": 16, + "column": 19 + }, + "end": { + "line": 16, + "column": 26 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 330, + "end": 331, + "loc": { + "start": { + "line": 16, + "column": 19 + }, + "end": { + "line": 16, + "column": 20 + }, + "identifierName": "d" + }, + "name": "d" + }, + "value": { + "type": "AssignmentPattern", + "start": 330, + "end": 337, + "loc": { + "start": { + "line": 16, + "column": 19 + }, + "end": { + "line": 16, + "column": 26 + } + }, + "left": { + "type": "Identifier", + "start": 330, + "end": 331, + "loc": { + "start": { + "line": 16, + "column": 19 + }, + "end": { + "line": 16, + "column": 20 + }, + "identifierName": "d" + }, + "name": "d" + }, + "right": { + "type": "StringLiteral", + "start": 334, + "end": 337, + "loc": { + "start": { + "line": 16, + "column": 23 + }, + "end": { + "line": 16, + "column": 26 + } + }, + "extra": { + "rawValue": "e", + "raw": "'e'" + }, + "value": "e" + } + }, + "extra": { + "shorthand": true + } + } + ] + } + }, + { + "type": "ObjectProperty", + "start": 339, + "end": 349, + "loc": { + "start": { + "line": 16, + "column": 28 + }, + "end": { + "line": 16, + "column": 38 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 339, + "end": 340, + "loc": { + "start": { + "line": 16, + "column": 28 + }, + "end": { + "line": 16, + "column": 29 + }, + "identifierName": "f" + }, + "name": "f" + }, + "value": { + "type": "ObjectPattern", + "start": 341, + "end": 349, + "loc": { + "start": { + "line": 16, + "column": 30 + }, + "end": { + "line": 16, + "column": 38 + } + }, + "properties": [ + { + "type": "RestProperty", + "start": 343, + "end": 347, + "loc": { + "start": { + "line": 16, + "column": 32 + }, + "end": { + "line": 16, + "column": 36 + } + }, + "argument": { + "type": "Identifier", + "start": 346, + "end": 347, + "loc": { + "start": { + "line": 16, + "column": 35 + }, + "end": { + "line": 16, + "column": 36 + }, + "identifierName": "g" + }, + "name": "g" + } + } + ] + } + } + ] + }, + "consequent": { + "type": "BlockStatement", + "start": 350, + "end": 374, + "loc": { + "start": { + "line": 16, + "column": 39 + }, + "end": { + "line": 17, + "column": 22 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 356, + "end": 374, + "loc": { + "start": { + "line": 17, + "column": 4 + }, + "end": { + "line": 17, + "column": 22 + } + }, + "expression": { + "type": "CallExpression", + "start": 356, + "end": 374, + "loc": { + "start": { + "line": 17, + "column": 4 + }, + "end": { + "line": 17, + "column": 22 + } + }, + "callee": { + "type": "MemberExpression", + "start": 356, + "end": 370, + "loc": { + "start": { + "line": 17, + "column": 4 + }, + "end": { + "line": 17, + "column": 18 + } + }, + "object": { + "type": "ArrayExpression", + "start": 356, + "end": 365, + "loc": { + "start": { + "line": 17, + "column": 4 + }, + "end": { + "line": 17, + "column": 13 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 357, + "end": 358, + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 6 + }, + "identifierName": "b" + }, + "name": "b" + }, + { + "type": "Identifier", + "start": 360, + "end": 361, + "loc": { + "start": { + "line": 17, + "column": 8 + }, + "end": { + "line": 17, + "column": 9 + }, + "identifierName": "d" + }, + "name": "d" + }, + { + "type": "Identifier", + "start": 363, + "end": 364, + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 12 + }, + "identifierName": "g" + }, + "name": "g" + } + ] + }, + "property": { + "type": "Identifier", + "start": 366, + "end": 370, + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 17, + "column": 18 + }, + "identifierName": "join" + }, + "name": "join" + }, + "computed": false + }, + "arguments": [ + { + "type": "StringLiteral", + "start": 371, + "end": 373, + "loc": { + "start": { + "line": 17, + "column": 19 + }, + "end": { + "line": 17, + "column": 21 + } + }, + "extra": { + "rawValue": "", + "raw": "''" + }, + "value": "" + } + ] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + ] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/match/destructuring-obj/options.json b/test/fixtures/lightscript/match/destructuring-obj/options.json new file mode 100644 index 0000000000..3ebf2619d6 --- /dev/null +++ b/test/fixtures/lightscript/match/destructuring-obj/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["objectRestSpread", "lightscript", "jsx", "flow"] +} diff --git a/test/fixtures/lightscript/match/discriminant-expression-as/actual.js b/test/fixtures/lightscript/match/discriminant-expression-as/actual.js new file mode 100644 index 0000000000..ee19855cfa --- /dev/null +++ b/test/fixtures/lightscript/match/discriminant-expression-as/actual.js @@ -0,0 +1,3 @@ +a = match (1, 2) + 3, a = 4 as foo: + | 2: "eq two" + | else: "some other thing" diff --git a/test/fixtures/lightscript/match/discriminant-expression-as/expected.json b/test/fixtures/lightscript/match/discriminant-expression-as/expected.json new file mode 100644 index 0000000000..9f80fef74c --- /dev/null +++ b/test/fixtures/lightscript/match/discriminant-expression-as/expected.json @@ -0,0 +1,424 @@ +{ + "type": "File", + "start": 0, + "end": 80, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 80, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "sourceType": "script", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 80, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "kind": "const", + "extra": { + "implicit": true + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 0, + "end": 80, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "id": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "a" + }, + "name": "a" + }, + "init": { + "type": "MatchExpression", + "start": 4, + "end": 80, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "discriminant": { + "type": "SequenceExpression", + "start": 10, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "expressions": [ + { + "type": "BinaryExpression", + "start": 10, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "left": { + "type": "SequenceExpression", + "start": 11, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "expressions": [ + { + "type": "NumericLiteral", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + }, + { + "type": "NumericLiteral", + "start": 14, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + ], + "extra": { + "parenthesized": true, + "parenStart": 10 + } + }, + "operator": "+", + "right": { + "type": "NumericLiteral", + "start": 19, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "extra": { + "rawValue": 3, + "raw": "3" + }, + "value": 3 + } + }, + { + "type": "AssignmentExpression", + "start": 22, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 22, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 23 + }, + "identifierName": "a" + }, + "name": "a" + }, + "right": { + "type": "NumericLiteral", + "start": 26, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "extra": { + "rawValue": 4, + "raw": "4" + }, + "value": 4 + }, + "isNowAssign": false + } + ] + }, + "alias": { + "type": "Identifier", + "start": 31, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 34 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "cases": [ + { + "type": "MatchCase", + "start": 38, + "end": 51, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "test": { + "type": "NumericLiteral", + "start": 40, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + }, + "consequent": { + "type": "ExpressionStatement", + "start": 43, + "end": 51, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "expression": { + "type": "StringLiteral", + "start": 43, + "end": 51, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "extra": { + "rawValue": "eq two", + "raw": "\"eq two\"" + }, + "value": "eq two" + } + } + }, + { + "type": "MatchCase", + "start": 54, + "end": 80, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "test": { + "type": "MatchElse", + "start": 56, + "end": 60, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 8 + } + } + }, + "consequent": { + "type": "ExpressionStatement", + "start": 62, + "end": 80, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "expression": { + "type": "StringLiteral", + "start": 62, + "end": 80, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "extra": { + "rawValue": "some other thing", + "raw": "\"some other thing\"" + }, + "value": "some other thing" + } + } + } + ] + } + } + ] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/match/discriminant-expression/actual.js b/test/fixtures/lightscript/match/discriminant-expression/actual.js new file mode 100644 index 0000000000..c8f1e5a4bf --- /dev/null +++ b/test/fixtures/lightscript/match/discriminant-expression/actual.js @@ -0,0 +1,3 @@ +a = match (1, 2) + 3, a = 4: + | 2: "eq two" + | else: "some other thing" diff --git a/test/fixtures/lightscript/match/discriminant-expression/expected.json b/test/fixtures/lightscript/match/discriminant-expression/expected.json new file mode 100644 index 0000000000..30821824cf --- /dev/null +++ b/test/fixtures/lightscript/match/discriminant-expression/expected.json @@ -0,0 +1,407 @@ +{ + "type": "File", + "start": 0, + "end": 73, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 73, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "sourceType": "script", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 73, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "kind": "const", + "extra": { + "implicit": true + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 0, + "end": 73, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "id": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "a" + }, + "name": "a" + }, + "init": { + "type": "MatchExpression", + "start": 4, + "end": 73, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "discriminant": { + "type": "SequenceExpression", + "start": 10, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "expressions": [ + { + "type": "BinaryExpression", + "start": 10, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "left": { + "type": "SequenceExpression", + "start": 11, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "expressions": [ + { + "type": "NumericLiteral", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + }, + { + "type": "NumericLiteral", + "start": 14, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + ], + "extra": { + "parenthesized": true, + "parenStart": 10 + } + }, + "operator": "+", + "right": { + "type": "NumericLiteral", + "start": 19, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "extra": { + "rawValue": 3, + "raw": "3" + }, + "value": 3 + } + }, + { + "type": "AssignmentExpression", + "start": 22, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 22, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 23 + }, + "identifierName": "a" + }, + "name": "a" + }, + "right": { + "type": "NumericLiteral", + "start": 26, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "extra": { + "rawValue": 4, + "raw": "4" + }, + "value": 4 + }, + "isNowAssign": false + } + ] + }, + "cases": [ + { + "type": "MatchCase", + "start": 31, + "end": 44, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "test": { + "type": "NumericLiteral", + "start": 33, + "end": 34, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + }, + "consequent": { + "type": "ExpressionStatement", + "start": 36, + "end": 44, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "expression": { + "type": "StringLiteral", + "start": 36, + "end": 44, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "extra": { + "rawValue": "eq two", + "raw": "\"eq two\"" + }, + "value": "eq two" + } + } + }, + { + "type": "MatchCase", + "start": 47, + "end": 73, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "test": { + "type": "MatchElse", + "start": 49, + "end": 53, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 8 + } + } + }, + "consequent": { + "type": "ExpressionStatement", + "start": 55, + "end": 73, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "expression": { + "type": "StringLiteral", + "start": 55, + "end": 73, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "extra": { + "rawValue": "some other thing", + "raw": "\"some other thing\"" + }, + "value": "some other thing" + } + } + } + ] + } + } + ] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/match/else-before-case-illegal/actual.js b/test/fixtures/lightscript/match/else-before-case-illegal/actual.js new file mode 100644 index 0000000000..43a2e7dad9 --- /dev/null +++ b/test/fixtures/lightscript/match/else-before-case-illegal/actual.js @@ -0,0 +1,3 @@ +match x: + | else: "some other thing" + | a: b diff --git a/test/fixtures/lightscript/match/else-before-case-illegal/options.json b/test/fixtures/lightscript/match/else-before-case-illegal/options.json new file mode 100644 index 0000000000..ddcb18af96 --- /dev/null +++ b/test/fixtures/lightscript/match/else-before-case-illegal/options.json @@ -0,0 +1,3 @@ +{ + "throws": "`else` must be last case. (3:2)" +} diff --git a/test/fixtures/lightscript/match/else-solo/actual.js b/test/fixtures/lightscript/match/else-solo/actual.js new file mode 100644 index 0000000000..600d6e2496 --- /dev/null +++ b/test/fixtures/lightscript/match/else-solo/actual.js @@ -0,0 +1,2 @@ +match x: + | else: "some other thing" diff --git a/test/fixtures/lightscript/match/else-solo/expected.json b/test/fixtures/lightscript/match/else-solo/expected.json new file mode 100644 index 0000000000..486d864b11 --- /dev/null +++ b/test/fixtures/lightscript/match/else-solo/expected.json @@ -0,0 +1,133 @@ +{ + "type": "File", + "start": 0, + "end": 37, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 28 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 37, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 28 + } + }, + "sourceType": "script", + "body": [ + { + "type": "MatchStatement", + "start": 0, + "end": 37, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 28 + } + }, + "discriminant": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "x" + }, + "name": "x" + }, + "cases": [ + { + "type": "MatchCase", + "start": 11, + "end": 37, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 28 + } + }, + "test": { + "type": "MatchElse", + "start": 13, + "end": 17, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 8 + } + } + }, + "consequent": { + "type": "ExpressionStatement", + "start": 19, + "end": 37, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 28 + } + }, + "expression": { + "type": "StringLiteral", + "start": 19, + "end": 37, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 28 + } + }, + "extra": { + "rawValue": "some other thing", + "raw": "\"some other thing\"" + }, + "value": "some other thing" + } + } + } + ] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/match/else/actual.js b/test/fixtures/lightscript/match/else/actual.js new file mode 100644 index 0000000000..321d37ebcb --- /dev/null +++ b/test/fixtures/lightscript/match/else/actual.js @@ -0,0 +1,3 @@ +match x: + | a: b + | else: c diff --git a/test/fixtures/lightscript/match/else/expected.json b/test/fixtures/lightscript/match/else/expected.json new file mode 100644 index 0000000000..2afdb8cf87 --- /dev/null +++ b/test/fixtures/lightscript/match/else/expected.json @@ -0,0 +1,194 @@ +{ + "type": "File", + "start": 0, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "sourceType": "script", + "body": [ + { + "type": "MatchStatement", + "start": 0, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "discriminant": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "x" + }, + "name": "x" + }, + "cases": [ + { + "type": "MatchCase", + "start": 11, + "end": 17, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "test": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + }, + "identifierName": "a" + }, + "name": "a" + }, + "consequent": { + "type": "ExpressionStatement", + "start": 16, + "end": 17, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "expression": { + "type": "Identifier", + "start": 16, + "end": 17, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + }, + "identifierName": "b" + }, + "name": "b" + } + } + }, + { + "type": "MatchCase", + "start": 20, + "end": 29, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "test": { + "type": "MatchElse", + "start": 22, + "end": 26, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 8 + } + } + }, + "consequent": { + "type": "ExpressionStatement", + "start": 28, + "end": 29, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "expression": { + "type": "Identifier", + "start": 28, + "end": 29, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + }, + "identifierName": "c" + }, + "name": "c" + } + } + } + ] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/match/expression-break-illegal/actual.js b/test/fixtures/lightscript/match/expression-break-illegal/actual.js new file mode 100644 index 0000000000..1b7891b8da --- /dev/null +++ b/test/fixtures/lightscript/match/expression-break-illegal/actual.js @@ -0,0 +1,3 @@ +while false: + x = match y: + | 1: break diff --git a/test/fixtures/lightscript/match/expression-break-illegal/options.json b/test/fixtures/lightscript/match/expression-break-illegal/options.json new file mode 100644 index 0000000000..12bf86d926 --- /dev/null +++ b/test/fixtures/lightscript/match/expression-break-illegal/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unsyntactic break (3:9)" +} diff --git a/test/fixtures/lightscript/match/expression-return-illegal/actual.js b/test/fixtures/lightscript/match/expression-return-illegal/actual.js new file mode 100644 index 0000000000..bbfcefa258 --- /dev/null +++ b/test/fixtures/lightscript/match/expression-return-illegal/actual.js @@ -0,0 +1,5 @@ +f() -> + x = match y: + | 1: + a + return diff --git a/test/fixtures/lightscript/match/expression-return-illegal/options.json b/test/fixtures/lightscript/match/expression-return-illegal/options.json new file mode 100644 index 0000000000..917b526256 --- /dev/null +++ b/test/fixtures/lightscript/match/expression-return-illegal/options.json @@ -0,0 +1,3 @@ +{ + "throws": "'return' outside of function (5:6)" +} diff --git a/test/fixtures/lightscript/match/illegal-arrow-fn/actual.js b/test/fixtures/lightscript/match/illegal-arrow-fn/actual.js new file mode 100644 index 0000000000..72885b53a2 --- /dev/null +++ b/test/fixtures/lightscript/match/illegal-arrow-fn/actual.js @@ -0,0 +1,2 @@ +match x: + | true and -> 1: "not allowed" diff --git a/test/fixtures/lightscript/match/illegal-arrow-fn/options.json b/test/fixtures/lightscript/match/illegal-arrow-fn/options.json new file mode 100644 index 0000000000..84c1ac1adf --- /dev/null +++ b/test/fixtures/lightscript/match/illegal-arrow-fn/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Cannot match on functions. (2:13)" +} diff --git a/test/fixtures/lightscript/match/illegal-assignment-expression/actual.js b/test/fixtures/lightscript/match/illegal-assignment-expression/actual.js new file mode 100644 index 0000000000..761e3814fa --- /dev/null +++ b/test/fixtures/lightscript/match/illegal-assignment-expression/actual.js @@ -0,0 +1,3 @@ +var a +match x: + | true and a = 1: "not allowed" diff --git a/test/fixtures/lightscript/match/illegal-assignment-expression/options.json b/test/fixtures/lightscript/match/illegal-assignment-expression/options.json new file mode 100644 index 0000000000..412c2d36a1 --- /dev/null +++ b/test/fixtures/lightscript/match/illegal-assignment-expression/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected { (3:15)" +} diff --git a/test/fixtures/lightscript/match/illegal-destructure-and-with/actual.js b/test/fixtures/lightscript/match/illegal-destructure-and-with/actual.js new file mode 100644 index 0000000000..5a536fa493 --- /dev/null +++ b/test/fixtures/lightscript/match/illegal-destructure-and-with/actual.js @@ -0,0 +1,4 @@ +match x: + // error must be thrown at the compiler level + // TODO: consider using lodash `isMatch` for this. + | { a } with { a }: "not allowed" diff --git a/test/fixtures/lightscript/match/illegal-destructure-and-with/expected.json b/test/fixtures/lightscript/match/illegal-destructure-and-with/expected.json new file mode 100644 index 0000000000..1de5fe5b6a --- /dev/null +++ b/test/fixtures/lightscript/match/illegal-destructure-and-with/expected.json @@ -0,0 +1,333 @@ +{ + "type": "File", + "start": 0, + "end": 145, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 35 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 145, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 35 + } + }, + "sourceType": "script", + "body": [ + { + "type": "MatchStatement", + "start": 0, + "end": 145, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 35 + } + }, + "discriminant": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "x" + }, + "name": "x" + }, + "cases": [ + { + "type": "MatchCase", + "start": 112, + "end": 145, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 35 + } + }, + "test": { + "type": "ObjectExpression", + "start": 114, + "end": 119, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 9 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 116, + "end": 117, + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 7 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 116, + "end": 117, + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 7 + }, + "identifierName": "a" + }, + "name": "a", + "leadingComments": null + }, + "value": { + "type": "Identifier", + "start": 116, + "end": 117, + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 7 + }, + "identifierName": "a" + }, + "name": "a" + }, + "leadingComments": null, + "extra": { + "shorthand": true + } + } + ], + "leadingComments": null + }, + "binding": { + "type": "ObjectPattern", + "start": 125, + "end": 130, + "loc": { + "start": { + "line": 4, + "column": 15 + }, + "end": { + "line": 4, + "column": 20 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 127, + "end": 128, + "loc": { + "start": { + "line": 4, + "column": 17 + }, + "end": { + "line": 4, + "column": 18 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 127, + "end": 128, + "loc": { + "start": { + "line": 4, + "column": 17 + }, + "end": { + "line": 4, + "column": 18 + }, + "identifierName": "a" + }, + "name": "a" + }, + "value": { + "type": "Identifier", + "start": 127, + "end": 128, + "loc": { + "start": { + "line": 4, + "column": 17 + }, + "end": { + "line": 4, + "column": 18 + }, + "identifierName": "a" + }, + "name": "a" + }, + "extra": { + "shorthand": true + } + } + ] + }, + "consequent": { + "type": "ExpressionStatement", + "start": 132, + "end": 145, + "loc": { + "start": { + "line": 4, + "column": 22 + }, + "end": { + "line": 4, + "column": 35 + } + }, + "expression": { + "type": "StringLiteral", + "start": 132, + "end": 145, + "loc": { + "start": { + "line": 4, + "column": 22 + }, + "end": { + "line": 4, + "column": 35 + } + }, + "extra": { + "rawValue": "not allowed", + "raw": "\"not allowed\"" + }, + "value": "not allowed" + } + }, + "leadingComments": [ + { + "type": "CommentLine", + "value": " error must be thrown at the compiler level", + "start": 11, + "end": 56, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 47 + } + } + }, + { + "type": "CommentLine", + "value": " TODO: consider using lodash `isMatch` for this.", + "start": 59, + "end": 109, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 52 + } + } + } + ] + } + ] + } + ], + "directives": [] + }, + "comments": [ + { + "type": "CommentLine", + "value": " error must be thrown at the compiler level", + "start": 11, + "end": 56, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 47 + } + } + }, + { + "type": "CommentLine", + "value": " TODO: consider using lodash `isMatch` for this.", + "start": 59, + "end": 109, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 52 + } + } + } + ] +} \ No newline at end of file diff --git a/test/fixtures/lightscript/match/illegal-fn-expression/actual.js b/test/fixtures/lightscript/match/illegal-fn-expression/actual.js new file mode 100644 index 0000000000..e16c0c943c --- /dev/null +++ b/test/fixtures/lightscript/match/illegal-fn-expression/actual.js @@ -0,0 +1,2 @@ +match x: + | true and function(){}: "not allowed" diff --git a/test/fixtures/lightscript/match/illegal-fn-expression/options.json b/test/fixtures/lightscript/match/illegal-fn-expression/options.json new file mode 100644 index 0000000000..84c1ac1adf --- /dev/null +++ b/test/fixtures/lightscript/match/illegal-fn-expression/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Cannot match on functions. (2:13)" +} diff --git a/test/fixtures/lightscript/match/illegal-nested-match-in-test/actual.js b/test/fixtures/lightscript/match/illegal-nested-match-in-test/actual.js new file mode 100644 index 0000000000..a731d498b4 --- /dev/null +++ b/test/fixtures/lightscript/match/illegal-nested-match-in-test/actual.js @@ -0,0 +1,2 @@ +match x: + | true and match y {}: "not allowed" diff --git a/test/fixtures/lightscript/match/illegal-nested-match-in-test/options.json b/test/fixtures/lightscript/match/illegal-nested-match-in-test/options.json new file mode 100644 index 0000000000..f45f06d72e --- /dev/null +++ b/test/fixtures/lightscript/match/illegal-nested-match-in-test/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token (2:13)" +} diff --git a/test/fixtures/lightscript/match/illegal-no-cases/actual.js b/test/fixtures/lightscript/match/illegal-no-cases/actual.js new file mode 100644 index 0000000000..ef24b83b9d --- /dev/null +++ b/test/fixtures/lightscript/match/illegal-no-cases/actual.js @@ -0,0 +1 @@ +match x: diff --git a/test/fixtures/lightscript/match/illegal-no-cases/options.json b/test/fixtures/lightscript/match/illegal-no-cases/options.json new file mode 100644 index 0000000000..fbe5418297 --- /dev/null +++ b/test/fixtures/lightscript/match/illegal-no-cases/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected | (1:8)" +} diff --git a/test/fixtures/lightscript/match/illegal-not-call/actual.js b/test/fixtures/lightscript/match/illegal-not-call/actual.js new file mode 100644 index 0000000000..a9407abf3c --- /dev/null +++ b/test/fixtures/lightscript/match/illegal-not-call/actual.js @@ -0,0 +1,2 @@ +match x: + | f(!): false diff --git a/test/fixtures/lightscript/match/illegal-not-call/options.json b/test/fixtures/lightscript/match/illegal-not-call/options.json new file mode 100644 index 0000000000..4e84114247 --- /dev/null +++ b/test/fixtures/lightscript/match/illegal-not-call/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token (2:7)" +} diff --git a/test/fixtures/lightscript/match/illegal-sequence-expression/actual.js b/test/fixtures/lightscript/match/illegal-sequence-expression/actual.js new file mode 100644 index 0000000000..f720876559 --- /dev/null +++ b/test/fixtures/lightscript/match/illegal-sequence-expression/actual.js @@ -0,0 +1,2 @@ +match x: + | true and 1, 1: "not allowed" diff --git a/test/fixtures/lightscript/match/illegal-sequence-expression/options.json b/test/fixtures/lightscript/match/illegal-sequence-expression/options.json new file mode 100644 index 0000000000..0751a21aef --- /dev/null +++ b/test/fixtures/lightscript/match/illegal-sequence-expression/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected { (2:14)" +} diff --git a/test/fixtures/lightscript/match/illegal-ternary/actual.js b/test/fixtures/lightscript/match/illegal-ternary/actual.js new file mode 100644 index 0000000000..49cf11604e --- /dev/null +++ b/test/fixtures/lightscript/match/illegal-ternary/actual.js @@ -0,0 +1,2 @@ +match x: + | true and true ? 1 : 0: "not allowed" diff --git a/test/fixtures/lightscript/match/illegal-ternary/options.json b/test/fixtures/lightscript/match/illegal-ternary/options.json new file mode 100644 index 0000000000..72ffe6cb7d --- /dev/null +++ b/test/fixtures/lightscript/match/illegal-ternary/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected { (2:18)" +} diff --git a/test/fixtures/lightscript/match/in-assignment/actual.js b/test/fixtures/lightscript/match/in-assignment/actual.js new file mode 100644 index 0000000000..aa9ea91eea --- /dev/null +++ b/test/fixtures/lightscript/match/in-assignment/actual.js @@ -0,0 +1,3 @@ +a = match x: + | 2: "eq two" + | else: "some other thing" diff --git a/test/fixtures/lightscript/match/in-assignment/expected.json b/test/fixtures/lightscript/match/in-assignment/expected.json new file mode 100644 index 0000000000..0150cc4179 --- /dev/null +++ b/test/fixtures/lightscript/match/in-assignment/expected.json @@ -0,0 +1,256 @@ +{ + "type": "File", + "start": 0, + "end": 57, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 57, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "sourceType": "script", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 57, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "kind": "const", + "extra": { + "implicit": true + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 0, + "end": 57, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "id": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "a" + }, + "name": "a" + }, + "init": { + "type": "MatchExpression", + "start": 4, + "end": 57, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "discriminant": { + "type": "Identifier", + "start": 10, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + }, + "cases": [ + { + "type": "MatchCase", + "start": 15, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "test": { + "type": "NumericLiteral", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + }, + "consequent": { + "type": "ExpressionStatement", + "start": 20, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "expression": { + "type": "StringLiteral", + "start": 20, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "extra": { + "rawValue": "eq two", + "raw": "\"eq two\"" + }, + "value": "eq two" + } + } + }, + { + "type": "MatchCase", + "start": 31, + "end": 57, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "test": { + "type": "MatchElse", + "start": 33, + "end": 37, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 8 + } + } + }, + "consequent": { + "type": "ExpressionStatement", + "start": 39, + "end": 57, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "expression": { + "type": "StringLiteral", + "start": 39, + "end": 57, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "extra": { + "rawValue": "some other thing", + "raw": "\"some other thing\"" + }, + "value": "some other thing" + } + } + } + ] + } + } + ] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/match/jsx-result/actual.js b/test/fixtures/lightscript/match/jsx-result/actual.js new file mode 100644 index 0000000000..96ff088f19 --- /dev/null +++ b/test/fixtures/lightscript/match/jsx-result/actual.js @@ -0,0 +1,2 @@ +match x: + | y:
diff --git a/test/fixtures/lightscript/match/jsx-result/expected.json b/test/fixtures/lightscript/match/jsx-result/expected.json new file mode 100644 index 0000000000..f0e7cd06a5 --- /dev/null +++ b/test/fixtures/lightscript/match/jsx-result/expected.json @@ -0,0 +1,165 @@ +{ + "type": "File", + "start": 0, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "sourceType": "script", + "body": [ + { + "type": "MatchStatement", + "start": 0, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "discriminant": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "x" + }, + "name": "x" + }, + "cases": [ + { + "type": "MatchCase", + "start": 11, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "test": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + }, + "identifierName": "y" + }, + "name": "y" + }, + "consequent": { + "type": "ExpressionStatement", + "start": 16, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "expression": { + "type": "JSXElement", + "start": 16, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "openingElement": { + "type": "JSXOpeningElement", + "start": 16, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "attributes": [], + "name": { + "type": "JSXIdentifier", + "start": 17, + "end": 20, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "name": "div" + }, + "selfClosing": true + }, + "closingElement": null, + "children": [] + } + } + } + ] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/match/jsx-test-illegal/actual.js b/test/fixtures/lightscript/match/jsx-test-illegal/actual.js new file mode 100644 index 0000000000..e7b9d76c6a --- /dev/null +++ b/test/fixtures/lightscript/match/jsx-test-illegal/actual.js @@ -0,0 +1,2 @@ +match x: + |
: "does this make sense?" diff --git a/test/fixtures/lightscript/match/jsx-test-illegal/options.json b/test/fixtures/lightscript/match/jsx-test-illegal/options.json new file mode 100644 index 0000000000..b2f4797ad8 --- /dev/null +++ b/test/fixtures/lightscript/match/jsx-test-illegal/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token (2:4)" +} diff --git a/test/fixtures/lightscript/match/literals/actual.js b/test/fixtures/lightscript/match/literals/actual.js new file mode 100644 index 0000000000..dd7f054602 --- /dev/null +++ b/test/fixtures/lightscript/match/literals/actual.js @@ -0,0 +1,11 @@ +match x: + | 2: "two" + | "hello": "hi" + | /\w+/: "word" + | /\w+/ig: "word" + | +1: "equal to positive one" + | -1: "equal to negative one" + | null: "null" + | undefined: "undefined" + | true: "strict true" + | false: "strict false" diff --git a/test/fixtures/lightscript/match/literals/expected.json b/test/fixtures/lightscript/match/literals/expected.json new file mode 100644 index 0000000000..0b2f2ce487 --- /dev/null +++ b/test/fixtures/lightscript/match/literals/expected.json @@ -0,0 +1,792 @@ +{ + "type": "File", + "start": 0, + "end": 235, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 11, + "column": 25 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 235, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 11, + "column": 25 + } + }, + "sourceType": "script", + "body": [ + { + "type": "MatchStatement", + "start": 0, + "end": 235, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 11, + "column": 25 + } + }, + "discriminant": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "x" + }, + "name": "x" + }, + "cases": [ + { + "type": "MatchCase", + "start": 11, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "test": { + "type": "NumericLiteral", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + }, + "consequent": { + "type": "ExpressionStatement", + "start": 16, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "expression": { + "type": "StringLiteral", + "start": 16, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "extra": { + "rawValue": "two", + "raw": "\"two\"" + }, + "value": "two" + } + } + }, + { + "type": "MatchCase", + "start": 24, + "end": 39, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 17 + } + }, + "test": { + "type": "StringLiteral", + "start": 26, + "end": 33, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "extra": { + "rawValue": "hello", + "raw": "\"hello\"" + }, + "value": "hello" + }, + "consequent": { + "type": "ExpressionStatement", + "start": 35, + "end": 39, + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 17 + } + }, + "expression": { + "type": "StringLiteral", + "start": 35, + "end": 39, + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 17 + } + }, + "extra": { + "rawValue": "hi", + "raw": "\"hi\"" + }, + "value": "hi" + } + } + }, + { + "type": "MatchCase", + "start": 42, + "end": 57, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 17 + } + }, + "test": { + "type": "RegExpLiteral", + "start": 44, + "end": 49, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 9 + } + }, + "extra": { + "raw": "/\\w+/" + }, + "pattern": "\\w+", + "flags": "" + }, + "consequent": { + "type": "ExpressionStatement", + "start": 51, + "end": 57, + "loc": { + "start": { + "line": 4, + "column": 11 + }, + "end": { + "line": 4, + "column": 17 + } + }, + "expression": { + "type": "StringLiteral", + "start": 51, + "end": 57, + "loc": { + "start": { + "line": 4, + "column": 11 + }, + "end": { + "line": 4, + "column": 17 + } + }, + "extra": { + "rawValue": "word", + "raw": "\"word\"" + }, + "value": "word" + } + } + }, + { + "type": "MatchCase", + "start": 60, + "end": 77, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 19 + } + }, + "test": { + "type": "RegExpLiteral", + "start": 62, + "end": 69, + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 11 + } + }, + "extra": { + "raw": "/\\w+/ig" + }, + "pattern": "\\w+", + "flags": "ig" + }, + "consequent": { + "type": "ExpressionStatement", + "start": 71, + "end": 77, + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 19 + } + }, + "expression": { + "type": "StringLiteral", + "start": 71, + "end": 77, + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 19 + } + }, + "extra": { + "rawValue": "word", + "raw": "\"word\"" + }, + "value": "word" + } + } + }, + { + "type": "MatchCase", + "start": 80, + "end": 109, + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 31 + } + }, + "test": { + "type": "UnaryExpression", + "start": 82, + "end": 84, + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 6 + } + }, + "operator": "+", + "prefix": true, + "argument": { + "type": "NumericLiteral", + "start": 83, + "end": 84, + "loc": { + "start": { + "line": 6, + "column": 5 + }, + "end": { + "line": 6, + "column": 6 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + }, + "extra": { + "parenthesizedArgument": false + } + }, + "consequent": { + "type": "ExpressionStatement", + "start": 86, + "end": 109, + "loc": { + "start": { + "line": 6, + "column": 8 + }, + "end": { + "line": 6, + "column": 31 + } + }, + "expression": { + "type": "StringLiteral", + "start": 86, + "end": 109, + "loc": { + "start": { + "line": 6, + "column": 8 + }, + "end": { + "line": 6, + "column": 31 + } + }, + "extra": { + "rawValue": "equal to positive one", + "raw": "\"equal to positive one\"" + }, + "value": "equal to positive one" + } + } + }, + { + "type": "MatchCase", + "start": 112, + "end": 141, + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 31 + } + }, + "test": { + "type": "UnaryExpression", + "start": 114, + "end": 116, + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 6 + } + }, + "operator": "-", + "prefix": true, + "argument": { + "type": "NumericLiteral", + "start": 115, + "end": 116, + "loc": { + "start": { + "line": 7, + "column": 5 + }, + "end": { + "line": 7, + "column": 6 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + }, + "extra": { + "parenthesizedArgument": false + } + }, + "consequent": { + "type": "ExpressionStatement", + "start": 118, + "end": 141, + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 31 + } + }, + "expression": { + "type": "StringLiteral", + "start": 118, + "end": 141, + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 31 + } + }, + "extra": { + "rawValue": "equal to negative one", + "raw": "\"equal to negative one\"" + }, + "value": "equal to negative one" + } + } + }, + { + "type": "MatchCase", + "start": 144, + "end": 158, + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 16 + } + }, + "test": { + "type": "NullLiteral", + "start": 146, + "end": 150, + "loc": { + "start": { + "line": 8, + "column": 4 + }, + "end": { + "line": 8, + "column": 8 + } + } + }, + "consequent": { + "type": "ExpressionStatement", + "start": 152, + "end": 158, + "loc": { + "start": { + "line": 8, + "column": 10 + }, + "end": { + "line": 8, + "column": 16 + } + }, + "expression": { + "type": "StringLiteral", + "start": 152, + "end": 158, + "loc": { + "start": { + "line": 8, + "column": 10 + }, + "end": { + "line": 8, + "column": 16 + } + }, + "extra": { + "rawValue": "null", + "raw": "\"null\"" + }, + "value": "null" + } + } + }, + { + "type": "MatchCase", + "start": 161, + "end": 185, + "loc": { + "start": { + "line": 9, + "column": 2 + }, + "end": { + "line": 9, + "column": 26 + } + }, + "test": { + "type": "Identifier", + "start": 163, + "end": 172, + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 13 + }, + "identifierName": "undefined" + }, + "name": "undefined" + }, + "consequent": { + "type": "ExpressionStatement", + "start": 174, + "end": 185, + "loc": { + "start": { + "line": 9, + "column": 15 + }, + "end": { + "line": 9, + "column": 26 + } + }, + "expression": { + "type": "StringLiteral", + "start": 174, + "end": 185, + "loc": { + "start": { + "line": 9, + "column": 15 + }, + "end": { + "line": 9, + "column": 26 + } + }, + "extra": { + "rawValue": "undefined", + "raw": "\"undefined\"" + }, + "value": "undefined" + } + } + }, + { + "type": "MatchCase", + "start": 188, + "end": 209, + "loc": { + "start": { + "line": 10, + "column": 2 + }, + "end": { + "line": 10, + "column": 23 + } + }, + "test": { + "type": "BooleanLiteral", + "start": 190, + "end": 194, + "loc": { + "start": { + "line": 10, + "column": 4 + }, + "end": { + "line": 10, + "column": 8 + } + }, + "value": true + }, + "consequent": { + "type": "ExpressionStatement", + "start": 196, + "end": 209, + "loc": { + "start": { + "line": 10, + "column": 10 + }, + "end": { + "line": 10, + "column": 23 + } + }, + "expression": { + "type": "StringLiteral", + "start": 196, + "end": 209, + "loc": { + "start": { + "line": 10, + "column": 10 + }, + "end": { + "line": 10, + "column": 23 + } + }, + "extra": { + "rawValue": "strict true", + "raw": "\"strict true\"" + }, + "value": "strict true" + } + } + }, + { + "type": "MatchCase", + "start": 212, + "end": 235, + "loc": { + "start": { + "line": 11, + "column": 2 + }, + "end": { + "line": 11, + "column": 25 + } + }, + "test": { + "type": "BooleanLiteral", + "start": 214, + "end": 219, + "loc": { + "start": { + "line": 11, + "column": 4 + }, + "end": { + "line": 11, + "column": 9 + } + }, + "value": false + }, + "consequent": { + "type": "ExpressionStatement", + "start": 221, + "end": 235, + "loc": { + "start": { + "line": 11, + "column": 11 + }, + "end": { + "line": 11, + "column": 25 + } + }, + "expression": { + "type": "StringLiteral", + "start": 221, + "end": 235, + "loc": { + "start": { + "line": 11, + "column": 11 + }, + "end": { + "line": 11, + "column": 25 + } + }, + "extra": { + "rawValue": "strict false", + "raw": "\"strict false\"" + }, + "value": "strict false" + } + } + } + ] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/match/mismatched-indent-level-curly/actual.js b/test/fixtures/lightscript/match/mismatched-indent-level-curly/actual.js new file mode 100644 index 0000000000..dd0c10c33c --- /dev/null +++ b/test/fixtures/lightscript/match/mismatched-indent-level-curly/actual.js @@ -0,0 +1,4 @@ +match x { + | true: true + | false: false +} diff --git a/test/fixtures/lightscript/match/mismatched-indent-level-curly/expected.json b/test/fixtures/lightscript/match/mismatched-indent-level-curly/expected.json new file mode 100644 index 0000000000..db10c84de5 --- /dev/null +++ b/test/fixtures/lightscript/match/mismatched-indent-level-curly/expected.json @@ -0,0 +1,192 @@ +{ + "type": "File", + "start": 0, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "body": [ + { + "type": "MatchStatement", + "start": 0, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "discriminant": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "x" + }, + "name": "x" + }, + "cases": [ + { + "type": "MatchCase", + "start": 12, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "test": { + "type": "BooleanLiteral", + "start": 14, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "value": true + }, + "consequent": { + "type": "ExpressionStatement", + "start": 20, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "expression": { + "type": "BooleanLiteral", + "start": 20, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "value": true + } + } + }, + { + "type": "MatchCase", + "start": 29, + "end": 43, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 18 + } + }, + "test": { + "type": "BooleanLiteral", + "start": 31, + "end": 36, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "value": false + }, + "consequent": { + "type": "ExpressionStatement", + "start": 38, + "end": 43, + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 18 + } + }, + "expression": { + "type": "BooleanLiteral", + "start": 38, + "end": 43, + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 18 + } + }, + "value": false + } + } + } + ] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/match/mismatched-indent-level-illegal/actual.js b/test/fixtures/lightscript/match/mismatched-indent-level-illegal/actual.js new file mode 100644 index 0000000000..6050b761a5 --- /dev/null +++ b/test/fixtures/lightscript/match/mismatched-indent-level-illegal/actual.js @@ -0,0 +1,3 @@ +match x: + | true: true + | false: false diff --git a/test/fixtures/lightscript/match/mismatched-indent-level-illegal/options.json b/test/fixtures/lightscript/match/mismatched-indent-level-illegal/options.json new file mode 100644 index 0000000000..8c651f3120 --- /dev/null +++ b/test/fixtures/lightscript/match/mismatched-indent-level-illegal/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Mismatched indent. (3:4)" +} diff --git a/test/fixtures/lightscript/match/nested/actual.js b/test/fixtures/lightscript/match/nested/actual.js new file mode 100644 index 0000000000..2e436ad960 --- /dev/null +++ b/test/fixtures/lightscript/match/nested/actual.js @@ -0,0 +1,6 @@ +match x: + | x > 2: match y: + | y > 10: "soo big" + | y > 5: "still pretty big" + | else: "kinda big" + | else: "some other thing" diff --git a/test/fixtures/lightscript/match/nested/expected.json b/test/fixtures/lightscript/match/nested/expected.json new file mode 100644 index 0000000000..cb608e0bc0 --- /dev/null +++ b/test/fixtures/lightscript/match/nested/expected.json @@ -0,0 +1,506 @@ +{ + "type": "File", + "start": 0, + "end": 137, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 28 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 137, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 28 + } + }, + "sourceType": "script", + "body": [ + { + "type": "MatchStatement", + "start": 0, + "end": 137, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 28 + } + }, + "discriminant": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "x" + }, + "name": "x" + }, + "cases": [ + { + "type": "MatchCase", + "start": 11, + "end": 108, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 5, + "column": 23 + } + }, + "test": { + "type": "BinaryExpression", + "start": 13, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "left": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + }, + "identifierName": "x" + }, + "name": "x" + }, + "operator": ">", + "right": { + "type": "NumericLiteral", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + }, + "consequent": { + "type": "MatchStatement", + "start": 20, + "end": 108, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 5, + "column": 23 + } + }, + "discriminant": { + "type": "Identifier", + "start": 26, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 18 + }, + "identifierName": "y" + }, + "name": "y" + }, + "cases": [ + { + "type": "MatchCase", + "start": 33, + "end": 52, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 23 + } + }, + "test": { + "type": "BinaryExpression", + "start": 35, + "end": 41, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 12 + } + }, + "left": { + "type": "Identifier", + "start": 35, + "end": 36, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 7 + }, + "identifierName": "y" + }, + "name": "y" + }, + "operator": ">", + "right": { + "type": "NumericLiteral", + "start": 39, + "end": 41, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 12 + } + }, + "extra": { + "rawValue": 10, + "raw": "10" + }, + "value": 10 + } + }, + "consequent": { + "type": "ExpressionStatement", + "start": 43, + "end": 52, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 23 + } + }, + "expression": { + "type": "StringLiteral", + "start": 43, + "end": 52, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 23 + } + }, + "extra": { + "rawValue": "soo big", + "raw": "\"soo big\"" + }, + "value": "soo big" + } + } + }, + { + "type": "MatchCase", + "start": 57, + "end": 84, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 31 + } + }, + "test": { + "type": "BinaryExpression", + "start": 59, + "end": 64, + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 11 + } + }, + "left": { + "type": "Identifier", + "start": 59, + "end": 60, + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 7 + }, + "identifierName": "y" + }, + "name": "y" + }, + "operator": ">", + "right": { + "type": "NumericLiteral", + "start": 63, + "end": 64, + "loc": { + "start": { + "line": 4, + "column": 10 + }, + "end": { + "line": 4, + "column": 11 + } + }, + "extra": { + "rawValue": 5, + "raw": "5" + }, + "value": 5 + } + }, + "consequent": { + "type": "ExpressionStatement", + "start": 66, + "end": 84, + "loc": { + "start": { + "line": 4, + "column": 13 + }, + "end": { + "line": 4, + "column": 31 + } + }, + "expression": { + "type": "StringLiteral", + "start": 66, + "end": 84, + "loc": { + "start": { + "line": 4, + "column": 13 + }, + "end": { + "line": 4, + "column": 31 + } + }, + "extra": { + "rawValue": "still pretty big", + "raw": "\"still pretty big\"" + }, + "value": "still pretty big" + } + } + }, + { + "type": "MatchCase", + "start": 89, + "end": 108, + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 23 + } + }, + "test": { + "type": "MatchElse", + "start": 91, + "end": 95, + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 5, + "column": 10 + } + } + }, + "consequent": { + "type": "ExpressionStatement", + "start": 97, + "end": 108, + "loc": { + "start": { + "line": 5, + "column": 12 + }, + "end": { + "line": 5, + "column": 23 + } + }, + "expression": { + "type": "StringLiteral", + "start": 97, + "end": 108, + "loc": { + "start": { + "line": 5, + "column": 12 + }, + "end": { + "line": 5, + "column": 23 + } + }, + "extra": { + "rawValue": "kinda big", + "raw": "\"kinda big\"" + }, + "value": "kinda big" + } + } + } + ] + } + }, + { + "type": "MatchCase", + "start": 111, + "end": 137, + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 28 + } + }, + "test": { + "type": "MatchElse", + "start": 113, + "end": 117, + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 8 + } + } + }, + "consequent": { + "type": "ExpressionStatement", + "start": 119, + "end": 137, + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 28 + } + }, + "expression": { + "type": "StringLiteral", + "start": 119, + "end": 137, + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 28 + } + }, + "extra": { + "rawValue": "some other thing", + "raw": "\"some other thing\"" + }, + "value": "some other thing" + } + } + } + ] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/match/newline-after-pipe-illegal/actual.js b/test/fixtures/lightscript/match/newline-after-pipe-illegal/actual.js new file mode 100644 index 0000000000..c8c3c0b9ca --- /dev/null +++ b/test/fixtures/lightscript/match/newline-after-pipe-illegal/actual.js @@ -0,0 +1,3 @@ +match x: + | + d: 'its a func' diff --git a/test/fixtures/lightscript/match/newline-after-pipe-illegal/options.json b/test/fixtures/lightscript/match/newline-after-pipe-illegal/options.json new file mode 100644 index 0000000000..69f60c2be3 --- /dev/null +++ b/test/fixtures/lightscript/match/newline-after-pipe-illegal/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Illegal newline. (2:3)" +} diff --git a/test/fixtures/lightscript/match/overindent-allowed/actual.js b/test/fixtures/lightscript/match/overindent-allowed/actual.js new file mode 100644 index 0000000000..99efbc86bc --- /dev/null +++ b/test/fixtures/lightscript/match/overindent-allowed/actual.js @@ -0,0 +1,3 @@ +match x: + | true: true + | false: false diff --git a/test/fixtures/lightscript/match/overindent-allowed/expected.json b/test/fixtures/lightscript/match/overindent-allowed/expected.json new file mode 100644 index 0000000000..0f240f8b96 --- /dev/null +++ b/test/fixtures/lightscript/match/overindent-allowed/expected.json @@ -0,0 +1,192 @@ +{ + "type": "File", + "start": 0, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 18 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 18 + } + }, + "sourceType": "script", + "body": [ + { + "type": "MatchStatement", + "start": 0, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 18 + } + }, + "discriminant": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "x" + }, + "name": "x" + }, + "cases": [ + { + "type": "MatchCase", + "start": 13, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "test": { + "type": "BooleanLiteral", + "start": 15, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "value": true + }, + "consequent": { + "type": "ExpressionStatement", + "start": 21, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "expression": { + "type": "BooleanLiteral", + "start": 21, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "value": true + } + } + }, + { + "type": "MatchCase", + "start": 30, + "end": 44, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 18 + } + }, + "test": { + "type": "BooleanLiteral", + "start": 32, + "end": 37, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "value": false + }, + "consequent": { + "type": "ExpressionStatement", + "start": 39, + "end": 44, + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 18 + } + }, + "expression": { + "type": "BooleanLiteral", + "start": 39, + "end": 44, + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 18 + } + }, + "value": false + } + } + } + ] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/match/paren-no-curly-consequent-illegal/actual.js b/test/fixtures/lightscript/match/paren-no-curly-consequent-illegal/actual.js new file mode 100644 index 0000000000..0b779c0b85 --- /dev/null +++ b/test/fixtures/lightscript/match/paren-no-curly-consequent-illegal/actual.js @@ -0,0 +1,2 @@ +a = match x: + | (y) "y" diff --git a/test/fixtures/lightscript/match/paren-no-curly-consequent-illegal/options.json b/test/fixtures/lightscript/match/paren-no-curly-consequent-illegal/options.json new file mode 100644 index 0000000000..a5ea04d45f --- /dev/null +++ b/test/fixtures/lightscript/match/paren-no-curly-consequent-illegal/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected { (2:8)" +} diff --git a/test/fixtures/lightscript/match/parens-arent-calls/actual.js b/test/fixtures/lightscript/match/parens-arent-calls/actual.js new file mode 100644 index 0000000000..41e01ef13d --- /dev/null +++ b/test/fixtures/lightscript/match/parens-arent-calls/actual.js @@ -0,0 +1,2 @@ +a = match x: + | (y): "bigger than two" diff --git a/test/fixtures/lightscript/match/parens-arent-calls/expected.json b/test/fixtures/lightscript/match/parens-arent-calls/expected.json new file mode 100644 index 0000000000..d85a596994 --- /dev/null +++ b/test/fixtures/lightscript/match/parens-arent-calls/expected.json @@ -0,0 +1,192 @@ +{ + "type": "File", + "start": 0, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 26 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 26 + } + }, + "sourceType": "script", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 26 + } + }, + "kind": "const", + "extra": { + "implicit": true + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 0, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 26 + } + }, + "id": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "a" + }, + "name": "a" + }, + "init": { + "type": "MatchExpression", + "start": 4, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 2, + "column": 26 + } + }, + "discriminant": { + "type": "Identifier", + "start": 10, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + }, + "cases": [ + { + "type": "MatchCase", + "start": 15, + "end": 39, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 26 + } + }, + "test": { + "type": "Identifier", + "start": 18, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 6 + }, + "identifierName": "y" + }, + "name": "y", + "extra": { + "parenthesized": true, + "parenStart": 17 + } + }, + "consequent": { + "type": "ExpressionStatement", + "start": 22, + "end": 39, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 26 + } + }, + "expression": { + "type": "StringLiteral", + "start": 22, + "end": 39, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 26 + } + }, + "extra": { + "rawValue": "bigger than two", + "raw": "\"bigger than two\"" + }, + "value": "bigger than two" + } + } + } + ] + } + } + ] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/match/parens-no-curlies-no-colon-illegal/actual.js b/test/fixtures/lightscript/match/parens-no-curlies-no-colon-illegal/actual.js new file mode 100644 index 0000000000..3e3f3d123d --- /dev/null +++ b/test/fixtures/lightscript/match/parens-no-curlies-no-colon-illegal/actual.js @@ -0,0 +1 @@ +a = match (x) | > 2: "bigger than two" diff --git a/test/fixtures/lightscript/match/parens-no-curlies-no-colon-illegal/options.json b/test/fixtures/lightscript/match/parens-no-curlies-no-colon-illegal/options.json new file mode 100644 index 0000000000..5a6e234031 --- /dev/null +++ b/test/fixtures/lightscript/match/parens-no-curlies-no-colon-illegal/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected { (1:14)" +} diff --git a/test/fixtures/lightscript/match/parens-no-curlies/actual.js b/test/fixtures/lightscript/match/parens-no-curlies/actual.js new file mode 100644 index 0000000000..b3103df97a --- /dev/null +++ b/test/fixtures/lightscript/match/parens-no-curlies/actual.js @@ -0,0 +1,3 @@ +a = match (x): + | 2: "eq two" + | else: "some other thing" diff --git a/test/fixtures/lightscript/match/parens-no-curlies/expected.json b/test/fixtures/lightscript/match/parens-no-curlies/expected.json new file mode 100644 index 0000000000..7bfa24b559 --- /dev/null +++ b/test/fixtures/lightscript/match/parens-no-curlies/expected.json @@ -0,0 +1,257 @@ +{ + "type": "File", + "start": 0, + "end": 59, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 59, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "sourceType": "script", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 59, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "kind": "const", + "extra": { + "implicit": true + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 0, + "end": 59, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "id": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "a" + }, + "name": "a" + }, + "init": { + "type": "MatchExpression", + "start": 4, + "end": 59, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "discriminant": { + "type": "Identifier", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "x" + }, + "name": "x", + "extra": {} + }, + "cases": [ + { + "type": "MatchCase", + "start": 17, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "test": { + "type": "NumericLiteral", + "start": 19, + "end": 20, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + }, + "consequent": { + "type": "ExpressionStatement", + "start": 22, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "expression": { + "type": "StringLiteral", + "start": 22, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "extra": { + "rawValue": "eq two", + "raw": "\"eq two\"" + }, + "value": "eq two" + } + } + }, + { + "type": "MatchCase", + "start": 33, + "end": 59, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "test": { + "type": "MatchElse", + "start": 35, + "end": 39, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 8 + } + } + }, + "consequent": { + "type": "ExpressionStatement", + "start": 41, + "end": 59, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "expression": { + "type": "StringLiteral", + "start": 41, + "end": 59, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "extra": { + "rawValue": "some other thing", + "raw": "\"some other thing\"" + }, + "value": "some other thing" + } + } + } + ] + } + } + ] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/match/parenthesized-destructuring-illegal/actual.js b/test/fixtures/lightscript/match/parenthesized-destructuring-illegal/actual.js new file mode 100644 index 0000000000..c89d86c9f2 --- /dev/null +++ b/test/fixtures/lightscript/match/parenthesized-destructuring-illegal/actual.js @@ -0,0 +1,2 @@ +a = match x: + | 3 with ({ three }): three diff --git a/test/fixtures/lightscript/match/parenthesized-destructuring-illegal/options.json b/test/fixtures/lightscript/match/parenthesized-destructuring-illegal/options.json new file mode 100644 index 0000000000..8551537138 --- /dev/null +++ b/test/fixtures/lightscript/match/parenthesized-destructuring-illegal/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token (2:11)" +} diff --git a/test/fixtures/lightscript/match/plain-obj-arr/actual.js b/test/fixtures/lightscript/match/plain-obj-arr/actual.js new file mode 100644 index 0000000000..e98d0eb3e5 --- /dev/null +++ b/test/fixtures/lightscript/match/plain-obj-arr/actual.js @@ -0,0 +1,5 @@ +match x: + | { a, b }~isObject(): true + | { a: 'a' }: 'should throw in compiler' + | [a, b].includes(x): true + | [a, 'b']: 'should throw in compiler' diff --git a/test/fixtures/lightscript/match/plain-obj-arr/expected.json b/test/fixtures/lightscript/match/plain-obj-arr/expected.json new file mode 100644 index 0000000000..41abc7a7e7 --- /dev/null +++ b/test/fixtures/lightscript/match/plain-obj-arr/expected.json @@ -0,0 +1,664 @@ +{ + "type": "File", + "start": 0, + "end": 151, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 40 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 151, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 40 + } + }, + "sourceType": "script", + "body": [ + { + "type": "MatchStatement", + "start": 0, + "end": 151, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 40 + } + }, + "discriminant": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "x" + }, + "name": "x" + }, + "cases": [ + { + "type": "MatchCase", + "start": 11, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "test": { + "type": "TildeCallExpression", + "start": 13, + "end": 32, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "left": { + "type": "ObjectExpression", + "start": 13, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 7 + }, + "identifierName": "a" + }, + "name": "a" + }, + "value": { + "type": "Identifier", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 7 + }, + "identifierName": "a" + }, + "name": "a" + }, + "extra": { + "shorthand": true + } + }, + { + "type": "ObjectProperty", + "start": 18, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 18, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 10 + }, + "identifierName": "b" + }, + "name": "b" + }, + "value": { + "type": "Identifier", + "start": 18, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 10 + }, + "identifierName": "b" + }, + "name": "b" + }, + "extra": { + "shorthand": true + } + } + ] + }, + "right": { + "type": "Identifier", + "start": 22, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 21 + }, + "identifierName": "isObject" + }, + "name": "isObject" + }, + "arguments": [] + }, + "consequent": { + "type": "ExpressionStatement", + "start": 34, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "expression": { + "type": "BooleanLiteral", + "start": 34, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "value": true + } + } + }, + { + "type": "MatchCase", + "start": 41, + "end": 81, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 42 + } + }, + "test": { + "type": "ObjectExpression", + "start": 43, + "end": 53, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 45, + "end": 51, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 12 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 45, + "end": 46, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 7 + }, + "identifierName": "a" + }, + "name": "a" + }, + "value": { + "type": "StringLiteral", + "start": 48, + "end": 51, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 12 + } + }, + "extra": { + "rawValue": "a", + "raw": "'a'" + }, + "value": "a" + } + } + ] + }, + "consequent": { + "type": "ExpressionStatement", + "start": 55, + "end": 81, + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 42 + } + }, + "expression": { + "type": "StringLiteral", + "start": 55, + "end": 81, + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 42 + } + }, + "extra": { + "rawValue": "should throw in compiler", + "raw": "'should throw in compiler'" + }, + "value": "should throw in compiler" + } + } + }, + { + "type": "MatchCase", + "start": 84, + "end": 110, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 28 + } + }, + "test": { + "type": "CallExpression", + "start": 86, + "end": 104, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 22 + } + }, + "callee": { + "type": "MemberExpression", + "start": 86, + "end": 101, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 19 + } + }, + "object": { + "type": "ArrayExpression", + "start": 86, + "end": 92, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 10 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 87, + "end": 88, + "loc": { + "start": { + "line": 4, + "column": 5 + }, + "end": { + "line": 4, + "column": 6 + }, + "identifierName": "a" + }, + "name": "a" + }, + { + "type": "Identifier", + "start": 90, + "end": 91, + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 9 + }, + "identifierName": "b" + }, + "name": "b" + } + ] + }, + "property": { + "type": "Identifier", + "start": 93, + "end": 101, + "loc": { + "start": { + "line": 4, + "column": 11 + }, + "end": { + "line": 4, + "column": 19 + }, + "identifierName": "includes" + }, + "name": "includes" + }, + "computed": false + }, + "arguments": [ + { + "type": "Identifier", + "start": 102, + "end": 103, + "loc": { + "start": { + "line": 4, + "column": 20 + }, + "end": { + "line": 4, + "column": 21 + }, + "identifierName": "x" + }, + "name": "x" + } + ] + }, + "consequent": { + "type": "ExpressionStatement", + "start": 106, + "end": 110, + "loc": { + "start": { + "line": 4, + "column": 24 + }, + "end": { + "line": 4, + "column": 28 + } + }, + "expression": { + "type": "BooleanLiteral", + "start": 106, + "end": 110, + "loc": { + "start": { + "line": 4, + "column": 24 + }, + "end": { + "line": 4, + "column": 28 + } + }, + "value": true + } + } + }, + { + "type": "MatchCase", + "start": 113, + "end": 151, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 40 + } + }, + "test": { + "type": "ArrayExpression", + "start": 115, + "end": 123, + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 12 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 116, + "end": 117, + "loc": { + "start": { + "line": 5, + "column": 5 + }, + "end": { + "line": 5, + "column": 6 + }, + "identifierName": "a" + }, + "name": "a" + }, + { + "type": "StringLiteral", + "start": 119, + "end": 122, + "loc": { + "start": { + "line": 5, + "column": 8 + }, + "end": { + "line": 5, + "column": 11 + } + }, + "extra": { + "rawValue": "b", + "raw": "'b'" + }, + "value": "b" + } + ] + }, + "consequent": { + "type": "ExpressionStatement", + "start": 125, + "end": 151, + "loc": { + "start": { + "line": 5, + "column": 14 + }, + "end": { + "line": 5, + "column": 40 + } + }, + "expression": { + "type": "StringLiteral", + "start": 125, + "end": 151, + "loc": { + "start": { + "line": 5, + "column": 14 + }, + "end": { + "line": 5, + "column": 40 + } + }, + "extra": { + "rawValue": "should throw in compiler", + "raw": "'should throw in compiler'" + }, + "value": "should throw in compiler" + } + } + } + ] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/match/statement-break/actual.js b/test/fixtures/lightscript/match/statement-break/actual.js new file mode 100644 index 0000000000..353c1ca6e9 --- /dev/null +++ b/test/fixtures/lightscript/match/statement-break/actual.js @@ -0,0 +1,3 @@ +while false: + match x: + | 1: break diff --git a/test/fixtures/lightscript/match/statement-break/expected.json b/test/fixtures/lightscript/match/statement-break/expected.json new file mode 100644 index 0000000000..3a49add969 --- /dev/null +++ b/test/fixtures/lightscript/match/statement-break/expected.json @@ -0,0 +1,171 @@ +{ + "type": "File", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "sourceType": "script", + "body": [ + { + "type": "WhileStatement", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "test": { + "type": "BooleanLiteral", + "start": 6, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "value": false + }, + "body": { + "type": "BlockStatement", + "start": 11, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "body": [ + { + "type": "MatchStatement", + "start": 15, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "discriminant": { + "type": "Identifier", + "start": 21, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 9 + }, + "identifierName": "x" + }, + "name": "x" + }, + "cases": [ + { + "type": "MatchCase", + "start": 28, + "end": 38, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "test": { + "type": "NumericLiteral", + "start": 30, + "end": 31, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 7 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + }, + "consequent": { + "type": "BreakStatement", + "start": 33, + "end": 38, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "label": null + } + } + ] + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/match/statement-return/actual.js b/test/fixtures/lightscript/match/statement-return/actual.js new file mode 100644 index 0000000000..f0e28950d2 --- /dev/null +++ b/test/fixtures/lightscript/match/statement-return/actual.js @@ -0,0 +1,3 @@ +f() -> + match x: + | 1: return diff --git a/test/fixtures/lightscript/match/statement-return/expected.json b/test/fixtures/lightscript/match/statement-return/expected.json new file mode 100644 index 0000000000..faa1524f2e --- /dev/null +++ b/test/fixtures/lightscript/match/statement-return/expected.json @@ -0,0 +1,177 @@ +{ + "type": "File", + "start": 0, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "sourceType": "script", + "body": [ + { + "type": "NamedArrowDeclaration", + "start": 0, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "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": 33, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "body": [ + { + "type": "MatchStatement", + "start": 9, + "end": 33, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "discriminant": { + "type": "Identifier", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 9 + }, + "identifierName": "x" + }, + "name": "x" + }, + "cases": [ + { + "type": "MatchCase", + "start": 22, + "end": 33, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "test": { + "type": "NumericLiteral", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 7 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + }, + "consequent": { + "type": "ReturnStatement", + "start": 27, + "end": 33, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "argument": null + } + } + ] + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/match/tag-literal/actual.js b/test/fixtures/lightscript/match/tag-literal/actual.js new file mode 100644 index 0000000000..05c725a01e --- /dev/null +++ b/test/fixtures/lightscript/match/tag-literal/actual.js @@ -0,0 +1,3 @@ +match x: + | `a`: 'is "a"' + | `${b}`: 'is str of b' diff --git a/test/fixtures/lightscript/match/tag-literal/expected.json b/test/fixtures/lightscript/match/tag-literal/expected.json new file mode 100644 index 0000000000..7ecb00e7bc --- /dev/null +++ b/test/fixtures/lightscript/match/tag-literal/expected.json @@ -0,0 +1,282 @@ +{ + "type": "File", + "start": 0, + "end": 52, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 25 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 52, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 25 + } + }, + "sourceType": "script", + "body": [ + { + "type": "MatchStatement", + "start": 0, + "end": 52, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 25 + } + }, + "discriminant": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "x" + }, + "name": "x" + }, + "cases": [ + { + "type": "MatchCase", + "start": 11, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "test": { + "type": "TemplateLiteral", + "start": 13, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "expressions": [], + "quasis": [ + { + "type": "TemplateElement", + "start": 14, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "value": { + "raw": "a", + "cooked": "a" + }, + "tail": true + } + ] + }, + "consequent": { + "type": "ExpressionStatement", + "start": 18, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "expression": { + "type": "StringLiteral", + "start": 18, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "extra": { + "rawValue": "is \"a\"", + "raw": "'is \"a\"'" + }, + "value": "is \"a\"" + } + } + }, + { + "type": "MatchCase", + "start": 29, + "end": 52, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 25 + } + }, + "test": { + "type": "TemplateLiteral", + "start": 31, + "end": 37, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "expressions": [ + { + "type": "Identifier", + "start": 34, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 8 + }, + "identifierName": "b" + }, + "name": "b" + } + ], + "quasis": [ + { + "type": "TemplateElement", + "start": 32, + "end": 32, + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 5 + } + }, + "value": { + "raw": "", + "cooked": "" + }, + "tail": false + }, + { + "type": "TemplateElement", + "start": 36, + "end": 36, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "value": { + "raw": "", + "cooked": "" + }, + "tail": true + } + ] + }, + "consequent": { + "type": "ExpressionStatement", + "start": 39, + "end": 52, + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 25 + } + }, + "expression": { + "type": "StringLiteral", + "start": 39, + "end": 52, + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 25 + } + }, + "extra": { + "rawValue": "is str of b", + "raw": "'is str of b'" + }, + "value": "is str of b" + } + } + } + ] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/match/yield/actual.js b/test/fixtures/lightscript/match/yield/actual.js new file mode 100644 index 0000000000..d9332f88a4 --- /dev/null +++ b/test/fixtures/lightscript/match/yield/actual.js @@ -0,0 +1,6 @@ +f() -*> + yield match x: + | a: 1 + | b: yield z() + | c: + yield z() diff --git a/test/fixtures/lightscript/match/yield/expected.json b/test/fixtures/lightscript/match/yield/expected.json new file mode 100644 index 0000000000..c544c8e1ff --- /dev/null +++ b/test/fixtures/lightscript/match/yield/expected.json @@ -0,0 +1,437 @@ +{ + "type": "File", + "start": 0, + "end": 79, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 15 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 79, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 15 + } + }, + "sourceType": "script", + "body": [ + { + "type": "NamedArrowDeclaration", + "start": 0, + "end": 79, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "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": true, + "expression": false, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "BlockStatement", + "start": 4, + "end": 79, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 6, + "column": 15 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 10, + "end": 79, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 6, + "column": 15 + } + }, + "expression": { + "type": "YieldExpression", + "start": 10, + "end": 79, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 6, + "column": 15 + } + }, + "delegate": false, + "argument": { + "type": "MatchExpression", + "start": 16, + "end": 79, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 6, + "column": 15 + } + }, + "discriminant": { + "type": "Identifier", + "start": 22, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + }, + "identifierName": "x" + }, + "name": "x" + }, + "cases": [ + { + "type": "MatchCase", + "start": 29, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "test": { + "type": "Identifier", + "start": 31, + "end": 32, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 7 + }, + "identifierName": "a" + }, + "name": "a" + }, + "consequent": { + "type": "ExpressionStatement", + "start": 34, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 34, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + }, + { + "type": "MatchCase", + "start": 40, + "end": 54, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 18 + } + }, + "test": { + "type": "Identifier", + "start": 42, + "end": 43, + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 7 + }, + "identifierName": "b" + }, + "name": "b" + }, + "consequent": { + "type": "ExpressionStatement", + "start": 45, + "end": 54, + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 4, + "column": 18 + } + }, + "expression": { + "type": "YieldExpression", + "start": 45, + "end": 54, + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 4, + "column": 18 + } + }, + "delegate": false, + "argument": { + "type": "CallExpression", + "start": 51, + "end": 54, + "loc": { + "start": { + "line": 4, + "column": 15 + }, + "end": { + "line": 4, + "column": 18 + } + }, + "callee": { + "type": "Identifier", + "start": 51, + "end": 52, + "loc": { + "start": { + "line": 4, + "column": 15 + }, + "end": { + "line": 4, + "column": 16 + }, + "identifierName": "z" + }, + "name": "z" + }, + "arguments": [] + } + } + } + }, + { + "type": "MatchCase", + "start": 59, + "end": 79, + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 6, + "column": 15 + } + }, + "test": { + "type": "Identifier", + "start": 61, + "end": 62, + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 5, + "column": 7 + }, + "identifierName": "c" + }, + "name": "c" + }, + "consequent": { + "type": "BlockStatement", + "start": 62, + "end": 79, + "loc": { + "start": { + "line": 5, + "column": 7 + }, + "end": { + "line": 6, + "column": 15 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 70, + "end": 79, + "loc": { + "start": { + "line": 6, + "column": 6 + }, + "end": { + "line": 6, + "column": 15 + } + }, + "expression": { + "type": "YieldExpression", + "start": 70, + "end": 79, + "loc": { + "start": { + "line": 6, + "column": 6 + }, + "end": { + "line": 6, + "column": 15 + } + }, + "delegate": false, + "argument": { + "type": "CallExpression", + "start": 76, + "end": 79, + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 6, + "column": 15 + } + }, + "callee": { + "type": "Identifier", + "start": 76, + "end": 77, + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 6, + "column": 13 + }, + "identifierName": "z" + }, + "name": "z" + }, + "arguments": [] + } + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + ] + } + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + ], + "directives": [] + } +} \ No newline at end of file