From 801bae64da3ce338224133414ec9fa9b5c3876d2 Mon Sep 17 00:00:00 2001 From: Alex Rattray Date: Mon, 24 Apr 2017 16:39:27 -0700 Subject: [PATCH 01/12] Pattern Matching --- src/parser/expression.js | 23 +- src/plugins/jsx/index.js | 5 + src/plugins/lightscript.js | 107 ++ src/tokenizer/state.js | 4 + src/tokenizer/types.js | 1 + src/util/identifier.js | 2 +- .../lightscript/match/arrow-fns/actual.js | 11 + .../lightscript/match/arrow-fns/expected.json | 1148 ++++++++++++++++ .../lightscript/match/async/actual.js | 8 + .../lightscript/match/async/expected.json | 641 +++++++++ .../match/binary-both-subscripts/actual.js | 2 + .../binary-both-subscripts/expected.json | 251 ++++ .../lightscript/match/binary/actual.js | 8 + .../lightscript/match/binary/expected.json | 1160 +++++++++++++++++ .../bitwise-or-consequent-inline/actual.js | 2 + .../expected.json | 230 ++++ .../actual.js | 4 + .../options.json | 3 + .../match/bitwise-or-test-explicit/actual.js | 2 + .../bitwise-or-test-explicit/expected.json | 230 ++++ .../actual.js | 2 + .../options.json | 3 + .../match/curlies-parens/actual.js | 4 + .../match/curlies-parens/expected.json | 300 +++++ .../lightscript/match/curlies/actual.js | 4 + .../lightscript/match/curlies/expected.json | 299 +++++ .../match/dot-then-binary-illegal/actual.js | 2 + .../dot-then-binary-illegal/options.json | 3 + .../match/else-before-case-illegal/actual.js | 3 + .../else-before-case-illegal/options.json | 3 + .../lightscript/match/else-solo/actual.js | 2 + .../lightscript/match/else-solo/expected.json | 154 +++ .../fixtures/lightscript/match/else/actual.js | 3 + .../lightscript/match/else/expected.json | 221 ++++ .../lightscript/match/in-assignment/actual.js | 3 + .../match/in-assignment/expected.json | 299 +++++ .../lightscript/match/jsx-result/actual.js | 2 + .../match/jsx-result/expected.json | 186 +++ .../match/jsx-test-illegal/actual.js | 2 + .../match/jsx-test-illegal/options.json | 3 + .../lightscript/match/less-than/actual.js | 3 + .../lightscript/match/less-than/expected.json | 297 +++++ .../lightscript/match/literals/actual.js | 11 + .../lightscript/match/literals/expected.json | 867 ++++++++++++ .../match/multi-subscripts-illegal/actual.js | 2 + .../multi-subscripts-illegal/options.json | 3 + .../multi-subscripts-number-WRONG/actual.js | 3 + .../expected.json | 335 +++++ .../multi-subscripts-number-illegal/actual.js | 2 + .../options.json | 3 + .../match/multi-subscripts/actual.js | 3 + .../match/multi-subscripts/expected.json | 419 ++++++ .../lightscript/match/nested/actual.js | 6 + .../lightscript/match/nested/expected.json | 578 ++++++++ .../newline-after-pipe-illegal/actual.js | 3 + .../newline-after-pipe-illegal/options.json | 3 + .../match/parens-arent-calls/actual.js | 2 + .../match/parens-arent-calls/expected.json | 198 +++ .../actual.js | 1 + .../options.json | 3 + .../match/parens-no-curlies/actual.js | 3 + .../match/parens-no-curlies/expected.json | 300 +++++ .../match/subscript-in-tilde/actual.js | 2 + .../match/subscript-in-tilde/expected.json | 236 ++++ .../lightscript/match/subscripts/actual.js | 7 + .../match/subscripts/expected.json | 668 ++++++++++ .../lightscript/match/tag-literal/actual.js | 3 + .../match/tag-literal/expected.json | 309 +++++ 68 files changed, 9608 insertions(+), 2 deletions(-) create mode 100644 test/fixtures/lightscript/match/arrow-fns/actual.js create mode 100644 test/fixtures/lightscript/match/arrow-fns/expected.json create mode 100644 test/fixtures/lightscript/match/async/actual.js create mode 100644 test/fixtures/lightscript/match/async/expected.json create mode 100644 test/fixtures/lightscript/match/binary-both-subscripts/actual.js create mode 100644 test/fixtures/lightscript/match/binary-both-subscripts/expected.json create mode 100644 test/fixtures/lightscript/match/binary/actual.js create mode 100644 test/fixtures/lightscript/match/binary/expected.json create mode 100644 test/fixtures/lightscript/match/bitwise-or-consequent-inline/actual.js create mode 100644 test/fixtures/lightscript/match/bitwise-or-consequent-inline/expected.json create mode 100644 test/fixtures/lightscript/match/bitwise-or-consequent-newline-illegal/actual.js create mode 100644 test/fixtures/lightscript/match/bitwise-or-consequent-newline-illegal/options.json create mode 100644 test/fixtures/lightscript/match/bitwise-or-test-explicit/actual.js create mode 100644 test/fixtures/lightscript/match/bitwise-or-test-explicit/expected.json create mode 100644 test/fixtures/lightscript/match/bitwise-or-test-implicit-illegal/actual.js create mode 100644 test/fixtures/lightscript/match/bitwise-or-test-implicit-illegal/options.json create mode 100644 test/fixtures/lightscript/match/curlies-parens/actual.js create mode 100644 test/fixtures/lightscript/match/curlies-parens/expected.json create mode 100644 test/fixtures/lightscript/match/curlies/actual.js create mode 100644 test/fixtures/lightscript/match/curlies/expected.json create mode 100644 test/fixtures/lightscript/match/dot-then-binary-illegal/actual.js create mode 100644 test/fixtures/lightscript/match/dot-then-binary-illegal/options.json create mode 100644 test/fixtures/lightscript/match/else-before-case-illegal/actual.js create mode 100644 test/fixtures/lightscript/match/else-before-case-illegal/options.json create mode 100644 test/fixtures/lightscript/match/else-solo/actual.js create mode 100644 test/fixtures/lightscript/match/else-solo/expected.json create mode 100644 test/fixtures/lightscript/match/else/actual.js create mode 100644 test/fixtures/lightscript/match/else/expected.json create mode 100644 test/fixtures/lightscript/match/in-assignment/actual.js create mode 100644 test/fixtures/lightscript/match/in-assignment/expected.json create mode 100644 test/fixtures/lightscript/match/jsx-result/actual.js create mode 100644 test/fixtures/lightscript/match/jsx-result/expected.json create mode 100644 test/fixtures/lightscript/match/jsx-test-illegal/actual.js create mode 100644 test/fixtures/lightscript/match/jsx-test-illegal/options.json create mode 100644 test/fixtures/lightscript/match/less-than/actual.js create mode 100644 test/fixtures/lightscript/match/less-than/expected.json create mode 100644 test/fixtures/lightscript/match/literals/actual.js create mode 100644 test/fixtures/lightscript/match/literals/expected.json create mode 100644 test/fixtures/lightscript/match/multi-subscripts-illegal/actual.js create mode 100644 test/fixtures/lightscript/match/multi-subscripts-illegal/options.json create mode 100644 test/fixtures/lightscript/match/multi-subscripts-number-WRONG/actual.js create mode 100644 test/fixtures/lightscript/match/multi-subscripts-number-WRONG/expected.json create mode 100644 test/fixtures/lightscript/match/multi-subscripts-number-illegal/actual.js create mode 100644 test/fixtures/lightscript/match/multi-subscripts-number-illegal/options.json create mode 100644 test/fixtures/lightscript/match/multi-subscripts/actual.js create mode 100644 test/fixtures/lightscript/match/multi-subscripts/expected.json create mode 100644 test/fixtures/lightscript/match/nested/actual.js create mode 100644 test/fixtures/lightscript/match/nested/expected.json create mode 100644 test/fixtures/lightscript/match/newline-after-pipe-illegal/actual.js create mode 100644 test/fixtures/lightscript/match/newline-after-pipe-illegal/options.json create mode 100644 test/fixtures/lightscript/match/parens-arent-calls/actual.js create mode 100644 test/fixtures/lightscript/match/parens-arent-calls/expected.json create mode 100644 test/fixtures/lightscript/match/parens-no-curlies-no-colon-illegal/actual.js create mode 100644 test/fixtures/lightscript/match/parens-no-curlies-no-colon-illegal/options.json create mode 100644 test/fixtures/lightscript/match/parens-no-curlies/actual.js create mode 100644 test/fixtures/lightscript/match/parens-no-curlies/expected.json create mode 100644 test/fixtures/lightscript/match/subscript-in-tilde/actual.js create mode 100644 test/fixtures/lightscript/match/subscript-in-tilde/expected.json create mode 100644 test/fixtures/lightscript/match/subscripts/actual.js create mode 100644 test/fixtures/lightscript/match/subscripts/expected.json create mode 100644 test/fixtures/lightscript/match/tag-literal/actual.js create mode 100644 test/fixtures/lightscript/match/tag-literal/expected.json diff --git a/src/parser/expression.js b/src/parser/expression.js index 1c075315f2..c829da4728 100644 --- a/src/parser/expression.js +++ b/src/parser/expression.js @@ -244,6 +244,12 @@ pp.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, noIn) { if (this.match(tt.plusMin) && !this.isNextCharWhitespace()) { return left; } + // if it's a `|` in a match/case on a newline, assume it's for the "case" + // TODO: consider using indentation to be more precise about this + // TODO: just remove all bitwise operators so this isn't necessary. + if (this.match(tt.bitwiseOR) && this.state.inMatchCaseConsequent) { + return left; + } } if (this.hasPlugin("lightscript") && this.isBitwiseOp()) { @@ -288,7 +294,12 @@ pp.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, noIn) { // Parse unary operators, both prefix and postfix. pp.parseMaybeUnary = function (refShorthandDefaultPos) { - if (this.state.type.prefix) { + const matchCaseBinaryPlusMin = this.hasPlugin("lightscript") && + this.state.inMatchCaseTest && + this.match(tt.plusMin) && + this.isNextCharWhitespace(); + + if (this.state.type.prefix && !matchCaseBinaryPlusMin) { if (this.hasPlugin("lightscript") && this.match(tt.plusMin)) { if (this.isNextCharWhitespace()) this.unexpected(null, "Unary +/- cannot be followed by a space in lightscript."); } @@ -716,6 +727,11 @@ pp.parseExprAtom = function (refShorthandDefaultPos) { return this.parseIfExpression(node); } + case tt._match: + if (this.hasPlugin("lightscript")) { + return this.parseMatch(); + } + case tt.arrow: if (this.hasPlugin("lightscript")) { node = this.startNode(); @@ -741,6 +757,11 @@ pp.parseExprAtom = function (refShorthandDefaultPos) { } default: + if (this.hasPlugin("lightscript") && this.allowMatchCasePlaceholder()) { + // use the blank space as an empty value (perhaps 0-length would be better) + node = this.startNodeAt(this.state.lastTokEnd, this.state.lastTokEndLoc); + return this.finishNodeAt(node, "PlaceholderExpression", this.state.start, this.state.startLoc); + } this.unexpected(); } }; 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..2da7887c76 100644 --- a/src/plugins/lightscript.js +++ b/src/plugins/lightscript.js @@ -550,6 +550,113 @@ pp.isBitwiseOp = function () { ); }; +pp.parseMatch = function () { + const node = this.startNode(); + this.expect(tt._match); + node.discriminant = this.parseParenExpression(); + + let isEnd; + if (this.match(tt.colon)) { + 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 = []; + let hasUsedElse = false; + while (!isEnd()) { + if (hasUsedElse) { + this.unexpected(null, "`else` must be last case."); + } + + const matchCase = this.parseMatchCase(); + if (matchCase.test && matchCase.test.type === "MatchElse") { + hasUsedElse = true; + } + node.cases.push(matchCase); + } + + return this.finishNode(node, "MatchExpression"); +}; + +pp.parseMatchCase = function () { + const node = this.startNode(); + + node.test = this.parseMatchCaseTest(); + this.expect(tt.comma); + + // parse arrow function expression. (TODO: consider allowing NamedArrowExpression) + const oldInMatchCaseConsequent = this.state.inMatchCaseConsequent; + this.state.inMatchCaseConsequent = true; + node.consequent = this.parseMaybeAssign(); + this.state.inMatchCaseConsequent = oldInMatchCaseConsequent; + if (node.consequent.type !== "ArrowFunctionExpression") { + this.unexpected(node.consequent.start, tt.arrow); + } + + return this.finishNode(node, "MatchCase"); +}; + +pp.parseMatchCaseTest = function () { + // 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."); + + let test; + if (this.match(tt._else)) { + const elseNode = this.startNode(); + this.next(); + test = this.finishNode(elseNode, "MatchElse"); + } else { + test = this.parseExprOps(); + } + + this.state.inMatchCaseTest = false; + return test; +}; + +pp.isBinaryTokenForMatchCase = function (tokenType) { + return ( + tokenType.binop != null && + tokenType !== tt.logicalOR && + tokenType !== tt.logicalAND && + tokenType !== tt.bitwiseOR + ); +}; + +pp.isSubscriptTokenForMatchCase = function (tokenType) { + return ( + tokenType === tt.dot || + tokenType === tt.elvis || + tokenType === tt.tilde || + tokenType === tt.bracketL || + (tokenType === this.state.type && this.isNumberStartingWithDot()) + ); +}; + +pp.allowMatchCasePlaceholder = function () { + if (!this.state.inMatchCaseTest) { + return false; + } + const cur = this.state.type; + const prev = this.state.tokens[this.state.tokens.length - 1].type; + + // don't allow two binary tokens in a row to use placeholders, eg; `+ *` + if (this.isBinaryTokenForMatchCase(cur)) { + return !this.isBinaryTokenForMatchCase(prev); + } + // don't allow two subscripts in a row to use placeholders, eg; `..` + if (this.isSubscriptTokenForMatchCase(cur)) { + return !this.isSubscriptTokenForMatchCase(prev); + } + return false; +}; + export default function (instance) { diff --git a/src/tokenizer/state.js b/src/tokenizer/state.js index e69f12055f..ee6349f33a 100644 --- a/src/tokenizer/state.js +++ b/src/tokenizer/state.js @@ -38,7 +38,11 @@ export default class State { this.pos = this.lineStart = 0; this.curLine = options.startLine; + // for lightscript this.indentLevel = 0; + this.inMatchCaseConsequent = + 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/match/arrow-fns/actual.js b/test/fixtures/lightscript/match/arrow-fns/actual.js new file mode 100644 index 0000000000..118b044d51 --- /dev/null +++ b/test/fixtures/lightscript/match/arrow-fns/actual.js @@ -0,0 +1,11 @@ +match x: + | a, -> 1 + | b, b -> b + | c, (c) -> c + | d, ({ d }) -> d + | e, ({ e = 1 }) -> e + | f, ([ f ]) -> f + | g, ([ g = 1 ]) -> g + | h, => 1 + | i, i => i + | j, (j) => j diff --git a/test/fixtures/lightscript/match/arrow-fns/expected.json b/test/fixtures/lightscript/match/arrow-fns/expected.json new file mode 100644 index 0000000000..a3d21d51fe --- /dev/null +++ b/test/fixtures/lightscript/match/arrow-fns/expected.json @@ -0,0 +1,1148 @@ +{ + "type": "File", + "start": 0, + "end": 180, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 11, + "column": 15 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 180, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 11, + "column": 15 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 180, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 11, + "column": 15 + } + }, + "expression": { + "type": "MatchExpression", + "start": 0, + "end": 180, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 11, + "column": 15 + } + }, + "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": 20, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "test": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + }, + "identifierName": "a" + }, + "name": "a" + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 16, + "end": 20, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "NumericLiteral", + "start": 19, + "end": 20, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + }, + { + "type": "MatchCase", + "start": 23, + "end": 34, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "test": { + "type": "Identifier", + "start": 25, + "end": 26, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 5 + }, + "identifierName": "b" + }, + "name": "b" + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 28, + "end": 34, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 28, + "end": 29, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 8 + }, + "identifierName": "b" + }, + "name": "b" + } + ], + "skinny": true, + "body": { + "type": "Identifier", + "start": 33, + "end": 34, + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 13 + }, + "identifierName": "b" + }, + "name": "b" + } + } + }, + { + "type": "MatchCase", + "start": 37, + "end": 50, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 15 + } + }, + "test": { + "type": "Identifier", + "start": 39, + "end": 40, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 5 + }, + "identifierName": "c" + }, + "name": "c" + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 42, + "end": 50, + "loc": { + "start": { + "line": 4, + "column": 7 + }, + "end": { + "line": 4, + "column": 15 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 43, + "end": 44, + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 9 + }, + "identifierName": "c" + }, + "name": "c" + } + ], + "skinny": true, + "body": { + "type": "Identifier", + "start": 49, + "end": 50, + "loc": { + "start": { + "line": 4, + "column": 14 + }, + "end": { + "line": 4, + "column": 15 + }, + "identifierName": "c" + }, + "name": "c" + } + } + }, + { + "type": "MatchCase", + "start": 53, + "end": 70, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 19 + } + }, + "test": { + "type": "Identifier", + "start": 55, + "end": 56, + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 5 + }, + "identifierName": "d" + }, + "name": "d" + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 58, + "end": 70, + "loc": { + "start": { + "line": 5, + "column": 7 + }, + "end": { + "line": 5, + "column": 19 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [ + { + "type": "ObjectPattern", + "start": 59, + "end": 64, + "loc": { + "start": { + "line": 5, + "column": 8 + }, + "end": { + "line": 5, + "column": 13 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 61, + "end": 62, + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 11 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 61, + "end": 62, + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 11 + }, + "identifierName": "d" + }, + "name": "d" + }, + "value": { + "type": "Identifier", + "start": 61, + "end": 62, + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 11 + }, + "identifierName": "d" + }, + "name": "d" + }, + "extra": { + "shorthand": true + } + } + ] + } + ], + "skinny": true, + "body": { + "type": "Identifier", + "start": 69, + "end": 70, + "loc": { + "start": { + "line": 5, + "column": 18 + }, + "end": { + "line": 5, + "column": 19 + }, + "identifierName": "d" + }, + "name": "d" + } + } + }, + { + "type": "MatchCase", + "start": 73, + "end": 94, + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 23 + } + }, + "test": { + "type": "Identifier", + "start": 75, + "end": 76, + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 5 + }, + "identifierName": "e" + }, + "name": "e" + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 78, + "end": 94, + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 23 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [ + { + "type": "ObjectPattern", + "start": 79, + "end": 88, + "loc": { + "start": { + "line": 6, + "column": 8 + }, + "end": { + "line": 6, + "column": 17 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 81, + "end": 86, + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 15 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 81, + "end": 82, + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 11 + }, + "identifierName": "e" + }, + "name": "e" + }, + "value": { + "type": "AssignmentPattern", + "start": 81, + "end": 86, + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 15 + } + }, + "left": { + "type": "Identifier", + "start": 81, + "end": 82, + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 11 + }, + "identifierName": "e" + }, + "name": "e" + }, + "right": { + "type": "NumericLiteral", + "start": 85, + "end": 86, + "loc": { + "start": { + "line": 6, + "column": 14 + }, + "end": { + "line": 6, + "column": 15 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + }, + "extra": { + "shorthand": true + } + } + ] + } + ], + "skinny": true, + "body": { + "type": "Identifier", + "start": 93, + "end": 94, + "loc": { + "start": { + "line": 6, + "column": 22 + }, + "end": { + "line": 6, + "column": 23 + }, + "identifierName": "e" + }, + "name": "e" + } + } + }, + { + "type": "MatchCase", + "start": 97, + "end": 114, + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 19 + } + }, + "test": { + "type": "Identifier", + "start": 99, + "end": 100, + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 5 + }, + "identifierName": "f" + }, + "name": "f" + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 102, + "end": 114, + "loc": { + "start": { + "line": 7, + "column": 7 + }, + "end": { + "line": 7, + "column": 19 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [ + { + "type": "ArrayPattern", + "start": 103, + "end": 108, + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 13 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 105, + "end": 106, + "loc": { + "start": { + "line": 7, + "column": 10 + }, + "end": { + "line": 7, + "column": 11 + }, + "identifierName": "f" + }, + "name": "f" + } + ] + } + ], + "skinny": true, + "body": { + "type": "Identifier", + "start": 113, + "end": 114, + "loc": { + "start": { + "line": 7, + "column": 18 + }, + "end": { + "line": 7, + "column": 19 + }, + "identifierName": "f" + }, + "name": "f" + } + } + }, + { + "type": "MatchCase", + "start": 117, + "end": 138, + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 23 + } + }, + "test": { + "type": "Identifier", + "start": 119, + "end": 120, + "loc": { + "start": { + "line": 8, + "column": 4 + }, + "end": { + "line": 8, + "column": 5 + }, + "identifierName": "g" + }, + "name": "g" + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 122, + "end": 138, + "loc": { + "start": { + "line": 8, + "column": 7 + }, + "end": { + "line": 8, + "column": 23 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [ + { + "type": "ArrayPattern", + "start": 123, + "end": 132, + "loc": { + "start": { + "line": 8, + "column": 8 + }, + "end": { + "line": 8, + "column": 17 + } + }, + "elements": [ + { + "type": "AssignmentPattern", + "start": 125, + "end": 130, + "loc": { + "start": { + "line": 8, + "column": 10 + }, + "end": { + "line": 8, + "column": 15 + } + }, + "left": { + "type": "Identifier", + "start": 125, + "end": 126, + "loc": { + "start": { + "line": 8, + "column": 10 + }, + "end": { + "line": 8, + "column": 11 + }, + "identifierName": "g" + }, + "name": "g" + }, + "right": { + "type": "NumericLiteral", + "start": 129, + "end": 130, + "loc": { + "start": { + "line": 8, + "column": 14 + }, + "end": { + "line": 8, + "column": 15 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + }, + "isNowAssign": false + } + ] + } + ], + "skinny": true, + "body": { + "type": "Identifier", + "start": 137, + "end": 138, + "loc": { + "start": { + "line": 8, + "column": 22 + }, + "end": { + "line": 8, + "column": 23 + }, + "identifierName": "g" + }, + "name": "g" + } + } + }, + { + "type": "MatchCase", + "start": 141, + "end": 150, + "loc": { + "start": { + "line": 9, + "column": 2 + }, + "end": { + "line": 9, + "column": 11 + } + }, + "test": { + "type": "Identifier", + "start": 143, + "end": 144, + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 5 + }, + "identifierName": "h" + }, + "name": "h" + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 146, + "end": 150, + "loc": { + "start": { + "line": 9, + "column": 7 + }, + "end": { + "line": 9, + "column": 11 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": false, + "body": { + "type": "NumericLiteral", + "start": 149, + "end": 150, + "loc": { + "start": { + "line": 9, + "column": 10 + }, + "end": { + "line": 9, + "column": 11 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + }, + { + "type": "MatchCase", + "start": 153, + "end": 164, + "loc": { + "start": { + "line": 10, + "column": 2 + }, + "end": { + "line": 10, + "column": 13 + } + }, + "test": { + "type": "Identifier", + "start": 155, + "end": 156, + "loc": { + "start": { + "line": 10, + "column": 4 + }, + "end": { + "line": 10, + "column": 5 + }, + "identifierName": "i" + }, + "name": "i" + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 158, + "end": 164, + "loc": { + "start": { + "line": 10, + "column": 7 + }, + "end": { + "line": 10, + "column": 13 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 158, + "end": 159, + "loc": { + "start": { + "line": 10, + "column": 7 + }, + "end": { + "line": 10, + "column": 8 + }, + "identifierName": "i" + }, + "name": "i" + } + ], + "skinny": false, + "body": { + "type": "Identifier", + "start": 163, + "end": 164, + "loc": { + "start": { + "line": 10, + "column": 12 + }, + "end": { + "line": 10, + "column": 13 + }, + "identifierName": "i" + }, + "name": "i" + } + } + }, + { + "type": "MatchCase", + "start": 167, + "end": 180, + "loc": { + "start": { + "line": 11, + "column": 2 + }, + "end": { + "line": 11, + "column": 15 + } + }, + "test": { + "type": "Identifier", + "start": 169, + "end": 170, + "loc": { + "start": { + "line": 11, + "column": 4 + }, + "end": { + "line": 11, + "column": 5 + }, + "identifierName": "j" + }, + "name": "j" + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 172, + "end": 180, + "loc": { + "start": { + "line": 11, + "column": 7 + }, + "end": { + "line": 11, + "column": 15 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 173, + "end": 174, + "loc": { + "start": { + "line": 11, + "column": 8 + }, + "end": { + "line": 11, + "column": 9 + }, + "identifierName": "j" + }, + "name": "j" + } + ], + "skinny": false, + "body": { + "type": "Identifier", + "start": 179, + "end": 180, + "loc": { + "start": { + "line": 11, + "column": 14 + }, + "end": { + "line": 11, + "column": 15 + }, + "identifierName": "j" + }, + "name": "j" + } + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/match/async/actual.js b/test/fixtures/lightscript/match/async/actual.js new file mode 100644 index 0000000000..1482f84c8f --- /dev/null +++ b/test/fixtures/lightscript/match/async/actual.js @@ -0,0 +1,8 @@ +f() -/> + <- match x: + | a, -/> 1 + | b, -/> + <- z() + | c, async y => await y + | d, =/> d() + | e, => e() diff --git a/test/fixtures/lightscript/match/async/expected.json b/test/fixtures/lightscript/match/async/expected.json new file mode 100644 index 0000000000..a9c9fb063c --- /dev/null +++ b/test/fixtures/lightscript/match/async/expected.json @@ -0,0 +1,641 @@ +{ + "type": "File", + "start": 0, + "end": 123, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 8, + "column": 15 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 123, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 8, + "column": 15 + } + }, + "sourceType": "script", + "body": [ + { + "type": "NamedArrowDeclaration", + "start": 0, + "end": 123, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 8, + "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": true, + "params": [], + "skinny": true, + "body": { + "type": "BlockStatement", + "start": 4, + "end": 123, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 8, + "column": 15 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 10, + "end": 123, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 8, + "column": 15 + } + }, + "expression": { + "type": "AwaitExpression", + "start": 10, + "end": 123, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 8, + "column": 15 + } + }, + "argument": { + "type": "MatchExpression", + "start": 13, + "end": 123, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 8, + "column": 15 + } + }, + "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": 36, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "test": { + "type": "Identifier", + "start": 28, + "end": 29, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 7 + }, + "identifierName": "a" + }, + "name": "a" + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 31, + "end": 36, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": true, + "params": [], + "skinny": true, + "body": { + "type": "NumericLiteral", + "start": 35, + "end": 36, + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + }, + { + "type": "MatchCase", + "start": 41, + "end": 62, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 5, + "column": 12 + } + }, + "test": { + "type": "Identifier", + "start": 43, + "end": 44, + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 7 + }, + "identifierName": "b" + }, + "name": "b" + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 46, + "end": 62, + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 5, + "column": 12 + } + }, + "id": null, + "generator": false, + "expression": false, + "async": true, + "params": [], + "skinny": true, + "body": { + "type": "BlockStatement", + "start": 46, + "end": 62, + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 5, + "column": 12 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 56, + "end": 62, + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 5, + "column": 12 + } + }, + "expression": { + "type": "AwaitExpression", + "start": 56, + "end": 62, + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 5, + "column": 12 + } + }, + "argument": { + "type": "CallExpression", + "start": 59, + "end": 62, + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 5, + "column": 12 + } + }, + "callee": { + "type": "Identifier", + "start": 59, + "end": 60, + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 5, + "column": 10 + }, + "identifierName": "z" + }, + "name": "z" + }, + "arguments": [] + } + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + }, + { + "type": "MatchCase", + "start": 67, + "end": 90, + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 27 + } + }, + "test": { + "type": "Identifier", + "start": 69, + "end": 70, + "loc": { + "start": { + "line": 6, + "column": 6 + }, + "end": { + "line": 6, + "column": 7 + }, + "identifierName": "c" + }, + "name": "c" + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 72, + "end": 90, + "loc": { + "start": { + "line": 6, + "column": 9 + }, + "end": { + "line": 6, + "column": 27 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": true, + "params": [ + { + "type": "Identifier", + "start": 78, + "end": 79, + "loc": { + "start": { + "line": 6, + "column": 15 + }, + "end": { + "line": 6, + "column": 16 + }, + "identifierName": "y" + }, + "name": "y" + } + ], + "skinny": false, + "body": { + "type": "AwaitExpression", + "start": 83, + "end": 90, + "loc": { + "start": { + "line": 6, + "column": 20 + }, + "end": { + "line": 6, + "column": 27 + } + }, + "argument": { + "type": "Identifier", + "start": 89, + "end": 90, + "loc": { + "start": { + "line": 6, + "column": 26 + }, + "end": { + "line": 6, + "column": 27 + }, + "identifierName": "y" + }, + "name": "y" + } + } + } + }, + { + "type": "MatchCase", + "start": 95, + "end": 107, + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 16 + } + }, + "test": { + "type": "Identifier", + "start": 97, + "end": 98, + "loc": { + "start": { + "line": 7, + "column": 6 + }, + "end": { + "line": 7, + "column": 7 + }, + "identifierName": "d" + }, + "name": "d" + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 100, + "end": 107, + "loc": { + "start": { + "line": 7, + "column": 9 + }, + "end": { + "line": 7, + "column": 16 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": true, + "params": [], + "skinny": false, + "body": { + "type": "CallExpression", + "start": 104, + "end": 107, + "loc": { + "start": { + "line": 7, + "column": 13 + }, + "end": { + "line": 7, + "column": 16 + } + }, + "callee": { + "type": "Identifier", + "start": 104, + "end": 105, + "loc": { + "start": { + "line": 7, + "column": 13 + }, + "end": { + "line": 7, + "column": 14 + }, + "identifierName": "d" + }, + "name": "d" + }, + "arguments": [] + } + } + }, + { + "type": "MatchCase", + "start": 112, + "end": 123, + "loc": { + "start": { + "line": 8, + "column": 4 + }, + "end": { + "line": 8, + "column": 15 + } + }, + "test": { + "type": "Identifier", + "start": 114, + "end": 115, + "loc": { + "start": { + "line": 8, + "column": 6 + }, + "end": { + "line": 8, + "column": 7 + }, + "identifierName": "e" + }, + "name": "e" + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 117, + "end": 123, + "loc": { + "start": { + "line": 8, + "column": 9 + }, + "end": { + "line": 8, + "column": 15 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": false, + "body": { + "type": "CallExpression", + "start": 120, + "end": 123, + "loc": { + "start": { + "line": 8, + "column": 12 + }, + "end": { + "line": 8, + "column": 15 + } + }, + "callee": { + "type": "Identifier", + "start": 120, + "end": 121, + "loc": { + "start": { + "line": 8, + "column": 12 + }, + "end": { + "line": 8, + "column": 13 + }, + "identifierName": "e" + }, + "name": "e" + }, + "arguments": [] + } + } + } + ] + } + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/match/binary-both-subscripts/actual.js b/test/fixtures/lightscript/match/binary-both-subscripts/actual.js new file mode 100644 index 0000000000..4f4257f56d --- /dev/null +++ b/test/fixtures/lightscript/match/binary-both-subscripts/actual.js @@ -0,0 +1,2 @@ +match x: + | .a + .b, -> 'has a and b' diff --git a/test/fixtures/lightscript/match/binary-both-subscripts/expected.json b/test/fixtures/lightscript/match/binary-both-subscripts/expected.json new file mode 100644 index 0000000000..429d321f8e --- /dev/null +++ b/test/fixtures/lightscript/match/binary-both-subscripts/expected.json @@ -0,0 +1,251 @@ +{ + "type": "File", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "expression": { + "type": "MatchExpression", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "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": "BinaryExpression", + "start": 13, + "end": 20, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "left": { + "type": "MemberExpression", + "start": 13, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "object": { + "type": "PlaceholderExpression", + "start": 12, + "end": 13, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + } + } + }, + "property": { + "type": "Identifier", + "start": 14, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 6 + }, + "identifierName": "a" + }, + "name": "a" + }, + "computed": false + }, + "operator": "+", + "right": { + "type": "MemberExpression", + "start": 18, + "end": 20, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "object": { + "type": "PlaceholderExpression", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 9 + } + } + }, + "property": { + "type": "Identifier", + "start": 19, + "end": 20, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + }, + "identifierName": "b" + }, + "name": "b" + }, + "computed": false + } + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 22, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 25, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "extra": { + "rawValue": "has a and b", + "raw": "'has a and b'" + }, + "value": "has a and b" + } + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/match/binary/actual.js b/test/fixtures/lightscript/match/binary/actual.js new file mode 100644 index 0000000000..102fdb8fe4 --- /dev/null +++ b/test/fixtures/lightscript/match/binary/actual.js @@ -0,0 +1,8 @@ +match x: + | > 2, -> "bigger than two" + | > 3 and > 2, -> "so cool" + | + 3 == 4, -> "its one shhh" + | +1 or -1, -> "equal to one or negative one" + | -1 or +1, -> "equal to one or negative one" + | instanceof Class, -> "its a Class thing!" + | ** 2 == b ** 2 + c ** 2, -> "triangle?" diff --git a/test/fixtures/lightscript/match/binary/expected.json b/test/fixtures/lightscript/match/binary/expected.json new file mode 100644 index 0000000000..f39ca6e176 --- /dev/null +++ b/test/fixtures/lightscript/match/binary/expected.json @@ -0,0 +1,1160 @@ +{ + "type": "File", + "start": 0, + "end": 286, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 8, + "column": 43 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 286, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 8, + "column": 43 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 286, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 8, + "column": 43 + } + }, + "expression": { + "type": "MatchExpression", + "start": 0, + "end": 286, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 8, + "column": 43 + } + }, + "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": "BinaryExpression", + "start": 13, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "left": { + "type": "PlaceholderExpression", + "start": 12, + "end": 13, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + } + } + }, + "operator": ">", + "right": { + "type": "NumericLiteral", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 18, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 21, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "extra": { + "rawValue": "bigger than two", + "raw": "\"bigger than two\"" + }, + "value": "bigger than two" + } + } + }, + { + "type": "MatchCase", + "start": 41, + "end": 68, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 29 + } + }, + "test": { + "type": "LogicalExpression", + "start": 43, + "end": 54, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "left": { + "type": "BinaryExpression", + "start": 43, + "end": 46, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 7 + } + }, + "left": { + "type": "PlaceholderExpression", + "start": 42, + "end": 43, + "loc": { + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 4 + } + } + }, + "operator": ">", + "right": { + "type": "NumericLiteral", + "start": 45, + "end": 46, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 7 + } + }, + "extra": { + "rawValue": 3, + "raw": "3" + }, + "value": 3 + } + }, + "operator": "&&", + "right": { + "type": "BinaryExpression", + "start": 51, + "end": 54, + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "left": { + "type": "PlaceholderExpression", + "start": 50, + "end": 51, + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 12 + } + } + }, + "operator": ">", + "right": { + "type": "NumericLiteral", + "start": 53, + "end": 54, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + } + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 56, + "end": 68, + "loc": { + "start": { + "line": 3, + "column": 17 + }, + "end": { + "line": 3, + "column": 29 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 59, + "end": 68, + "loc": { + "start": { + "line": 3, + "column": 20 + }, + "end": { + "line": 3, + "column": 29 + } + }, + "extra": { + "rawValue": "so cool", + "raw": "\"so cool\"" + }, + "value": "so cool" + } + } + }, + { + "type": "MatchCase", + "start": 71, + "end": 100, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 31 + } + }, + "test": { + "type": "BinaryExpression", + "start": 73, + "end": 81, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 12 + } + }, + "left": { + "type": "BinaryExpression", + "start": 73, + "end": 76, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 7 + } + }, + "left": { + "type": "PlaceholderExpression", + "start": 72, + "end": 73, + "loc": { + "start": { + "line": 4, + "column": 3 + }, + "end": { + "line": 4, + "column": 4 + } + } + }, + "operator": "+", + "right": { + "type": "NumericLiteral", + "start": 75, + "end": 76, + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 7 + } + }, + "extra": { + "rawValue": 3, + "raw": "3" + }, + "value": 3 + } + }, + "operator": "===", + "right": { + "type": "NumericLiteral", + "start": 80, + "end": 81, + "loc": { + "start": { + "line": 4, + "column": 11 + }, + "end": { + "line": 4, + "column": 12 + } + }, + "extra": { + "rawValue": 4, + "raw": "4" + }, + "value": 4 + } + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 83, + "end": 100, + "loc": { + "start": { + "line": 4, + "column": 14 + }, + "end": { + "line": 4, + "column": 31 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 86, + "end": 100, + "loc": { + "start": { + "line": 4, + "column": 17 + }, + "end": { + "line": 4, + "column": 31 + } + }, + "extra": { + "rawValue": "its one shhh", + "raw": "\"its one shhh\"" + }, + "value": "its one shhh" + } + } + }, + { + "type": "MatchCase", + "start": 103, + "end": 148, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 47 + } + }, + "test": { + "type": "LogicalExpression", + "start": 105, + "end": 113, + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 12 + } + }, + "left": { + "type": "UnaryExpression", + "start": 105, + "end": 107, + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 6 + } + }, + "operator": "+", + "prefix": true, + "argument": { + "type": "NumericLiteral", + "start": 106, + "end": 107, + "loc": { + "start": { + "line": 5, + "column": 5 + }, + "end": { + "line": 5, + "column": 6 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + }, + "extra": { + "parenthesizedArgument": false + } + }, + "operator": "||", + "right": { + "type": "UnaryExpression", + "start": 111, + "end": 113, + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 12 + } + }, + "operator": "-", + "prefix": true, + "argument": { + "type": "NumericLiteral", + "start": 112, + "end": 113, + "loc": { + "start": { + "line": 5, + "column": 11 + }, + "end": { + "line": 5, + "column": 12 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + }, + "extra": { + "parenthesizedArgument": false + } + } + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 115, + "end": 148, + "loc": { + "start": { + "line": 5, + "column": 14 + }, + "end": { + "line": 5, + "column": 47 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 118, + "end": 148, + "loc": { + "start": { + "line": 5, + "column": 17 + }, + "end": { + "line": 5, + "column": 47 + } + }, + "extra": { + "rawValue": "equal to one or negative one", + "raw": "\"equal to one or negative one\"" + }, + "value": "equal to one or negative one" + } + } + }, + { + "type": "MatchCase", + "start": 151, + "end": 196, + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 47 + } + }, + "test": { + "type": "LogicalExpression", + "start": 153, + "end": 161, + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 12 + } + }, + "left": { + "type": "UnaryExpression", + "start": 153, + "end": 155, + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 6 + } + }, + "operator": "-", + "prefix": true, + "argument": { + "type": "NumericLiteral", + "start": 154, + "end": 155, + "loc": { + "start": { + "line": 6, + "column": 5 + }, + "end": { + "line": 6, + "column": 6 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + }, + "extra": { + "parenthesizedArgument": false + } + }, + "operator": "||", + "right": { + "type": "UnaryExpression", + "start": 159, + "end": 161, + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 12 + } + }, + "operator": "+", + "prefix": true, + "argument": { + "type": "NumericLiteral", + "start": 160, + "end": 161, + "loc": { + "start": { + "line": 6, + "column": 11 + }, + "end": { + "line": 6, + "column": 12 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + }, + "extra": { + "parenthesizedArgument": false + } + } + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 163, + "end": 196, + "loc": { + "start": { + "line": 6, + "column": 14 + }, + "end": { + "line": 6, + "column": 47 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 166, + "end": 196, + "loc": { + "start": { + "line": 6, + "column": 17 + }, + "end": { + "line": 6, + "column": 47 + } + }, + "extra": { + "rawValue": "equal to one or negative one", + "raw": "\"equal to one or negative one\"" + }, + "value": "equal to one or negative one" + } + } + }, + { + "type": "MatchCase", + "start": 199, + "end": 242, + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 45 + } + }, + "test": { + "type": "BinaryExpression", + "start": 201, + "end": 217, + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 20 + } + }, + "left": { + "type": "PlaceholderExpression", + "start": 200, + "end": 201, + "loc": { + "start": { + "line": 7, + "column": 3 + }, + "end": { + "line": 7, + "column": 4 + } + } + }, + "operator": "instanceof", + "right": { + "type": "Identifier", + "start": 212, + "end": 217, + "loc": { + "start": { + "line": 7, + "column": 15 + }, + "end": { + "line": 7, + "column": 20 + }, + "identifierName": "Class" + }, + "name": "Class" + } + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 219, + "end": 242, + "loc": { + "start": { + "line": 7, + "column": 22 + }, + "end": { + "line": 7, + "column": 45 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 222, + "end": 242, + "loc": { + "start": { + "line": 7, + "column": 25 + }, + "end": { + "line": 7, + "column": 45 + } + }, + "extra": { + "rawValue": "its a Class thing!", + "raw": "\"its a Class thing!\"" + }, + "value": "its a Class thing!" + } + } + }, + { + "type": "MatchCase", + "start": 245, + "end": 286, + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 43 + } + }, + "test": { + "type": "BinaryExpression", + "start": 247, + "end": 270, + "loc": { + "start": { + "line": 8, + "column": 4 + }, + "end": { + "line": 8, + "column": 27 + } + }, + "left": { + "type": "BinaryExpression", + "start": 247, + "end": 251, + "loc": { + "start": { + "line": 8, + "column": 4 + }, + "end": { + "line": 8, + "column": 8 + } + }, + "left": { + "type": "PlaceholderExpression", + "start": 246, + "end": 247, + "loc": { + "start": { + "line": 8, + "column": 3 + }, + "end": { + "line": 8, + "column": 4 + } + } + }, + "operator": "**", + "right": { + "type": "NumericLiteral", + "start": 250, + "end": 251, + "loc": { + "start": { + "line": 8, + "column": 7 + }, + "end": { + "line": 8, + "column": 8 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + }, + "operator": "===", + "right": { + "type": "BinaryExpression", + "start": 255, + "end": 270, + "loc": { + "start": { + "line": 8, + "column": 12 + }, + "end": { + "line": 8, + "column": 27 + } + }, + "left": { + "type": "BinaryExpression", + "start": 255, + "end": 261, + "loc": { + "start": { + "line": 8, + "column": 12 + }, + "end": { + "line": 8, + "column": 18 + } + }, + "left": { + "type": "Identifier", + "start": 255, + "end": 256, + "loc": { + "start": { + "line": 8, + "column": 12 + }, + "end": { + "line": 8, + "column": 13 + }, + "identifierName": "b" + }, + "name": "b" + }, + "operator": "**", + "right": { + "type": "NumericLiteral", + "start": 260, + "end": 261, + "loc": { + "start": { + "line": 8, + "column": 17 + }, + "end": { + "line": 8, + "column": 18 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + }, + "operator": "+", + "right": { + "type": "BinaryExpression", + "start": 264, + "end": 270, + "loc": { + "start": { + "line": 8, + "column": 21 + }, + "end": { + "line": 8, + "column": 27 + } + }, + "left": { + "type": "Identifier", + "start": 264, + "end": 265, + "loc": { + "start": { + "line": 8, + "column": 21 + }, + "end": { + "line": 8, + "column": 22 + }, + "identifierName": "c" + }, + "name": "c" + }, + "operator": "**", + "right": { + "type": "NumericLiteral", + "start": 269, + "end": 270, + "loc": { + "start": { + "line": 8, + "column": 26 + }, + "end": { + "line": 8, + "column": 27 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + } + } + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 272, + "end": 286, + "loc": { + "start": { + "line": 8, + "column": 29 + }, + "end": { + "line": 8, + "column": 43 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 275, + "end": 286, + "loc": { + "start": { + "line": 8, + "column": 32 + }, + "end": { + "line": 8, + "column": 43 + } + }, + "extra": { + "rawValue": "triangle?", + "raw": "\"triangle?\"" + }, + "value": "triangle?" + } + } + } + ] + } + } + ], + "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..56386219b5 --- /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/expected.json b/test/fixtures/lightscript/match/bitwise-or-consequent-inline/expected.json new file mode 100644 index 0000000000..067347ad4d --- /dev/null +++ b/test/fixtures/lightscript/match/bitwise-or-consequent-inline/expected.json @@ -0,0 +1,230 @@ +{ + "type": "File", + "start": 0, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "sourceType": "script", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "kind": "const", + "extra": { + "implicit": true + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 0, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "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": 28, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "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": 3, + "raw": "3" + }, + "value": 3 + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 20, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "BinaryExpression", + "start": 23, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "left": { + "type": "Identifier", + "start": 23, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + }, + "operator": "|", + "right": { + "type": "NumericLiteral", + "start": 27, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + } + } + ] + } + } + ] + } + ], + "directives": [] + } +} \ No newline at end of file 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..212e169860 --- /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/expected.json b/test/fixtures/lightscript/match/bitwise-or-test-explicit/expected.json new file mode 100644 index 0000000000..7dade6cc34 --- /dev/null +++ b/test/fixtures/lightscript/match/bitwise-or-test-explicit/expected.json @@ -0,0 +1,230 @@ +{ + "type": "File", + "start": 0, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 28 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 28 + } + }, + "sourceType": "script", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 28 + } + }, + "kind": "const", + "extra": { + "implicit": true + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 0, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "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": 41, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 2, + "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": 41, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 28 + } + }, + "test": { + "type": "BinaryExpression", + "start": 17, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "left": { + "type": "Identifier", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + }, + "identifierName": "x" + }, + "name": "x" + }, + "operator": "|", + "right": { + "type": "NumericLiteral", + "start": 21, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "extra": { + "rawValue": 3, + "raw": "3" + }, + "value": 3 + } + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 24, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 28 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 27, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 28 + } + }, + "extra": { + "rawValue": "bitwise or 3", + "raw": "\"bitwise or 3\"" + }, + "value": "bitwise or 3" + } + } + } + ] + } + } + ] + } + ], + "directives": [] + } +} \ No newline at end of file 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..aa828624dd --- /dev/null +++ b/test/fixtures/lightscript/match/curlies-parens/actual.js @@ -0,0 +1,4 @@ +a = match (x) { +| > 2, -> "bigger than 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..c3f7b8422f --- /dev/null +++ b/test/fixtures/lightscript/match/curlies-parens/expected.json @@ -0,0 +1,300 @@ +{ + "type": "File", + "start": 0, + "end": 75, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 75, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 75, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "kind": "const", + "extra": { + "implicit": true + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 0, + "end": 75, + "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": 75, + "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": 43, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 27 + } + }, + "test": { + "type": "BinaryExpression", + "start": 18, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 5 + } + }, + "left": { + "type": "PlaceholderExpression", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 2 + } + } + }, + "operator": ">", + "right": { + "type": "NumericLiteral", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 23, + "end": 43, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 27 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 26, + "end": 43, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 27 + } + }, + "extra": { + "rawValue": "bigger than two", + "raw": "\"bigger than two\"" + }, + "value": "bigger than two" + } + } + }, + { + "type": "MatchCase", + "start": 44, + "end": 73, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 29 + } + }, + "test": { + "type": "MatchElse", + "start": 46, + "end": 50, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 6 + } + } + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 52, + "end": 73, + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 29 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 55, + "end": 73, + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 29 + } + }, + "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..2e45b3aa67 --- /dev/null +++ b/test/fixtures/lightscript/match/curlies/actual.js @@ -0,0 +1,4 @@ +a = match x { +| > 2, -> "bigger than 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..b832ce560d --- /dev/null +++ b/test/fixtures/lightscript/match/curlies/expected.json @@ -0,0 +1,299 @@ +{ + "type": "File", + "start": 0, + "end": 73, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 73, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 73, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "kind": "const", + "extra": { + "implicit": true + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 0, + "end": 73, + "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": 73, + "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": 41, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 27 + } + }, + "test": { + "type": "BinaryExpression", + "start": 16, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 5 + } + }, + "left": { + "type": "PlaceholderExpression", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 2 + } + } + }, + "operator": ">", + "right": { + "type": "NumericLiteral", + "start": 18, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 21, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 27 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 24, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 27 + } + }, + "extra": { + "rawValue": "bigger than two", + "raw": "\"bigger than two\"" + }, + "value": "bigger than two" + } + } + }, + { + "type": "MatchCase", + "start": 42, + "end": 71, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 29 + } + }, + "test": { + "type": "MatchElse", + "start": 44, + "end": 48, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 6 + } + } + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 50, + "end": 71, + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 29 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 53, + "end": 71, + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 29 + } + }, + "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/dot-then-binary-illegal/actual.js b/test/fixtures/lightscript/match/dot-then-binary-illegal/actual.js new file mode 100644 index 0000000000..45dde14f6e --- /dev/null +++ b/test/fixtures/lightscript/match/dot-then-binary-illegal/actual.js @@ -0,0 +1,2 @@ +match x: + | . < 4, -> 'bad' diff --git a/test/fixtures/lightscript/match/dot-then-binary-illegal/options.json b/test/fixtures/lightscript/match/dot-then-binary-illegal/options.json new file mode 100644 index 0000000000..9660494a29 --- /dev/null +++ b/test/fixtures/lightscript/match/dot-then-binary-illegal/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token (2:6)" +} 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..1843706a76 --- /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..6c5825b8df --- /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..c8a4cdeb5b --- /dev/null +++ b/test/fixtures/lightscript/match/else-solo/expected.json @@ -0,0 +1,154 @@ +{ + "type": "File", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 31 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 31 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 31 + } + }, + "expression": { + "type": "MatchExpression", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 31 + } + }, + "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": 40, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 31 + } + }, + "test": { + "type": "MatchElse", + "start": 13, + "end": 17, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 8 + } + } + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 19, + "end": 40, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 31 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 22, + "end": 40, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 31 + } + }, + "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..3dc3e7fe46 --- /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..10c56abcd6 --- /dev/null +++ b/test/fixtures/lightscript/match/else/expected.json @@ -0,0 +1,221 @@ +{ + "type": "File", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "expression": { + "type": "MatchExpression", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "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": 20, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "test": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + }, + "identifierName": "a" + }, + "name": "a" + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 16, + "end": 20, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "Identifier", + "start": 19, + "end": 20, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + }, + "identifierName": "b" + }, + "name": "b" + } + } + }, + { + "type": "MatchCase", + "start": 23, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "test": { + "type": "MatchElse", + "start": 25, + "end": 29, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 8 + } + } + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 31, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "Identifier", + "start": 34, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 14 + }, + "identifierName": "c" + }, + "name": "c" + } + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file 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..004a8c60bb --- /dev/null +++ b/test/fixtures/lightscript/match/in-assignment/actual.js @@ -0,0 +1,3 @@ +a = match x: + | > 2, -> "bigger than 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..d3354afa5d --- /dev/null +++ b/test/fixtures/lightscript/match/in-assignment/expected.json @@ -0,0 +1,299 @@ +{ + "type": "File", + "start": 0, + "end": 74, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 31 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 74, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 31 + } + }, + "sourceType": "script", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 74, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 31 + } + }, + "kind": "const", + "extra": { + "implicit": true + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 0, + "end": 74, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 31 + } + }, + "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": 74, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 3, + "column": 31 + } + }, + "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": 42, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "test": { + "type": "BinaryExpression", + "start": 17, + "end": 20, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "left": { + "type": "PlaceholderExpression", + "start": 16, + "end": 17, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + } + } + }, + "operator": ">", + "right": { + "type": "NumericLiteral", + "start": 19, + "end": 20, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 22, + "end": 42, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 25, + "end": 42, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "extra": { + "rawValue": "bigger than two", + "raw": "\"bigger than two\"" + }, + "value": "bigger than two" + } + } + }, + { + "type": "MatchCase", + "start": 45, + "end": 74, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 31 + } + }, + "test": { + "type": "MatchElse", + "start": 47, + "end": 51, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 8 + } + } + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 53, + "end": 74, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 31 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 56, + "end": 74, + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 31 + } + }, + "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..d02c205ab5 --- /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..e43e10dd3d --- /dev/null +++ b/test/fixtures/lightscript/match/jsx-result/expected.json @@ -0,0 +1,186 @@ +{ + "type": "File", + "start": 0, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "expression": { + "type": "MatchExpression", + "start": 0, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "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": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + }, + "identifierName": "y" + }, + "name": "y" + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 16, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "JSXElement", + "start": 19, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "openingElement": { + "type": "JSXOpeningElement", + "start": 19, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "attributes": [], + "name": { + "type": "JSXIdentifier", + "start": 20, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "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..565ab8a3a4 --- /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..7c05159f45 --- /dev/null +++ b/test/fixtures/lightscript/match/jsx-test-illegal/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token (2:10)" +} diff --git a/test/fixtures/lightscript/match/less-than/actual.js b/test/fixtures/lightscript/match/less-than/actual.js new file mode 100644 index 0000000000..54ba1ab1e3 --- /dev/null +++ b/test/fixtures/lightscript/match/less-than/actual.js @@ -0,0 +1,3 @@ +match x: + | < 3, -> "not jsx" + | <3, -> "not jsx" diff --git a/test/fixtures/lightscript/match/less-than/expected.json b/test/fixtures/lightscript/match/less-than/expected.json new file mode 100644 index 0000000000..8059b81eab --- /dev/null +++ b/test/fixtures/lightscript/match/less-than/expected.json @@ -0,0 +1,297 @@ +{ + "type": "File", + "start": 0, + "end": 51, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 20 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 51, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 20 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 51, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 20 + } + }, + "expression": { + "type": "MatchExpression", + "start": 0, + "end": 51, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 20 + } + }, + "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": 30, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "test": { + "type": "BinaryExpression", + "start": 13, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "left": { + "type": "PlaceholderExpression", + "start": 12, + "end": 13, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + } + } + }, + "operator": "<", + "right": { + "type": "NumericLiteral", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "extra": { + "rawValue": 3, + "raw": "3" + }, + "value": 3 + } + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 18, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 21, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "extra": { + "rawValue": "not jsx", + "raw": "\"not jsx\"" + }, + "value": "not jsx" + } + } + }, + { + "type": "MatchCase", + "start": 33, + "end": 51, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 20 + } + }, + "test": { + "type": "BinaryExpression", + "start": 35, + "end": 37, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 6 + } + }, + "left": { + "type": "PlaceholderExpression", + "start": 34, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 4 + } + } + }, + "operator": "<", + "right": { + "type": "NumericLiteral", + "start": 36, + "end": 37, + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 6 + } + }, + "extra": { + "rawValue": 3, + "raw": "3" + }, + "value": 3 + } + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 39, + "end": 51, + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 20 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 42, + "end": 51, + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 20 + } + }, + "extra": { + "rawValue": "not jsx", + "raw": "\"not jsx\"" + }, + "value": "not jsx" + } + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/match/literals/actual.js b/test/fixtures/lightscript/match/literals/actual.js new file mode 100644 index 0000000000..a708fe5882 --- /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..3e15f8f989 --- /dev/null +++ b/test/fixtures/lightscript/match/literals/expected.json @@ -0,0 +1,867 @@ +{ + "type": "File", + "start": 0, + "end": 265, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 11, + "column": 28 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 265, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 11, + "column": 28 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 265, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 11, + "column": 28 + } + }, + "expression": { + "type": "MatchExpression", + "start": 0, + "end": 265, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 11, + "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": 24, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "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": "ArrowFunctionExpression", + "start": 16, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 19, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "extra": { + "rawValue": "two", + "raw": "\"two\"" + }, + "value": "two" + } + } + }, + { + "type": "MatchCase", + "start": 27, + "end": 45, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 20 + } + }, + "test": { + "type": "StringLiteral", + "start": 29, + "end": 36, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "extra": { + "rawValue": "hello", + "raw": "\"hello\"" + }, + "value": "hello" + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 38, + "end": 45, + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 20 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 41, + "end": 45, + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 20 + } + }, + "extra": { + "rawValue": "hi", + "raw": "\"hi\"" + }, + "value": "hi" + } + } + }, + { + "type": "MatchCase", + "start": 48, + "end": 66, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 20 + } + }, + "test": { + "type": "RegExpLiteral", + "start": 50, + "end": 55, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 9 + } + }, + "extra": { + "raw": "/\\w+/" + }, + "pattern": "\\w+", + "flags": "" + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 57, + "end": 66, + "loc": { + "start": { + "line": 4, + "column": 11 + }, + "end": { + "line": 4, + "column": 20 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 60, + "end": 66, + "loc": { + "start": { + "line": 4, + "column": 14 + }, + "end": { + "line": 4, + "column": 20 + } + }, + "extra": { + "rawValue": "word", + "raw": "\"word\"" + }, + "value": "word" + } + } + }, + { + "type": "MatchCase", + "start": 69, + "end": 89, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 22 + } + }, + "test": { + "type": "RegExpLiteral", + "start": 71, + "end": 78, + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 11 + } + }, + "extra": { + "raw": "/\\w+/ig" + }, + "pattern": "\\w+", + "flags": "ig" + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 80, + "end": 89, + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 22 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 83, + "end": 89, + "loc": { + "start": { + "line": 5, + "column": 16 + }, + "end": { + "line": 5, + "column": 22 + } + }, + "extra": { + "rawValue": "word", + "raw": "\"word\"" + }, + "value": "word" + } + } + }, + { + "type": "MatchCase", + "start": 92, + "end": 124, + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 34 + } + }, + "test": { + "type": "UnaryExpression", + "start": 94, + "end": 96, + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 6 + } + }, + "operator": "+", + "prefix": true, + "argument": { + "type": "NumericLiteral", + "start": 95, + "end": 96, + "loc": { + "start": { + "line": 6, + "column": 5 + }, + "end": { + "line": 6, + "column": 6 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + }, + "extra": { + "parenthesizedArgument": false + } + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 98, + "end": 124, + "loc": { + "start": { + "line": 6, + "column": 8 + }, + "end": { + "line": 6, + "column": 34 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 101, + "end": 124, + "loc": { + "start": { + "line": 6, + "column": 11 + }, + "end": { + "line": 6, + "column": 34 + } + }, + "extra": { + "rawValue": "equal to positive one", + "raw": "\"equal to positive one\"" + }, + "value": "equal to positive one" + } + } + }, + { + "type": "MatchCase", + "start": 127, + "end": 159, + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 34 + } + }, + "test": { + "type": "UnaryExpression", + "start": 129, + "end": 131, + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 6 + } + }, + "operator": "-", + "prefix": true, + "argument": { + "type": "NumericLiteral", + "start": 130, + "end": 131, + "loc": { + "start": { + "line": 7, + "column": 5 + }, + "end": { + "line": 7, + "column": 6 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + }, + "extra": { + "parenthesizedArgument": false + } + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 133, + "end": 159, + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 34 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 136, + "end": 159, + "loc": { + "start": { + "line": 7, + "column": 11 + }, + "end": { + "line": 7, + "column": 34 + } + }, + "extra": { + "rawValue": "equal to negative one", + "raw": "\"equal to negative one\"" + }, + "value": "equal to negative one" + } + } + }, + { + "type": "MatchCase", + "start": 162, + "end": 179, + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 19 + } + }, + "test": { + "type": "NullLiteral", + "start": 164, + "end": 168, + "loc": { + "start": { + "line": 8, + "column": 4 + }, + "end": { + "line": 8, + "column": 8 + } + } + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 170, + "end": 179, + "loc": { + "start": { + "line": 8, + "column": 10 + }, + "end": { + "line": 8, + "column": 19 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 173, + "end": 179, + "loc": { + "start": { + "line": 8, + "column": 13 + }, + "end": { + "line": 8, + "column": 19 + } + }, + "extra": { + "rawValue": "null", + "raw": "\"null\"" + }, + "value": "null" + } + } + }, + { + "type": "MatchCase", + "start": 182, + "end": 209, + "loc": { + "start": { + "line": 9, + "column": 2 + }, + "end": { + "line": 9, + "column": 29 + } + }, + "test": { + "type": "Identifier", + "start": 184, + "end": 193, + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 13 + }, + "identifierName": "undefined" + }, + "name": "undefined" + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 195, + "end": 209, + "loc": { + "start": { + "line": 9, + "column": 15 + }, + "end": { + "line": 9, + "column": 29 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 198, + "end": 209, + "loc": { + "start": { + "line": 9, + "column": 18 + }, + "end": { + "line": 9, + "column": 29 + } + }, + "extra": { + "rawValue": "undefined", + "raw": "\"undefined\"" + }, + "value": "undefined" + } + } + }, + { + "type": "MatchCase", + "start": 212, + "end": 236, + "loc": { + "start": { + "line": 10, + "column": 2 + }, + "end": { + "line": 10, + "column": 26 + } + }, + "test": { + "type": "BooleanLiteral", + "start": 214, + "end": 218, + "loc": { + "start": { + "line": 10, + "column": 4 + }, + "end": { + "line": 10, + "column": 8 + } + }, + "value": true + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 220, + "end": 236, + "loc": { + "start": { + "line": 10, + "column": 10 + }, + "end": { + "line": 10, + "column": 26 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 223, + "end": 236, + "loc": { + "start": { + "line": 10, + "column": 13 + }, + "end": { + "line": 10, + "column": 26 + } + }, + "extra": { + "rawValue": "strict true", + "raw": "\"strict true\"" + }, + "value": "strict true" + } + } + }, + { + "type": "MatchCase", + "start": 239, + "end": 265, + "loc": { + "start": { + "line": 11, + "column": 2 + }, + "end": { + "line": 11, + "column": 28 + } + }, + "test": { + "type": "BooleanLiteral", + "start": 241, + "end": 246, + "loc": { + "start": { + "line": 11, + "column": 4 + }, + "end": { + "line": 11, + "column": 9 + } + }, + "value": false + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 248, + "end": 265, + "loc": { + "start": { + "line": 11, + "column": 11 + }, + "end": { + "line": 11, + "column": 28 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 251, + "end": 265, + "loc": { + "start": { + "line": 11, + "column": 14 + }, + "end": { + "line": 11, + "column": 28 + } + }, + "extra": { + "rawValue": "strict false", + "raw": "\"strict false\"" + }, + "value": "strict false" + } + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/match/multi-subscripts-illegal/actual.js b/test/fixtures/lightscript/match/multi-subscripts-illegal/actual.js new file mode 100644 index 0000000000..33f98acb0b --- /dev/null +++ b/test/fixtures/lightscript/match/multi-subscripts-illegal/actual.js @@ -0,0 +1,2 @@ +match x: + | ..d, -> 'its a func' diff --git a/test/fixtures/lightscript/match/multi-subscripts-illegal/options.json b/test/fixtures/lightscript/match/multi-subscripts-illegal/options.json new file mode 100644 index 0000000000..34002b17a3 --- /dev/null +++ b/test/fixtures/lightscript/match/multi-subscripts-illegal/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token (2:5)" +} diff --git a/test/fixtures/lightscript/match/multi-subscripts-number-WRONG/actual.js b/test/fixtures/lightscript/match/multi-subscripts-number-WRONG/actual.js new file mode 100644 index 0000000000..09029d4ecc --- /dev/null +++ b/test/fixtures/lightscript/match/multi-subscripts-number-WRONG/actual.js @@ -0,0 +1,3 @@ +match x: + | .a and .0, -> 'has a and first child' + | .0.0, -> 'first child of first child' diff --git a/test/fixtures/lightscript/match/multi-subscripts-number-WRONG/expected.json b/test/fixtures/lightscript/match/multi-subscripts-number-WRONG/expected.json new file mode 100644 index 0000000000..243eac0b1f --- /dev/null +++ b/test/fixtures/lightscript/match/multi-subscripts-number-WRONG/expected.json @@ -0,0 +1,335 @@ +{ + "type": "File", + "start": 0, + "end": 92, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 41 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 92, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 41 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 92, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 41 + } + }, + "expression": { + "type": "MatchExpression", + "start": 0, + "end": 92, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 41 + } + }, + "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": 50, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 41 + } + }, + "test": { + "type": "LogicalExpression", + "start": 13, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "left": { + "type": "MemberExpression", + "start": 13, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "object": { + "type": "PlaceholderExpression", + "start": 12, + "end": 13, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + } + } + }, + "property": { + "type": "Identifier", + "start": 14, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 6 + }, + "identifierName": "a" + }, + "name": "a" + }, + "computed": false + }, + "operator": "&&", + "right": { + "type": "NumericLiteral", + "start": 20, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "extra": { + "rawValue": 0, + "raw": ".0" + }, + "value": 0 + } + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 24, + "end": 50, + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 41 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 27, + "end": 50, + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 41 + } + }, + "extra": { + "rawValue": "has a and first child", + "raw": "'has a and first child'" + }, + "value": "has a and first child" + } + } + }, + { + "type": "MatchCase", + "start": 53, + "end": 92, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 41 + } + }, + "test": { + "type": "MemberExpression", + "start": 55, + "end": 59, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "object": { + "type": "NumericLiteral", + "start": 55, + "end": 57, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 6 + } + }, + "extra": { + "rawValue": 0, + "raw": ".0" + }, + "value": 0 + }, + "property": { + "type": "NumericLiteral", + "start": 57, + "end": 59, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + }, + "computed": true + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 61, + "end": 92, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 41 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 64, + "end": 92, + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 41 + } + }, + "extra": { + "rawValue": "first child of first child", + "raw": "'first child of first child'" + }, + "value": "first child of first child" + } + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/match/multi-subscripts-number-illegal/actual.js b/test/fixtures/lightscript/match/multi-subscripts-number-illegal/actual.js new file mode 100644 index 0000000000..1aa2f6bd46 --- /dev/null +++ b/test/fixtures/lightscript/match/multi-subscripts-number-illegal/actual.js @@ -0,0 +1,2 @@ +match x: + | ..0, -> 'bad' diff --git a/test/fixtures/lightscript/match/multi-subscripts-number-illegal/options.json b/test/fixtures/lightscript/match/multi-subscripts-number-illegal/options.json new file mode 100644 index 0000000000..34002b17a3 --- /dev/null +++ b/test/fixtures/lightscript/match/multi-subscripts-number-illegal/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token (2:5)" +} diff --git a/test/fixtures/lightscript/match/multi-subscripts/actual.js b/test/fixtures/lightscript/match/multi-subscripts/actual.js new file mode 100644 index 0000000000..a538d7d946 --- /dev/null +++ b/test/fixtures/lightscript/match/multi-subscripts/actual.js @@ -0,0 +1,3 @@ +match x: + | .a and .b, -> 'has a and b' + | ~c() or ~d(), -> 'its a func' diff --git a/test/fixtures/lightscript/match/multi-subscripts/expected.json b/test/fixtures/lightscript/match/multi-subscripts/expected.json new file mode 100644 index 0000000000..c26c00b3fe --- /dev/null +++ b/test/fixtures/lightscript/match/multi-subscripts/expected.json @@ -0,0 +1,419 @@ +{ + "type": "File", + "start": 0, + "end": 74, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 33 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 74, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 33 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 74, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 33 + } + }, + "expression": { + "type": "MatchExpression", + "start": 0, + "end": 74, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 33 + } + }, + "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": 40, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 31 + } + }, + "test": { + "type": "LogicalExpression", + "start": 13, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "left": { + "type": "MemberExpression", + "start": 13, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "object": { + "type": "PlaceholderExpression", + "start": 12, + "end": 13, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + } + } + }, + "property": { + "type": "Identifier", + "start": 14, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 6 + }, + "identifierName": "a" + }, + "name": "a" + }, + "computed": false + }, + "operator": "&&", + "right": { + "type": "MemberExpression", + "start": 20, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "object": { + "type": "PlaceholderExpression", + "start": 19, + "end": 20, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + } + } + }, + "property": { + "type": "Identifier", + "start": 21, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 13 + }, + "identifierName": "b" + }, + "name": "b" + }, + "computed": false + } + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 24, + "end": 40, + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 31 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 27, + "end": 40, + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 31 + } + }, + "extra": { + "rawValue": "has a and b", + "raw": "'has a and b'" + }, + "value": "has a and b" + } + } + }, + { + "type": "MatchCase", + "start": 43, + "end": 74, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 33 + } + }, + "test": { + "type": "LogicalExpression", + "start": 45, + "end": 57, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "left": { + "type": "TildeCallExpression", + "start": 45, + "end": 49, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "left": { + "type": "PlaceholderExpression", + "start": 44, + "end": 45, + "loc": { + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 4 + } + } + }, + "right": { + "type": "Identifier", + "start": 46, + "end": 47, + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 6 + }, + "identifierName": "c" + }, + "name": "c" + }, + "arguments": [] + }, + "operator": "||", + "right": { + "type": "TildeCallExpression", + "start": 53, + "end": 57, + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "left": { + "type": "PlaceholderExpression", + "start": 52, + "end": 53, + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 12 + } + } + }, + "right": { + "type": "Identifier", + "start": 54, + "end": 55, + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 14 + }, + "identifierName": "d" + }, + "name": "d" + }, + "arguments": [] + } + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 59, + "end": 74, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 33 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 62, + "end": 74, + "loc": { + "start": { + "line": 3, + "column": 21 + }, + "end": { + "line": 3, + "column": 33 + } + }, + "extra": { + "rawValue": "its a func", + "raw": "'its a func'" + }, + "value": "its a func" + } + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/match/nested/actual.js b/test/fixtures/lightscript/match/nested/actual.js new file mode 100644 index 0000000000..d0b680155e --- /dev/null +++ b/test/fixtures/lightscript/match/nested/actual.js @@ -0,0 +1,6 @@ +match x: + | > 2, (y) -> match y: + | > 10, -> "soo big" + | > 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..47813f720e --- /dev/null +++ b/test/fixtures/lightscript/match/nested/expected.json @@ -0,0 +1,578 @@ +{ + "type": "File", + "start": 0, + "end": 150, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 31 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 150, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 31 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 150, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 31 + } + }, + "expression": { + "type": "MatchExpression", + "start": 0, + "end": 150, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 31 + } + }, + "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": 118, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 5, + "column": 26 + } + }, + "test": { + "type": "BinaryExpression", + "start": 13, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "left": { + "type": "PlaceholderExpression", + "start": 12, + "end": 13, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + } + } + }, + "operator": ">", + "right": { + "type": "NumericLiteral", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 18, + "end": 118, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 5, + "column": 26 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 19, + "end": 20, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + }, + "identifierName": "y" + }, + "name": "y" + } + ], + "skinny": true, + "body": { + "type": "MatchExpression", + "start": 25, + "end": 118, + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 5, + "column": 26 + } + }, + "discriminant": { + "type": "Identifier", + "start": 31, + "end": 32, + "loc": { + "start": { + "line": 2, + "column": 22 + }, + "end": { + "line": 2, + "column": 23 + }, + "identifierName": "y" + }, + "name": "y" + }, + "cases": [ + { + "type": "MatchCase", + "start": 38, + "end": 58, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 24 + } + }, + "test": { + "type": "BinaryExpression", + "start": 40, + "end": 44, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "left": { + "type": "PlaceholderExpression", + "start": 39, + "end": 40, + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 6 + } + } + }, + "operator": ">", + "right": { + "type": "NumericLiteral", + "start": 42, + "end": 44, + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "extra": { + "rawValue": 10, + "raw": "10" + }, + "value": 10 + } + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 46, + "end": 58, + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 24 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 49, + "end": 58, + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 24 + } + }, + "extra": { + "rawValue": "soo big", + "raw": "\"soo big\"" + }, + "value": "soo big" + } + } + }, + { + "type": "MatchCase", + "start": 63, + "end": 91, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 32 + } + }, + "test": { + "type": "BinaryExpression", + "start": 65, + "end": 68, + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 9 + } + }, + "left": { + "type": "PlaceholderExpression", + "start": 64, + "end": 65, + "loc": { + "start": { + "line": 4, + "column": 5 + }, + "end": { + "line": 4, + "column": 6 + } + } + }, + "operator": ">", + "right": { + "type": "NumericLiteral", + "start": 67, + "end": 68, + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 9 + } + }, + "extra": { + "rawValue": 5, + "raw": "5" + }, + "value": 5 + } + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 70, + "end": 91, + "loc": { + "start": { + "line": 4, + "column": 11 + }, + "end": { + "line": 4, + "column": 32 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 73, + "end": 91, + "loc": { + "start": { + "line": 4, + "column": 14 + }, + "end": { + "line": 4, + "column": 32 + } + }, + "extra": { + "rawValue": "still pretty big", + "raw": "\"still pretty big\"" + }, + "value": "still pretty big" + } + } + }, + { + "type": "MatchCase", + "start": 96, + "end": 118, + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 26 + } + }, + "test": { + "type": "MatchElse", + "start": 98, + "end": 102, + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 5, + "column": 10 + } + } + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 104, + "end": 118, + "loc": { + "start": { + "line": 5, + "column": 12 + }, + "end": { + "line": 5, + "column": 26 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 107, + "end": 118, + "loc": { + "start": { + "line": 5, + "column": 15 + }, + "end": { + "line": 5, + "column": 26 + } + }, + "extra": { + "rawValue": "kinda big", + "raw": "\"kinda big\"" + }, + "value": "kinda big" + } + } + } + ] + } + } + }, + { + "type": "MatchCase", + "start": 121, + "end": 150, + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 31 + } + }, + "test": { + "type": "MatchElse", + "start": 123, + "end": 127, + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 8 + } + } + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 129, + "end": 150, + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 31 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 132, + "end": 150, + "loc": { + "start": { + "line": 6, + "column": 13 + }, + "end": { + "line": 6, + "column": 31 + } + }, + "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..527e589796 --- /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/parens-arent-calls/actual.js b/test/fixtures/lightscript/match/parens-arent-calls/actual.js new file mode 100644 index 0000000000..64eaeb2bf4 --- /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..6c4945ff71 --- /dev/null +++ b/test/fixtures/lightscript/match/parens-arent-calls/expected.json @@ -0,0 +1,198 @@ +{ + "type": "File", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "sourceType": "script", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "kind": "const", + "extra": { + "implicit": true + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "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": 42, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "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": 42, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "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": "ArrowFunctionExpression", + "start": 22, + "end": 42, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 25, + "end": 42, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "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..886c29fd3c --- /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..047e5e7344 --- /dev/null +++ b/test/fixtures/lightscript/match/parens-no-curlies/actual.js @@ -0,0 +1,3 @@ +a = match (x): + | > 2, -> "bigger than 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..45d8369207 --- /dev/null +++ b/test/fixtures/lightscript/match/parens-no-curlies/expected.json @@ -0,0 +1,300 @@ +{ + "type": "File", + "start": 0, + "end": 76, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 31 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 76, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 31 + } + }, + "sourceType": "script", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 76, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 31 + } + }, + "kind": "const", + "extra": { + "implicit": true + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 0, + "end": 76, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 31 + } + }, + "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": 76, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 3, + "column": 31 + } + }, + "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": 44, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "test": { + "type": "BinaryExpression", + "start": 19, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "left": { + "type": "PlaceholderExpression", + "start": 18, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + } + } + }, + "operator": ">", + "right": { + "type": "NumericLiteral", + "start": 21, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 24, + "end": 44, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 27, + "end": 44, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "extra": { + "rawValue": "bigger than two", + "raw": "\"bigger than two\"" + }, + "value": "bigger than two" + } + } + }, + { + "type": "MatchCase", + "start": 47, + "end": 76, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 31 + } + }, + "test": { + "type": "MatchElse", + "start": 49, + "end": 53, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 8 + } + } + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 55, + "end": 76, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 31 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 58, + "end": 76, + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 31 + } + }, + "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/subscript-in-tilde/actual.js b/test/fixtures/lightscript/match/subscript-in-tilde/actual.js new file mode 100644 index 0000000000..8a58cab69f --- /dev/null +++ b/test/fixtures/lightscript/match/subscript-in-tilde/actual.js @@ -0,0 +1,2 @@ +match x: + | ~c(.d), -> 'its a func' diff --git a/test/fixtures/lightscript/match/subscript-in-tilde/expected.json b/test/fixtures/lightscript/match/subscript-in-tilde/expected.json new file mode 100644 index 0000000000..e699a3926d --- /dev/null +++ b/test/fixtures/lightscript/match/subscript-in-tilde/expected.json @@ -0,0 +1,236 @@ +{ + "type": "File", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 27 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 27 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 27 + } + }, + "expression": { + "type": "MatchExpression", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 27 + } + }, + "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": 36, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 27 + } + }, + "test": { + "type": "TildeCallExpression", + "start": 13, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "left": { + "type": "PlaceholderExpression", + "start": 12, + "end": 13, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + } + } + }, + "right": { + "type": "Identifier", + "start": 14, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 6 + }, + "identifierName": "c" + }, + "name": "c" + }, + "arguments": [ + { + "type": "MemberExpression", + "start": 16, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "object": { + "type": "PlaceholderExpression", + "start": 16, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 7 + } + } + }, + "property": { + "type": "Identifier", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 9 + }, + "identifierName": "d" + }, + "name": "d" + }, + "computed": false + } + ] + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 21, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 27 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 24, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 27 + } + }, + "extra": { + "rawValue": "its a func", + "raw": "'its a func'" + }, + "value": "its a func" + } + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/match/subscripts/actual.js b/test/fixtures/lightscript/match/subscripts/actual.js new file mode 100644 index 0000000000..5257531524 --- /dev/null +++ b/test/fixtures/lightscript/match/subscripts/actual.js @@ -0,0 +1,7 @@ +match x: + | .a, -> 'has a' + | ['b'], -> 'has b' + | ?.c, -> 'has c' + | ?[d], -> 'has d' + | .0, -> 'has first elem' + | ~isFunction(), -> 'its a func' diff --git a/test/fixtures/lightscript/match/subscripts/expected.json b/test/fixtures/lightscript/match/subscripts/expected.json new file mode 100644 index 0000000000..c4fe95bc0d --- /dev/null +++ b/test/fixtures/lightscript/match/subscripts/expected.json @@ -0,0 +1,668 @@ +{ + "type": "File", + "start": 0, + "end": 153, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 34 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 153, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 34 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 153, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 34 + } + }, + "expression": { + "type": "MatchExpression", + "start": 0, + "end": 153, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "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": 27, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "test": { + "type": "MemberExpression", + "start": 13, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "object": { + "type": "PlaceholderExpression", + "start": 12, + "end": 13, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + } + } + }, + "property": { + "type": "Identifier", + "start": 14, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 6 + }, + "identifierName": "a" + }, + "name": "a" + }, + "computed": false + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 17, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 20, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "extra": { + "rawValue": "has a", + "raw": "'has a'" + }, + "value": "has a" + } + } + }, + { + "type": "MatchCase", + "start": 30, + "end": 49, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 21 + } + }, + "test": { + "type": "ArrayExpression", + "start": 32, + "end": 37, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "elements": [ + { + "type": "StringLiteral", + "start": 33, + "end": 36, + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "extra": { + "rawValue": "b", + "raw": "'b'" + }, + "value": "b" + } + ] + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 39, + "end": 49, + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 21 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 42, + "end": 49, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 21 + } + }, + "extra": { + "rawValue": "has b", + "raw": "'has b'" + }, + "value": "has b" + } + } + }, + { + "type": "MatchCase", + "start": 52, + "end": 69, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 19 + } + }, + "test": { + "type": "SafeMemberExpression", + "start": 54, + "end": 57, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 7 + } + }, + "object": { + "type": "PlaceholderExpression", + "start": 53, + "end": 54, + "loc": { + "start": { + "line": 4, + "column": 3 + }, + "end": { + "line": 4, + "column": 4 + } + } + }, + "property": { + "type": "Identifier", + "start": 56, + "end": 57, + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 7 + }, + "identifierName": "c" + }, + "name": "c" + }, + "computed": false + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 59, + "end": 69, + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 4, + "column": 19 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 62, + "end": 69, + "loc": { + "start": { + "line": 4, + "column": 12 + }, + "end": { + "line": 4, + "column": 19 + } + }, + "extra": { + "rawValue": "has c", + "raw": "'has c'" + }, + "value": "has c" + } + } + }, + { + "type": "MatchCase", + "start": 72, + "end": 90, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 20 + } + }, + "test": { + "type": "SafeMemberExpression", + "start": 74, + "end": 78, + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 8 + } + }, + "object": { + "type": "PlaceholderExpression", + "start": 73, + "end": 74, + "loc": { + "start": { + "line": 5, + "column": 3 + }, + "end": { + "line": 5, + "column": 4 + } + } + }, + "property": { + "type": "Identifier", + "start": 76, + "end": 77, + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 5, + "column": 7 + }, + "identifierName": "d" + }, + "name": "d" + }, + "computed": true + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 80, + "end": 90, + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 20 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 83, + "end": 90, + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 20 + } + }, + "extra": { + "rawValue": "has d", + "raw": "'has d'" + }, + "value": "has d" + } + } + }, + { + "type": "MatchCase", + "start": 93, + "end": 118, + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 27 + } + }, + "test": { + "type": "NumericLiteral", + "start": 95, + "end": 97, + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 6 + } + }, + "extra": { + "rawValue": 0, + "raw": ".0" + }, + "value": 0 + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 99, + "end": 118, + "loc": { + "start": { + "line": 6, + "column": 8 + }, + "end": { + "line": 6, + "column": 27 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 102, + "end": 118, + "loc": { + "start": { + "line": 6, + "column": 11 + }, + "end": { + "line": 6, + "column": 27 + } + }, + "extra": { + "rawValue": "has first elem", + "raw": "'has first elem'" + }, + "value": "has first elem" + } + } + }, + { + "type": "MatchCase", + "start": 121, + "end": 153, + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 34 + } + }, + "test": { + "type": "TildeCallExpression", + "start": 123, + "end": 136, + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 17 + } + }, + "left": { + "type": "PlaceholderExpression", + "start": 122, + "end": 123, + "loc": { + "start": { + "line": 7, + "column": 3 + }, + "end": { + "line": 7, + "column": 4 + } + } + }, + "right": { + "type": "Identifier", + "start": 124, + "end": 134, + "loc": { + "start": { + "line": 7, + "column": 5 + }, + "end": { + "line": 7, + "column": 15 + }, + "identifierName": "isFunction" + }, + "name": "isFunction" + }, + "arguments": [] + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 138, + "end": 153, + "loc": { + "start": { + "line": 7, + "column": 19 + }, + "end": { + "line": 7, + "column": 34 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 141, + "end": 153, + "loc": { + "start": { + "line": 7, + "column": 22 + }, + "end": { + "line": 7, + "column": 34 + } + }, + "extra": { + "rawValue": "its a func", + "raw": "'its a func'" + }, + "value": "its a func" + } + } + } + ] + } + } + ], + "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..e6811e4078 --- /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..608f0c9180 --- /dev/null +++ b/test/fixtures/lightscript/match/tag-literal/expected.json @@ -0,0 +1,309 @@ +{ + "type": "File", + "start": 0, + "end": 58, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 58, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 58, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "expression": { + "type": "MatchExpression", + "start": 0, + "end": 58, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "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": 29, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "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": "ArrowFunctionExpression", + "start": 18, + "end": 29, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 21, + "end": 29, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "extra": { + "rawValue": "is \"a\"", + "raw": "'is \"a\"'" + }, + "value": "is \"a\"" + } + } + }, + { + "type": "MatchCase", + "start": 32, + "end": 58, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "test": { + "type": "TemplateLiteral", + "start": 34, + "end": 40, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "expressions": [ + { + "type": "Identifier", + "start": 37, + "end": 38, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 8 + }, + "identifierName": "b" + }, + "name": "b" + } + ], + "quasis": [ + { + "type": "TemplateElement", + "start": 35, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 5 + } + }, + "value": { + "raw": "", + "cooked": "" + }, + "tail": false + }, + { + "type": "TemplateElement", + "start": 39, + "end": 39, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "value": { + "raw": "", + "cooked": "" + }, + "tail": true + } + ] + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 42, + "end": 58, + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "StringLiteral", + "start": 45, + "end": 58, + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "extra": { + "rawValue": "is str of b", + "raw": "'is str of b'" + }, + "value": "is str of b" + } + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file From 045731f1b0d0041a5bd6b83316a5f8cc88cda2f4 Mon Sep 17 00:00:00 2001 From: Alex Rattray Date: Thu, 1 Jun 2017 10:39:47 -0700 Subject: [PATCH 02/12] Use colon syntax instead of comma-arrow --- src/parser/expression.js | 9 +- src/plugins/lightscript.js | 17 +- src/tokenizer/state.js | 4 +- .../lightscript/match/arrow-fns/actual.js | 11 - .../lightscript/match/arrow-fns/expected.json | 1148 ----------------- .../lightscript/match/async/actual.js | 8 - .../lightscript/match/async/expected.json | 641 --------- .../lightscript/match/await/actual.js | 6 + .../lightscript/match/await/expected.json | 434 +++++++ .../match/basic-destructuring/actual.js | 8 + .../match/basic-destructuring/expected.json | 833 ++++++++++++ .../match/binary-both-subscripts/actual.js | 2 +- .../binary-both-subscripts/expected.json | 42 +- .../lightscript/match/binary/actual.js | 14 +- .../lightscript/match/binary/expected.json | 366 +++--- .../bitwise-or-consequent-inline/actual.js | 2 +- .../expected.json | 230 ---- .../bitwise-or-consequent-inline/options.json | 3 + .../actual.js | 2 +- .../bitwise-or-test-explicit/expected.json | 230 ---- .../bitwise-or-test-explicit/options.json | 3 + .../match/curlies-parens/actual.js | 4 +- .../match/curlies-parens/expected.json | 70 +- .../lightscript/match/curlies/actual.js | 4 +- .../lightscript/match/curlies/expected.json | 70 +- .../match/dot-then-binary-illegal/actual.js | 2 +- .../match/else-before-case-illegal/actual.js | 4 +- .../lightscript/match/else-solo/actual.js | 2 +- .../lightscript/match/else-solo/expected.json | 42 +- .../fixtures/lightscript/match/else/actual.js | 4 +- .../lightscript/match/else/expected.json | 76 +- .../lightscript/match/in-assignment/actual.js | 4 +- .../match/in-assignment/expected.json | 80 +- .../lightscript/match/jsx-result/actual.js | 2 +- .../match/jsx-result/expected.json | 58 +- .../match/jsx-test-illegal/actual.js | 2 +- .../lightscript/match/less-than/actual.js | 4 +- .../lightscript/match/less-than/expected.json | 84 +- .../lightscript/match/literals/actual.js | 20 +- .../lightscript/match/literals/expected.json | 356 +++-- .../match/multi-subscripts-illegal/actual.js | 2 +- .../multi-subscripts-number-WRONG/actual.js | 3 - .../multi-subscripts-number-illegal/actual.js | 2 +- .../match/multi-subscripts-number/actual.js | 3 + .../expected.json | 168 ++- .../match/multi-subscripts/actual.js | 4 +- .../match/multi-subscripts/expected.json | 175 +-- .../lightscript/match/nested/actual.js | 10 +- .../lightscript/match/nested/expected.json | 213 ++- .../newline-after-pipe-illegal/actual.js | 2 +- .../match/parens-arent-calls/actual.js | 2 +- .../match/parens-arent-calls/expected.json | 46 +- .../actual.js | 2 +- .../match/parens-no-curlies/actual.js | 4 +- .../match/parens-no-curlies/expected.json | 80 +- .../match/subscript-in-tilde/actual.js | 2 +- .../match/subscript-in-tilde/expected.json | 42 +- .../lightscript/match/subscripts/actual.js | 12 +- .../match/subscripts/expected.json | 281 ++-- .../lightscript/match/tag-literal/actual.js | 4 +- .../match/tag-literal/expected.json | 88 +- .../lightscript/match/yield/actual.js | 6 + .../lightscript/match/yield/expected.json | 437 +++++++ 63 files changed, 2880 insertions(+), 3609 deletions(-) delete mode 100644 test/fixtures/lightscript/match/arrow-fns/actual.js delete mode 100644 test/fixtures/lightscript/match/arrow-fns/expected.json delete mode 100644 test/fixtures/lightscript/match/async/actual.js delete mode 100644 test/fixtures/lightscript/match/async/expected.json create mode 100644 test/fixtures/lightscript/match/await/actual.js create mode 100644 test/fixtures/lightscript/match/await/expected.json create mode 100644 test/fixtures/lightscript/match/basic-destructuring/actual.js create mode 100644 test/fixtures/lightscript/match/basic-destructuring/expected.json delete mode 100644 test/fixtures/lightscript/match/bitwise-or-consequent-inline/expected.json create mode 100644 test/fixtures/lightscript/match/bitwise-or-consequent-inline/options.json delete mode 100644 test/fixtures/lightscript/match/bitwise-or-test-explicit/expected.json create mode 100644 test/fixtures/lightscript/match/bitwise-or-test-explicit/options.json delete mode 100644 test/fixtures/lightscript/match/multi-subscripts-number-WRONG/actual.js create mode 100644 test/fixtures/lightscript/match/multi-subscripts-number/actual.js rename test/fixtures/lightscript/match/{multi-subscripts-number-WRONG => multi-subscripts-number}/expected.json (67%) create mode 100644 test/fixtures/lightscript/match/yield/actual.js create mode 100644 test/fixtures/lightscript/match/yield/expected.json diff --git a/src/parser/expression.js b/src/parser/expression.js index c829da4728..76ca02777c 100644 --- a/src/parser/expression.js +++ b/src/parser/expression.js @@ -239,15 +239,12 @@ 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; } - // if it's a `|` in a match/case on a newline, assume it's for the "case" - // TODO: consider using indentation to be more precise about this - // TODO: just remove all bitwise operators so this isn't necessary. - if (this.match(tt.bitwiseOR) && this.state.inMatchCaseConsequent) { + // for match/case + if (this.match(tt.bitwiseOR)) { return left; } } @@ -752,7 +749,7 @@ pp.parseExprAtom = function (refShorthandDefaultPos) { } case tt.dot: - if (this.hasPlugin("lightscript") && this.lookahead().type === tt.num) { + if (this.hasPlugin("lightscript") && this.lookahead().type === tt.num && !this.allowMatchCasePlaceholder()) { this.unexpected(null, "Decimal numbers must be prefixed with a `0` in LightScript (eg; `0.1`)."); } diff --git a/src/plugins/lightscript.js b/src/plugins/lightscript.js index 2da7887c76..a7752ce85e 100644 --- a/src/plugins/lightscript.js +++ b/src/plugins/lightscript.js @@ -573,7 +573,7 @@ pp.parseMatch = function () { } const matchCase = this.parseMatchCase(); - if (matchCase.test && matchCase.test.type === "MatchElse") { + if (matchCase.test.type === "MatchElse") { hasUsedElse = true; } node.cases.push(matchCase); @@ -586,17 +586,13 @@ pp.parseMatchCase = function () { const node = this.startNode(); node.test = this.parseMatchCaseTest(); - this.expect(tt.comma); - // parse arrow function expression. (TODO: consider allowing NamedArrowExpression) - const oldInMatchCaseConsequent = this.state.inMatchCaseConsequent; - this.state.inMatchCaseConsequent = true; - node.consequent = this.parseMaybeAssign(); - this.state.inMatchCaseConsequent = oldInMatchCaseConsequent; - if (node.consequent.type !== "ArrowFunctionExpression") { - this.unexpected(node.consequent.start, tt.arrow); + if (this.eat(tt._with)) { + node.binding = this.parseBindingAtom(); } + node.consequent = this.parseBlock(false); + return this.finishNode(node, "MatchCase"); }; @@ -634,8 +630,7 @@ pp.isSubscriptTokenForMatchCase = function (tokenType) { tokenType === tt.dot || tokenType === tt.elvis || tokenType === tt.tilde || - tokenType === tt.bracketL || - (tokenType === this.state.type && this.isNumberStartingWithDot()) + tokenType === tt.bracketL ); }; diff --git a/src/tokenizer/state.js b/src/tokenizer/state.js index ee6349f33a..9e19e9f21c 100644 --- a/src/tokenizer/state.js +++ b/src/tokenizer/state.js @@ -40,9 +40,7 @@ export default class State { // for lightscript this.indentLevel = 0; - this.inMatchCaseConsequent = - this.inMatchCaseTest = - false; + this.inMatchCaseTest = false; this.type = tt.eof; this.value = null; diff --git a/test/fixtures/lightscript/match/arrow-fns/actual.js b/test/fixtures/lightscript/match/arrow-fns/actual.js deleted file mode 100644 index 118b044d51..0000000000 --- a/test/fixtures/lightscript/match/arrow-fns/actual.js +++ /dev/null @@ -1,11 +0,0 @@ -match x: - | a, -> 1 - | b, b -> b - | c, (c) -> c - | d, ({ d }) -> d - | e, ({ e = 1 }) -> e - | f, ([ f ]) -> f - | g, ([ g = 1 ]) -> g - | h, => 1 - | i, i => i - | j, (j) => j diff --git a/test/fixtures/lightscript/match/arrow-fns/expected.json b/test/fixtures/lightscript/match/arrow-fns/expected.json deleted file mode 100644 index a3d21d51fe..0000000000 --- a/test/fixtures/lightscript/match/arrow-fns/expected.json +++ /dev/null @@ -1,1148 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 180, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 11, - "column": 15 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 180, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 11, - "column": 15 - } - }, - "sourceType": "script", - "body": [ - { - "type": "ExpressionStatement", - "start": 0, - "end": 180, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 11, - "column": 15 - } - }, - "expression": { - "type": "MatchExpression", - "start": 0, - "end": 180, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 11, - "column": 15 - } - }, - "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": 20, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 11 - } - }, - "test": { - "type": "Identifier", - "start": 13, - "end": 14, - "loc": { - "start": { - "line": 2, - "column": 4 - }, - "end": { - "line": 2, - "column": 5 - }, - "identifierName": "a" - }, - "name": "a" - }, - "consequent": { - "type": "ArrowFunctionExpression", - "start": 16, - "end": 20, - "loc": { - "start": { - "line": 2, - "column": 7 - }, - "end": { - "line": 2, - "column": 11 - } - }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { - "type": "NumericLiteral", - "start": 19, - "end": 20, - "loc": { - "start": { - "line": 2, - "column": 10 - }, - "end": { - "line": 2, - "column": 11 - } - }, - "extra": { - "rawValue": 1, - "raw": "1" - }, - "value": 1 - } - } - }, - { - "type": "MatchCase", - "start": 23, - "end": 34, - "loc": { - "start": { - "line": 3, - "column": 2 - }, - "end": { - "line": 3, - "column": 13 - } - }, - "test": { - "type": "Identifier", - "start": 25, - "end": 26, - "loc": { - "start": { - "line": 3, - "column": 4 - }, - "end": { - "line": 3, - "column": 5 - }, - "identifierName": "b" - }, - "name": "b" - }, - "consequent": { - "type": "ArrowFunctionExpression", - "start": 28, - "end": 34, - "loc": { - "start": { - "line": 3, - "column": 7 - }, - "end": { - "line": 3, - "column": 13 - } - }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [ - { - "type": "Identifier", - "start": 28, - "end": 29, - "loc": { - "start": { - "line": 3, - "column": 7 - }, - "end": { - "line": 3, - "column": 8 - }, - "identifierName": "b" - }, - "name": "b" - } - ], - "skinny": true, - "body": { - "type": "Identifier", - "start": 33, - "end": 34, - "loc": { - "start": { - "line": 3, - "column": 12 - }, - "end": { - "line": 3, - "column": 13 - }, - "identifierName": "b" - }, - "name": "b" - } - } - }, - { - "type": "MatchCase", - "start": 37, - "end": 50, - "loc": { - "start": { - "line": 4, - "column": 2 - }, - "end": { - "line": 4, - "column": 15 - } - }, - "test": { - "type": "Identifier", - "start": 39, - "end": 40, - "loc": { - "start": { - "line": 4, - "column": 4 - }, - "end": { - "line": 4, - "column": 5 - }, - "identifierName": "c" - }, - "name": "c" - }, - "consequent": { - "type": "ArrowFunctionExpression", - "start": 42, - "end": 50, - "loc": { - "start": { - "line": 4, - "column": 7 - }, - "end": { - "line": 4, - "column": 15 - } - }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [ - { - "type": "Identifier", - "start": 43, - "end": 44, - "loc": { - "start": { - "line": 4, - "column": 8 - }, - "end": { - "line": 4, - "column": 9 - }, - "identifierName": "c" - }, - "name": "c" - } - ], - "skinny": true, - "body": { - "type": "Identifier", - "start": 49, - "end": 50, - "loc": { - "start": { - "line": 4, - "column": 14 - }, - "end": { - "line": 4, - "column": 15 - }, - "identifierName": "c" - }, - "name": "c" - } - } - }, - { - "type": "MatchCase", - "start": 53, - "end": 70, - "loc": { - "start": { - "line": 5, - "column": 2 - }, - "end": { - "line": 5, - "column": 19 - } - }, - "test": { - "type": "Identifier", - "start": 55, - "end": 56, - "loc": { - "start": { - "line": 5, - "column": 4 - }, - "end": { - "line": 5, - "column": 5 - }, - "identifierName": "d" - }, - "name": "d" - }, - "consequent": { - "type": "ArrowFunctionExpression", - "start": 58, - "end": 70, - "loc": { - "start": { - "line": 5, - "column": 7 - }, - "end": { - "line": 5, - "column": 19 - } - }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [ - { - "type": "ObjectPattern", - "start": 59, - "end": 64, - "loc": { - "start": { - "line": 5, - "column": 8 - }, - "end": { - "line": 5, - "column": 13 - } - }, - "properties": [ - { - "type": "ObjectProperty", - "start": 61, - "end": 62, - "loc": { - "start": { - "line": 5, - "column": 10 - }, - "end": { - "line": 5, - "column": 11 - } - }, - "method": false, - "shorthand": true, - "computed": false, - "key": { - "type": "Identifier", - "start": 61, - "end": 62, - "loc": { - "start": { - "line": 5, - "column": 10 - }, - "end": { - "line": 5, - "column": 11 - }, - "identifierName": "d" - }, - "name": "d" - }, - "value": { - "type": "Identifier", - "start": 61, - "end": 62, - "loc": { - "start": { - "line": 5, - "column": 10 - }, - "end": { - "line": 5, - "column": 11 - }, - "identifierName": "d" - }, - "name": "d" - }, - "extra": { - "shorthand": true - } - } - ] - } - ], - "skinny": true, - "body": { - "type": "Identifier", - "start": 69, - "end": 70, - "loc": { - "start": { - "line": 5, - "column": 18 - }, - "end": { - "line": 5, - "column": 19 - }, - "identifierName": "d" - }, - "name": "d" - } - } - }, - { - "type": "MatchCase", - "start": 73, - "end": 94, - "loc": { - "start": { - "line": 6, - "column": 2 - }, - "end": { - "line": 6, - "column": 23 - } - }, - "test": { - "type": "Identifier", - "start": 75, - "end": 76, - "loc": { - "start": { - "line": 6, - "column": 4 - }, - "end": { - "line": 6, - "column": 5 - }, - "identifierName": "e" - }, - "name": "e" - }, - "consequent": { - "type": "ArrowFunctionExpression", - "start": 78, - "end": 94, - "loc": { - "start": { - "line": 6, - "column": 7 - }, - "end": { - "line": 6, - "column": 23 - } - }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [ - { - "type": "ObjectPattern", - "start": 79, - "end": 88, - "loc": { - "start": { - "line": 6, - "column": 8 - }, - "end": { - "line": 6, - "column": 17 - } - }, - "properties": [ - { - "type": "ObjectProperty", - "start": 81, - "end": 86, - "loc": { - "start": { - "line": 6, - "column": 10 - }, - "end": { - "line": 6, - "column": 15 - } - }, - "method": false, - "shorthand": true, - "computed": false, - "key": { - "type": "Identifier", - "start": 81, - "end": 82, - "loc": { - "start": { - "line": 6, - "column": 10 - }, - "end": { - "line": 6, - "column": 11 - }, - "identifierName": "e" - }, - "name": "e" - }, - "value": { - "type": "AssignmentPattern", - "start": 81, - "end": 86, - "loc": { - "start": { - "line": 6, - "column": 10 - }, - "end": { - "line": 6, - "column": 15 - } - }, - "left": { - "type": "Identifier", - "start": 81, - "end": 82, - "loc": { - "start": { - "line": 6, - "column": 10 - }, - "end": { - "line": 6, - "column": 11 - }, - "identifierName": "e" - }, - "name": "e" - }, - "right": { - "type": "NumericLiteral", - "start": 85, - "end": 86, - "loc": { - "start": { - "line": 6, - "column": 14 - }, - "end": { - "line": 6, - "column": 15 - } - }, - "extra": { - "rawValue": 1, - "raw": "1" - }, - "value": 1 - } - }, - "extra": { - "shorthand": true - } - } - ] - } - ], - "skinny": true, - "body": { - "type": "Identifier", - "start": 93, - "end": 94, - "loc": { - "start": { - "line": 6, - "column": 22 - }, - "end": { - "line": 6, - "column": 23 - }, - "identifierName": "e" - }, - "name": "e" - } - } - }, - { - "type": "MatchCase", - "start": 97, - "end": 114, - "loc": { - "start": { - "line": 7, - "column": 2 - }, - "end": { - "line": 7, - "column": 19 - } - }, - "test": { - "type": "Identifier", - "start": 99, - "end": 100, - "loc": { - "start": { - "line": 7, - "column": 4 - }, - "end": { - "line": 7, - "column": 5 - }, - "identifierName": "f" - }, - "name": "f" - }, - "consequent": { - "type": "ArrowFunctionExpression", - "start": 102, - "end": 114, - "loc": { - "start": { - "line": 7, - "column": 7 - }, - "end": { - "line": 7, - "column": 19 - } - }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [ - { - "type": "ArrayPattern", - "start": 103, - "end": 108, - "loc": { - "start": { - "line": 7, - "column": 8 - }, - "end": { - "line": 7, - "column": 13 - } - }, - "elements": [ - { - "type": "Identifier", - "start": 105, - "end": 106, - "loc": { - "start": { - "line": 7, - "column": 10 - }, - "end": { - "line": 7, - "column": 11 - }, - "identifierName": "f" - }, - "name": "f" - } - ] - } - ], - "skinny": true, - "body": { - "type": "Identifier", - "start": 113, - "end": 114, - "loc": { - "start": { - "line": 7, - "column": 18 - }, - "end": { - "line": 7, - "column": 19 - }, - "identifierName": "f" - }, - "name": "f" - } - } - }, - { - "type": "MatchCase", - "start": 117, - "end": 138, - "loc": { - "start": { - "line": 8, - "column": 2 - }, - "end": { - "line": 8, - "column": 23 - } - }, - "test": { - "type": "Identifier", - "start": 119, - "end": 120, - "loc": { - "start": { - "line": 8, - "column": 4 - }, - "end": { - "line": 8, - "column": 5 - }, - "identifierName": "g" - }, - "name": "g" - }, - "consequent": { - "type": "ArrowFunctionExpression", - "start": 122, - "end": 138, - "loc": { - "start": { - "line": 8, - "column": 7 - }, - "end": { - "line": 8, - "column": 23 - } - }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [ - { - "type": "ArrayPattern", - "start": 123, - "end": 132, - "loc": { - "start": { - "line": 8, - "column": 8 - }, - "end": { - "line": 8, - "column": 17 - } - }, - "elements": [ - { - "type": "AssignmentPattern", - "start": 125, - "end": 130, - "loc": { - "start": { - "line": 8, - "column": 10 - }, - "end": { - "line": 8, - "column": 15 - } - }, - "left": { - "type": "Identifier", - "start": 125, - "end": 126, - "loc": { - "start": { - "line": 8, - "column": 10 - }, - "end": { - "line": 8, - "column": 11 - }, - "identifierName": "g" - }, - "name": "g" - }, - "right": { - "type": "NumericLiteral", - "start": 129, - "end": 130, - "loc": { - "start": { - "line": 8, - "column": 14 - }, - "end": { - "line": 8, - "column": 15 - } - }, - "extra": { - "rawValue": 1, - "raw": "1" - }, - "value": 1 - }, - "isNowAssign": false - } - ] - } - ], - "skinny": true, - "body": { - "type": "Identifier", - "start": 137, - "end": 138, - "loc": { - "start": { - "line": 8, - "column": 22 - }, - "end": { - "line": 8, - "column": 23 - }, - "identifierName": "g" - }, - "name": "g" - } - } - }, - { - "type": "MatchCase", - "start": 141, - "end": 150, - "loc": { - "start": { - "line": 9, - "column": 2 - }, - "end": { - "line": 9, - "column": 11 - } - }, - "test": { - "type": "Identifier", - "start": 143, - "end": 144, - "loc": { - "start": { - "line": 9, - "column": 4 - }, - "end": { - "line": 9, - "column": 5 - }, - "identifierName": "h" - }, - "name": "h" - }, - "consequent": { - "type": "ArrowFunctionExpression", - "start": 146, - "end": 150, - "loc": { - "start": { - "line": 9, - "column": 7 - }, - "end": { - "line": 9, - "column": 11 - } - }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": false, - "body": { - "type": "NumericLiteral", - "start": 149, - "end": 150, - "loc": { - "start": { - "line": 9, - "column": 10 - }, - "end": { - "line": 9, - "column": 11 - } - }, - "extra": { - "rawValue": 1, - "raw": "1" - }, - "value": 1 - } - } - }, - { - "type": "MatchCase", - "start": 153, - "end": 164, - "loc": { - "start": { - "line": 10, - "column": 2 - }, - "end": { - "line": 10, - "column": 13 - } - }, - "test": { - "type": "Identifier", - "start": 155, - "end": 156, - "loc": { - "start": { - "line": 10, - "column": 4 - }, - "end": { - "line": 10, - "column": 5 - }, - "identifierName": "i" - }, - "name": "i" - }, - "consequent": { - "type": "ArrowFunctionExpression", - "start": 158, - "end": 164, - "loc": { - "start": { - "line": 10, - "column": 7 - }, - "end": { - "line": 10, - "column": 13 - } - }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [ - { - "type": "Identifier", - "start": 158, - "end": 159, - "loc": { - "start": { - "line": 10, - "column": 7 - }, - "end": { - "line": 10, - "column": 8 - }, - "identifierName": "i" - }, - "name": "i" - } - ], - "skinny": false, - "body": { - "type": "Identifier", - "start": 163, - "end": 164, - "loc": { - "start": { - "line": 10, - "column": 12 - }, - "end": { - "line": 10, - "column": 13 - }, - "identifierName": "i" - }, - "name": "i" - } - } - }, - { - "type": "MatchCase", - "start": 167, - "end": 180, - "loc": { - "start": { - "line": 11, - "column": 2 - }, - "end": { - "line": 11, - "column": 15 - } - }, - "test": { - "type": "Identifier", - "start": 169, - "end": 170, - "loc": { - "start": { - "line": 11, - "column": 4 - }, - "end": { - "line": 11, - "column": 5 - }, - "identifierName": "j" - }, - "name": "j" - }, - "consequent": { - "type": "ArrowFunctionExpression", - "start": 172, - "end": 180, - "loc": { - "start": { - "line": 11, - "column": 7 - }, - "end": { - "line": 11, - "column": 15 - } - }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [ - { - "type": "Identifier", - "start": 173, - "end": 174, - "loc": { - "start": { - "line": 11, - "column": 8 - }, - "end": { - "line": 11, - "column": 9 - }, - "identifierName": "j" - }, - "name": "j" - } - ], - "skinny": false, - "body": { - "type": "Identifier", - "start": 179, - "end": 180, - "loc": { - "start": { - "line": 11, - "column": 14 - }, - "end": { - "line": 11, - "column": 15 - }, - "identifierName": "j" - }, - "name": "j" - } - } - } - ] - } - } - ], - "directives": [] - } -} \ No newline at end of file diff --git a/test/fixtures/lightscript/match/async/actual.js b/test/fixtures/lightscript/match/async/actual.js deleted file mode 100644 index 1482f84c8f..0000000000 --- a/test/fixtures/lightscript/match/async/actual.js +++ /dev/null @@ -1,8 +0,0 @@ -f() -/> - <- match x: - | a, -/> 1 - | b, -/> - <- z() - | c, async y => await y - | d, =/> d() - | e, => e() diff --git a/test/fixtures/lightscript/match/async/expected.json b/test/fixtures/lightscript/match/async/expected.json deleted file mode 100644 index a9c9fb063c..0000000000 --- a/test/fixtures/lightscript/match/async/expected.json +++ /dev/null @@ -1,641 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 123, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 8, - "column": 15 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 123, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 8, - "column": 15 - } - }, - "sourceType": "script", - "body": [ - { - "type": "NamedArrowDeclaration", - "start": 0, - "end": 123, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 8, - "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": true, - "params": [], - "skinny": true, - "body": { - "type": "BlockStatement", - "start": 4, - "end": 123, - "loc": { - "start": { - "line": 1, - "column": 4 - }, - "end": { - "line": 8, - "column": 15 - } - }, - "body": [ - { - "type": "ExpressionStatement", - "start": 10, - "end": 123, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 8, - "column": 15 - } - }, - "expression": { - "type": "AwaitExpression", - "start": 10, - "end": 123, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 8, - "column": 15 - } - }, - "argument": { - "type": "MatchExpression", - "start": 13, - "end": 123, - "loc": { - "start": { - "line": 2, - "column": 5 - }, - "end": { - "line": 8, - "column": 15 - } - }, - "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": 36, - "loc": { - "start": { - "line": 3, - "column": 4 - }, - "end": { - "line": 3, - "column": 14 - } - }, - "test": { - "type": "Identifier", - "start": 28, - "end": 29, - "loc": { - "start": { - "line": 3, - "column": 6 - }, - "end": { - "line": 3, - "column": 7 - }, - "identifierName": "a" - }, - "name": "a" - }, - "consequent": { - "type": "ArrowFunctionExpression", - "start": 31, - "end": 36, - "loc": { - "start": { - "line": 3, - "column": 9 - }, - "end": { - "line": 3, - "column": 14 - } - }, - "id": null, - "generator": false, - "expression": true, - "async": true, - "params": [], - "skinny": true, - "body": { - "type": "NumericLiteral", - "start": 35, - "end": 36, - "loc": { - "start": { - "line": 3, - "column": 13 - }, - "end": { - "line": 3, - "column": 14 - } - }, - "extra": { - "rawValue": 1, - "raw": "1" - }, - "value": 1 - } - } - }, - { - "type": "MatchCase", - "start": 41, - "end": 62, - "loc": { - "start": { - "line": 4, - "column": 4 - }, - "end": { - "line": 5, - "column": 12 - } - }, - "test": { - "type": "Identifier", - "start": 43, - "end": 44, - "loc": { - "start": { - "line": 4, - "column": 6 - }, - "end": { - "line": 4, - "column": 7 - }, - "identifierName": "b" - }, - "name": "b" - }, - "consequent": { - "type": "ArrowFunctionExpression", - "start": 46, - "end": 62, - "loc": { - "start": { - "line": 4, - "column": 9 - }, - "end": { - "line": 5, - "column": 12 - } - }, - "id": null, - "generator": false, - "expression": false, - "async": true, - "params": [], - "skinny": true, - "body": { - "type": "BlockStatement", - "start": 46, - "end": 62, - "loc": { - "start": { - "line": 4, - "column": 9 - }, - "end": { - "line": 5, - "column": 12 - } - }, - "body": [ - { - "type": "ExpressionStatement", - "start": 56, - "end": 62, - "loc": { - "start": { - "line": 5, - "column": 6 - }, - "end": { - "line": 5, - "column": 12 - } - }, - "expression": { - "type": "AwaitExpression", - "start": 56, - "end": 62, - "loc": { - "start": { - "line": 5, - "column": 6 - }, - "end": { - "line": 5, - "column": 12 - } - }, - "argument": { - "type": "CallExpression", - "start": 59, - "end": 62, - "loc": { - "start": { - "line": 5, - "column": 9 - }, - "end": { - "line": 5, - "column": 12 - } - }, - "callee": { - "type": "Identifier", - "start": 59, - "end": 60, - "loc": { - "start": { - "line": 5, - "column": 9 - }, - "end": { - "line": 5, - "column": 10 - }, - "identifierName": "z" - }, - "name": "z" - }, - "arguments": [] - } - } - } - ], - "directives": [], - "extra": { - "curly": false - } - } - } - }, - { - "type": "MatchCase", - "start": 67, - "end": 90, - "loc": { - "start": { - "line": 6, - "column": 4 - }, - "end": { - "line": 6, - "column": 27 - } - }, - "test": { - "type": "Identifier", - "start": 69, - "end": 70, - "loc": { - "start": { - "line": 6, - "column": 6 - }, - "end": { - "line": 6, - "column": 7 - }, - "identifierName": "c" - }, - "name": "c" - }, - "consequent": { - "type": "ArrowFunctionExpression", - "start": 72, - "end": 90, - "loc": { - "start": { - "line": 6, - "column": 9 - }, - "end": { - "line": 6, - "column": 27 - } - }, - "id": null, - "generator": false, - "expression": true, - "async": true, - "params": [ - { - "type": "Identifier", - "start": 78, - "end": 79, - "loc": { - "start": { - "line": 6, - "column": 15 - }, - "end": { - "line": 6, - "column": 16 - }, - "identifierName": "y" - }, - "name": "y" - } - ], - "skinny": false, - "body": { - "type": "AwaitExpression", - "start": 83, - "end": 90, - "loc": { - "start": { - "line": 6, - "column": 20 - }, - "end": { - "line": 6, - "column": 27 - } - }, - "argument": { - "type": "Identifier", - "start": 89, - "end": 90, - "loc": { - "start": { - "line": 6, - "column": 26 - }, - "end": { - "line": 6, - "column": 27 - }, - "identifierName": "y" - }, - "name": "y" - } - } - } - }, - { - "type": "MatchCase", - "start": 95, - "end": 107, - "loc": { - "start": { - "line": 7, - "column": 4 - }, - "end": { - "line": 7, - "column": 16 - } - }, - "test": { - "type": "Identifier", - "start": 97, - "end": 98, - "loc": { - "start": { - "line": 7, - "column": 6 - }, - "end": { - "line": 7, - "column": 7 - }, - "identifierName": "d" - }, - "name": "d" - }, - "consequent": { - "type": "ArrowFunctionExpression", - "start": 100, - "end": 107, - "loc": { - "start": { - "line": 7, - "column": 9 - }, - "end": { - "line": 7, - "column": 16 - } - }, - "id": null, - "generator": false, - "expression": true, - "async": true, - "params": [], - "skinny": false, - "body": { - "type": "CallExpression", - "start": 104, - "end": 107, - "loc": { - "start": { - "line": 7, - "column": 13 - }, - "end": { - "line": 7, - "column": 16 - } - }, - "callee": { - "type": "Identifier", - "start": 104, - "end": 105, - "loc": { - "start": { - "line": 7, - "column": 13 - }, - "end": { - "line": 7, - "column": 14 - }, - "identifierName": "d" - }, - "name": "d" - }, - "arguments": [] - } - } - }, - { - "type": "MatchCase", - "start": 112, - "end": 123, - "loc": { - "start": { - "line": 8, - "column": 4 - }, - "end": { - "line": 8, - "column": 15 - } - }, - "test": { - "type": "Identifier", - "start": 114, - "end": 115, - "loc": { - "start": { - "line": 8, - "column": 6 - }, - "end": { - "line": 8, - "column": 7 - }, - "identifierName": "e" - }, - "name": "e" - }, - "consequent": { - "type": "ArrowFunctionExpression", - "start": 117, - "end": 123, - "loc": { - "start": { - "line": 8, - "column": 9 - }, - "end": { - "line": 8, - "column": 15 - } - }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": false, - "body": { - "type": "CallExpression", - "start": 120, - "end": 123, - "loc": { - "start": { - "line": 8, - "column": 12 - }, - "end": { - "line": 8, - "column": 15 - } - }, - "callee": { - "type": "Identifier", - "start": 120, - "end": 121, - "loc": { - "start": { - "line": 8, - "column": 12 - }, - "end": { - "line": 8, - "column": 13 - }, - "identifierName": "e" - }, - "name": "e" - }, - "arguments": [] - } - } - } - ] - } - } - } - ], - "directives": [], - "extra": { - "curly": false - } - } - } - ], - "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/basic-destructuring/actual.js b/test/fixtures/lightscript/match/basic-destructuring/actual.js new file mode 100644 index 0000000000..05ae81c620 --- /dev/null +++ b/test/fixtures/lightscript/match/basic-destructuring/actual.js @@ -0,0 +1,8 @@ +match x: + | a: 1 + | b: b + | c with c: c + | d with { d }: d + | e with { e = 1 }: e + | f with [ f ]: f + | g with [ g = 1 ]: g diff --git a/test/fixtures/lightscript/match/basic-destructuring/expected.json b/test/fixtures/lightscript/match/basic-destructuring/expected.json new file mode 100644 index 0000000000..952605c481 --- /dev/null +++ b/test/fixtures/lightscript/match/basic-destructuring/expected.json @@ -0,0 +1,833 @@ +{ + "type": "File", + "start": 0, + "end": 130, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 8, + "column": 23 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 130, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 8, + "column": 23 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 130, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 8, + "column": 23 + } + }, + "expression": { + "type": "MatchExpression", + "start": 0, + "end": 130, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 8, + "column": 23 + } + }, + "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": "NumericLiteral", + "start": 16, + "end": 17, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + }, + { + "type": "MatchCase", + "start": 20, + "end": 26, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "test": { + "type": "Identifier", + "start": 22, + "end": 23, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 5 + }, + "identifierName": "b" + }, + "name": "b" + }, + "consequent": { + "type": "ExpressionStatement", + "start": 25, + "end": 26, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "expression": { + "type": "Identifier", + "start": 25, + "end": 26, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 8 + }, + "identifierName": "b" + }, + "name": "b" + } + } + }, + { + "type": "MatchCase", + "start": 29, + "end": 42, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 15 + } + }, + "test": { + "type": "Identifier", + "start": 31, + "end": 32, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 5 + }, + "identifierName": "c" + }, + "name": "c" + }, + "binding": { + "type": "Identifier", + "start": 38, + "end": 39, + "loc": { + "start": { + "line": 4, + "column": 11 + }, + "end": { + "line": 4, + "column": 12 + }, + "identifierName": "c" + }, + "name": "c" + }, + "consequent": { + "type": "ExpressionStatement", + "start": 41, + "end": 42, + "loc": { + "start": { + "line": 4, + "column": 14 + }, + "end": { + "line": 4, + "column": 15 + } + }, + "expression": { + "type": "Identifier", + "start": 41, + "end": 42, + "loc": { + "start": { + "line": 4, + "column": 14 + }, + "end": { + "line": 4, + "column": 15 + }, + "identifierName": "c" + }, + "name": "c" + } + } + }, + { + "type": "MatchCase", + "start": 45, + "end": 62, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 19 + } + }, + "test": { + "type": "Identifier", + "start": 47, + "end": 48, + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 5 + }, + "identifierName": "d" + }, + "name": "d" + }, + "binding": { + "type": "ObjectPattern", + "start": 54, + "end": 59, + "loc": { + "start": { + "line": 5, + "column": 11 + }, + "end": { + "line": 5, + "column": 16 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 56, + "end": 57, + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 14 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 56, + "end": 57, + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 14 + }, + "identifierName": "d" + }, + "name": "d" + }, + "value": { + "type": "Identifier", + "start": 56, + "end": 57, + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 14 + }, + "identifierName": "d" + }, + "name": "d" + }, + "extra": { + "shorthand": true + } + } + ] + }, + "consequent": { + "type": "ExpressionStatement", + "start": 61, + "end": 62, + "loc": { + "start": { + "line": 5, + "column": 18 + }, + "end": { + "line": 5, + "column": 19 + } + }, + "expression": { + "type": "Identifier", + "start": 61, + "end": 62, + "loc": { + "start": { + "line": 5, + "column": 18 + }, + "end": { + "line": 5, + "column": 19 + }, + "identifierName": "d" + }, + "name": "d" + } + } + }, + { + "type": "MatchCase", + "start": 65, + "end": 86, + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 23 + } + }, + "test": { + "type": "Identifier", + "start": 67, + "end": 68, + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 5 + }, + "identifierName": "e" + }, + "name": "e" + }, + "binding": { + "type": "ObjectPattern", + "start": 74, + "end": 83, + "loc": { + "start": { + "line": 6, + "column": 11 + }, + "end": { + "line": 6, + "column": 20 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 76, + "end": 81, + "loc": { + "start": { + "line": 6, + "column": 13 + }, + "end": { + "line": 6, + "column": 18 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 76, + "end": 77, + "loc": { + "start": { + "line": 6, + "column": 13 + }, + "end": { + "line": 6, + "column": 14 + }, + "identifierName": "e" + }, + "name": "e" + }, + "value": { + "type": "AssignmentPattern", + "start": 76, + "end": 81, + "loc": { + "start": { + "line": 6, + "column": 13 + }, + "end": { + "line": 6, + "column": 18 + } + }, + "left": { + "type": "Identifier", + "start": 76, + "end": 77, + "loc": { + "start": { + "line": 6, + "column": 13 + }, + "end": { + "line": 6, + "column": 14 + }, + "identifierName": "e" + }, + "name": "e" + }, + "right": { + "type": "NumericLiteral", + "start": 80, + "end": 81, + "loc": { + "start": { + "line": 6, + "column": 17 + }, + "end": { + "line": 6, + "column": 18 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + }, + "extra": { + "shorthand": true + } + } + ] + }, + "consequent": { + "type": "ExpressionStatement", + "start": 85, + "end": 86, + "loc": { + "start": { + "line": 6, + "column": 22 + }, + "end": { + "line": 6, + "column": 23 + } + }, + "expression": { + "type": "Identifier", + "start": 85, + "end": 86, + "loc": { + "start": { + "line": 6, + "column": 22 + }, + "end": { + "line": 6, + "column": 23 + }, + "identifierName": "e" + }, + "name": "e" + } + } + }, + { + "type": "MatchCase", + "start": 89, + "end": 106, + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 19 + } + }, + "test": { + "type": "Identifier", + "start": 91, + "end": 92, + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 5 + }, + "identifierName": "f" + }, + "name": "f" + }, + "binding": { + "type": "ArrayPattern", + "start": 98, + "end": 103, + "loc": { + "start": { + "line": 7, + "column": 11 + }, + "end": { + "line": 7, + "column": 16 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 100, + "end": 101, + "loc": { + "start": { + "line": 7, + "column": 13 + }, + "end": { + "line": 7, + "column": 14 + }, + "identifierName": "f" + }, + "name": "f" + } + ] + }, + "consequent": { + "type": "ExpressionStatement", + "start": 105, + "end": 106, + "loc": { + "start": { + "line": 7, + "column": 18 + }, + "end": { + "line": 7, + "column": 19 + } + }, + "expression": { + "type": "Identifier", + "start": 105, + "end": 106, + "loc": { + "start": { + "line": 7, + "column": 18 + }, + "end": { + "line": 7, + "column": 19 + }, + "identifierName": "f" + }, + "name": "f" + } + } + }, + { + "type": "MatchCase", + "start": 109, + "end": 130, + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 23 + } + }, + "test": { + "type": "Identifier", + "start": 111, + "end": 112, + "loc": { + "start": { + "line": 8, + "column": 4 + }, + "end": { + "line": 8, + "column": 5 + }, + "identifierName": "g" + }, + "name": "g" + }, + "binding": { + "type": "ArrayPattern", + "start": 118, + "end": 127, + "loc": { + "start": { + "line": 8, + "column": 11 + }, + "end": { + "line": 8, + "column": 20 + } + }, + "elements": [ + { + "type": "AssignmentPattern", + "start": 120, + "end": 125, + "loc": { + "start": { + "line": 8, + "column": 13 + }, + "end": { + "line": 8, + "column": 18 + } + }, + "left": { + "type": "Identifier", + "start": 120, + "end": 121, + "loc": { + "start": { + "line": 8, + "column": 13 + }, + "end": { + "line": 8, + "column": 14 + }, + "identifierName": "g" + }, + "name": "g" + }, + "right": { + "type": "NumericLiteral", + "start": 124, + "end": 125, + "loc": { + "start": { + "line": 8, + "column": 17 + }, + "end": { + "line": 8, + "column": 18 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + ] + }, + "consequent": { + "type": "ExpressionStatement", + "start": 129, + "end": 130, + "loc": { + "start": { + "line": 8, + "column": 22 + }, + "end": { + "line": 8, + "column": 23 + } + }, + "expression": { + "type": "Identifier", + "start": 129, + "end": 130, + "loc": { + "start": { + "line": 8, + "column": 22 + }, + "end": { + "line": 8, + "column": 23 + }, + "identifierName": "g" + }, + "name": "g" + } + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/match/binary-both-subscripts/actual.js b/test/fixtures/lightscript/match/binary-both-subscripts/actual.js index 4f4257f56d..5bf62633da 100644 --- a/test/fixtures/lightscript/match/binary-both-subscripts/actual.js +++ b/test/fixtures/lightscript/match/binary-both-subscripts/actual.js @@ -1,2 +1,2 @@ match x: - | .a + .b, -> 'has a and b' + | .a + .b: 'has a and b' diff --git a/test/fixtures/lightscript/match/binary-both-subscripts/expected.json b/test/fixtures/lightscript/match/binary-both-subscripts/expected.json index 429d321f8e..129c0e2054 100644 --- a/test/fixtures/lightscript/match/binary-both-subscripts/expected.json +++ b/test/fixtures/lightscript/match/binary-both-subscripts/expected.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 38, + "end": 35, "loc": { "start": { "line": 1, @@ -9,13 +9,13 @@ }, "end": { "line": 2, - "column": 29 + "column": 26 } }, "program": { "type": "Program", "start": 0, - "end": 38, + "end": 35, "loc": { "start": { "line": 1, @@ -23,7 +23,7 @@ }, "end": { "line": 2, - "column": 29 + "column": 26 } }, "sourceType": "script", @@ -31,7 +31,7 @@ { "type": "ExpressionStatement", "start": 0, - "end": 38, + "end": 35, "loc": { "start": { "line": 1, @@ -39,13 +39,13 @@ }, "end": { "line": 2, - "column": 29 + "column": 26 } }, "expression": { "type": "MatchExpression", "start": 0, - "end": 38, + "end": 35, "loc": { "start": { "line": 1, @@ -53,7 +53,7 @@ }, "end": { "line": 2, - "column": 29 + "column": 26 } }, "discriminant": { @@ -77,7 +77,7 @@ { "type": "MatchCase", "start": 11, - "end": 38, + "end": 35, "loc": { "start": { "line": 2, @@ -85,7 +85,7 @@ }, "end": { "line": 2, - "column": 29 + "column": 26 } }, "test": { @@ -201,9 +201,9 @@ } }, "consequent": { - "type": "ArrowFunctionExpression", + "type": "ExpressionStatement", "start": 22, - "end": 38, + "end": 35, "loc": { "start": { "line": 2, @@ -211,27 +211,21 @@ }, "end": { "line": 2, - "column": 29 + "column": 26 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "StringLiteral", - "start": 25, - "end": 38, + "start": 22, + "end": 35, "loc": { "start": { "line": 2, - "column": 16 + "column": 13 }, "end": { "line": 2, - "column": 29 + "column": 26 } }, "extra": { diff --git a/test/fixtures/lightscript/match/binary/actual.js b/test/fixtures/lightscript/match/binary/actual.js index 102fdb8fe4..fe654095fc 100644 --- a/test/fixtures/lightscript/match/binary/actual.js +++ b/test/fixtures/lightscript/match/binary/actual.js @@ -1,8 +1,8 @@ match x: - | > 2, -> "bigger than two" - | > 3 and > 2, -> "so cool" - | + 3 == 4, -> "its one shhh" - | +1 or -1, -> "equal to one or negative one" - | -1 or +1, -> "equal to one or negative one" - | instanceof Class, -> "its a Class thing!" - | ** 2 == b ** 2 + c ** 2, -> "triangle?" + | > 2: "bigger than two" + | > 3 and > 2: "so cool" + | + 3 == 4: "its one shhh" + | +1 or -1: "equal to one or negative one" + | -1 or +1: "equal to one or negative one" + | instanceof Class: "its a Class thing!" + | ** 2 == b ** 2 + c ** 2: "triangle?" diff --git a/test/fixtures/lightscript/match/binary/expected.json b/test/fixtures/lightscript/match/binary/expected.json index f39ca6e176..071eac56e1 100644 --- a/test/fixtures/lightscript/match/binary/expected.json +++ b/test/fixtures/lightscript/match/binary/expected.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 286, + "end": 265, "loc": { "start": { "line": 1, @@ -9,13 +9,13 @@ }, "end": { "line": 8, - "column": 43 + "column": 40 } }, "program": { "type": "Program", "start": 0, - "end": 286, + "end": 265, "loc": { "start": { "line": 1, @@ -23,7 +23,7 @@ }, "end": { "line": 8, - "column": 43 + "column": 40 } }, "sourceType": "script", @@ -31,7 +31,7 @@ { "type": "ExpressionStatement", "start": 0, - "end": 286, + "end": 265, "loc": { "start": { "line": 1, @@ -39,13 +39,13 @@ }, "end": { "line": 8, - "column": 43 + "column": 40 } }, "expression": { "type": "MatchExpression", "start": 0, - "end": 286, + "end": 265, "loc": { "start": { "line": 1, @@ -53,7 +53,7 @@ }, "end": { "line": 8, - "column": 43 + "column": 40 } }, "discriminant": { @@ -77,7 +77,7 @@ { "type": "MatchCase", "start": 11, - "end": 38, + "end": 35, "loc": { "start": { "line": 2, @@ -85,7 +85,7 @@ }, "end": { "line": 2, - "column": 29 + "column": 26 } }, "test": { @@ -140,9 +140,9 @@ } }, "consequent": { - "type": "ArrowFunctionExpression", + "type": "ExpressionStatement", "start": 18, - "end": 38, + "end": 35, "loc": { "start": { "line": 2, @@ -150,27 +150,21 @@ }, "end": { "line": 2, - "column": 29 + "column": 26 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "StringLiteral", - "start": 21, - "end": 38, + "start": 18, + "end": 35, "loc": { "start": { "line": 2, - "column": 12 + "column": 9 }, "end": { "line": 2, - "column": 29 + "column": 26 } }, "extra": { @@ -183,8 +177,8 @@ }, { "type": "MatchCase", - "start": 41, - "end": 68, + "start": 38, + "end": 62, "loc": { "start": { "line": 3, @@ -192,13 +186,13 @@ }, "end": { "line": 3, - "column": 29 + "column": 26 } }, "test": { "type": "LogicalExpression", - "start": 43, - "end": 54, + "start": 40, + "end": 51, "loc": { "start": { "line": 3, @@ -211,8 +205,8 @@ }, "left": { "type": "BinaryExpression", - "start": 43, - "end": 46, + "start": 40, + "end": 43, "loc": { "start": { "line": 3, @@ -225,8 +219,8 @@ }, "left": { "type": "PlaceholderExpression", - "start": 42, - "end": 43, + "start": 39, + "end": 40, "loc": { "start": { "line": 3, @@ -241,8 +235,8 @@ "operator": ">", "right": { "type": "NumericLiteral", - "start": 45, - "end": 46, + "start": 42, + "end": 43, "loc": { "start": { "line": 3, @@ -263,8 +257,8 @@ "operator": "&&", "right": { "type": "BinaryExpression", - "start": 51, - "end": 54, + "start": 48, + "end": 51, "loc": { "start": { "line": 3, @@ -277,8 +271,8 @@ }, "left": { "type": "PlaceholderExpression", - "start": 50, - "end": 51, + "start": 47, + "end": 48, "loc": { "start": { "line": 3, @@ -293,8 +287,8 @@ "operator": ">", "right": { "type": "NumericLiteral", - "start": 53, - "end": 54, + "start": 50, + "end": 51, "loc": { "start": { "line": 3, @@ -314,9 +308,9 @@ } }, "consequent": { - "type": "ArrowFunctionExpression", - "start": 56, - "end": 68, + "type": "ExpressionStatement", + "start": 53, + "end": 62, "loc": { "start": { "line": 3, @@ -324,27 +318,21 @@ }, "end": { "line": 3, - "column": 29 + "column": 26 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "StringLiteral", - "start": 59, - "end": 68, + "start": 53, + "end": 62, "loc": { "start": { "line": 3, - "column": 20 + "column": 17 }, "end": { "line": 3, - "column": 29 + "column": 26 } }, "extra": { @@ -357,8 +345,8 @@ }, { "type": "MatchCase", - "start": 71, - "end": 100, + "start": 65, + "end": 91, "loc": { "start": { "line": 4, @@ -366,13 +354,13 @@ }, "end": { "line": 4, - "column": 31 + "column": 28 } }, "test": { "type": "BinaryExpression", - "start": 73, - "end": 81, + "start": 67, + "end": 75, "loc": { "start": { "line": 4, @@ -385,8 +373,8 @@ }, "left": { "type": "BinaryExpression", - "start": 73, - "end": 76, + "start": 67, + "end": 70, "loc": { "start": { "line": 4, @@ -399,8 +387,8 @@ }, "left": { "type": "PlaceholderExpression", - "start": 72, - "end": 73, + "start": 66, + "end": 67, "loc": { "start": { "line": 4, @@ -415,8 +403,8 @@ "operator": "+", "right": { "type": "NumericLiteral", - "start": 75, - "end": 76, + "start": 69, + "end": 70, "loc": { "start": { "line": 4, @@ -437,8 +425,8 @@ "operator": "===", "right": { "type": "NumericLiteral", - "start": 80, - "end": 81, + "start": 74, + "end": 75, "loc": { "start": { "line": 4, @@ -457,9 +445,9 @@ } }, "consequent": { - "type": "ArrowFunctionExpression", - "start": 83, - "end": 100, + "type": "ExpressionStatement", + "start": 77, + "end": 91, "loc": { "start": { "line": 4, @@ -467,27 +455,21 @@ }, "end": { "line": 4, - "column": 31 + "column": 28 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "StringLiteral", - "start": 86, - "end": 100, + "start": 77, + "end": 91, "loc": { "start": { "line": 4, - "column": 17 + "column": 14 }, "end": { "line": 4, - "column": 31 + "column": 28 } }, "extra": { @@ -500,8 +482,8 @@ }, { "type": "MatchCase", - "start": 103, - "end": 148, + "start": 94, + "end": 136, "loc": { "start": { "line": 5, @@ -509,13 +491,13 @@ }, "end": { "line": 5, - "column": 47 + "column": 44 } }, "test": { "type": "LogicalExpression", - "start": 105, - "end": 113, + "start": 96, + "end": 104, "loc": { "start": { "line": 5, @@ -528,8 +510,8 @@ }, "left": { "type": "UnaryExpression", - "start": 105, - "end": 107, + "start": 96, + "end": 98, "loc": { "start": { "line": 5, @@ -544,8 +526,8 @@ "prefix": true, "argument": { "type": "NumericLiteral", - "start": 106, - "end": 107, + "start": 97, + "end": 98, "loc": { "start": { "line": 5, @@ -569,8 +551,8 @@ "operator": "||", "right": { "type": "UnaryExpression", - "start": 111, - "end": 113, + "start": 102, + "end": 104, "loc": { "start": { "line": 5, @@ -585,8 +567,8 @@ "prefix": true, "argument": { "type": "NumericLiteral", - "start": 112, - "end": 113, + "start": 103, + "end": 104, "loc": { "start": { "line": 5, @@ -609,9 +591,9 @@ } }, "consequent": { - "type": "ArrowFunctionExpression", - "start": 115, - "end": 148, + "type": "ExpressionStatement", + "start": 106, + "end": 136, "loc": { "start": { "line": 5, @@ -619,27 +601,21 @@ }, "end": { "line": 5, - "column": 47 + "column": 44 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "StringLiteral", - "start": 118, - "end": 148, + "start": 106, + "end": 136, "loc": { "start": { "line": 5, - "column": 17 + "column": 14 }, "end": { "line": 5, - "column": 47 + "column": 44 } }, "extra": { @@ -652,8 +628,8 @@ }, { "type": "MatchCase", - "start": 151, - "end": 196, + "start": 139, + "end": 181, "loc": { "start": { "line": 6, @@ -661,13 +637,13 @@ }, "end": { "line": 6, - "column": 47 + "column": 44 } }, "test": { "type": "LogicalExpression", - "start": 153, - "end": 161, + "start": 141, + "end": 149, "loc": { "start": { "line": 6, @@ -680,8 +656,8 @@ }, "left": { "type": "UnaryExpression", - "start": 153, - "end": 155, + "start": 141, + "end": 143, "loc": { "start": { "line": 6, @@ -696,8 +672,8 @@ "prefix": true, "argument": { "type": "NumericLiteral", - "start": 154, - "end": 155, + "start": 142, + "end": 143, "loc": { "start": { "line": 6, @@ -721,8 +697,8 @@ "operator": "||", "right": { "type": "UnaryExpression", - "start": 159, - "end": 161, + "start": 147, + "end": 149, "loc": { "start": { "line": 6, @@ -737,8 +713,8 @@ "prefix": true, "argument": { "type": "NumericLiteral", - "start": 160, - "end": 161, + "start": 148, + "end": 149, "loc": { "start": { "line": 6, @@ -761,9 +737,9 @@ } }, "consequent": { - "type": "ArrowFunctionExpression", - "start": 163, - "end": 196, + "type": "ExpressionStatement", + "start": 151, + "end": 181, "loc": { "start": { "line": 6, @@ -771,27 +747,21 @@ }, "end": { "line": 6, - "column": 47 + "column": 44 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "StringLiteral", - "start": 166, - "end": 196, + "start": 151, + "end": 181, "loc": { "start": { "line": 6, - "column": 17 + "column": 14 }, "end": { "line": 6, - "column": 47 + "column": 44 } }, "extra": { @@ -804,8 +774,8 @@ }, { "type": "MatchCase", - "start": 199, - "end": 242, + "start": 184, + "end": 224, "loc": { "start": { "line": 7, @@ -813,13 +783,13 @@ }, "end": { "line": 7, - "column": 45 + "column": 42 } }, "test": { "type": "BinaryExpression", - "start": 201, - "end": 217, + "start": 186, + "end": 202, "loc": { "start": { "line": 7, @@ -832,8 +802,8 @@ }, "left": { "type": "PlaceholderExpression", - "start": 200, - "end": 201, + "start": 185, + "end": 186, "loc": { "start": { "line": 7, @@ -848,8 +818,8 @@ "operator": "instanceof", "right": { "type": "Identifier", - "start": 212, - "end": 217, + "start": 197, + "end": 202, "loc": { "start": { "line": 7, @@ -865,9 +835,9 @@ } }, "consequent": { - "type": "ArrowFunctionExpression", - "start": 219, - "end": 242, + "type": "ExpressionStatement", + "start": 204, + "end": 224, "loc": { "start": { "line": 7, @@ -875,27 +845,21 @@ }, "end": { "line": 7, - "column": 45 + "column": 42 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "StringLiteral", - "start": 222, - "end": 242, + "start": 204, + "end": 224, "loc": { "start": { "line": 7, - "column": 25 + "column": 22 }, "end": { "line": 7, - "column": 45 + "column": 42 } }, "extra": { @@ -908,8 +872,8 @@ }, { "type": "MatchCase", - "start": 245, - "end": 286, + "start": 227, + "end": 265, "loc": { "start": { "line": 8, @@ -917,13 +881,13 @@ }, "end": { "line": 8, - "column": 43 + "column": 40 } }, "test": { "type": "BinaryExpression", - "start": 247, - "end": 270, + "start": 229, + "end": 252, "loc": { "start": { "line": 8, @@ -936,8 +900,8 @@ }, "left": { "type": "BinaryExpression", - "start": 247, - "end": 251, + "start": 229, + "end": 233, "loc": { "start": { "line": 8, @@ -950,8 +914,8 @@ }, "left": { "type": "PlaceholderExpression", - "start": 246, - "end": 247, + "start": 228, + "end": 229, "loc": { "start": { "line": 8, @@ -966,8 +930,8 @@ "operator": "**", "right": { "type": "NumericLiteral", - "start": 250, - "end": 251, + "start": 232, + "end": 233, "loc": { "start": { "line": 8, @@ -988,8 +952,8 @@ "operator": "===", "right": { "type": "BinaryExpression", - "start": 255, - "end": 270, + "start": 237, + "end": 252, "loc": { "start": { "line": 8, @@ -1002,8 +966,8 @@ }, "left": { "type": "BinaryExpression", - "start": 255, - "end": 261, + "start": 237, + "end": 243, "loc": { "start": { "line": 8, @@ -1016,8 +980,8 @@ }, "left": { "type": "Identifier", - "start": 255, - "end": 256, + "start": 237, + "end": 238, "loc": { "start": { "line": 8, @@ -1034,8 +998,8 @@ "operator": "**", "right": { "type": "NumericLiteral", - "start": 260, - "end": 261, + "start": 242, + "end": 243, "loc": { "start": { "line": 8, @@ -1056,8 +1020,8 @@ "operator": "+", "right": { "type": "BinaryExpression", - "start": 264, - "end": 270, + "start": 246, + "end": 252, "loc": { "start": { "line": 8, @@ -1070,8 +1034,8 @@ }, "left": { "type": "Identifier", - "start": 264, - "end": 265, + "start": 246, + "end": 247, "loc": { "start": { "line": 8, @@ -1088,8 +1052,8 @@ "operator": "**", "right": { "type": "NumericLiteral", - "start": 269, - "end": 270, + "start": 251, + "end": 252, "loc": { "start": { "line": 8, @@ -1110,9 +1074,9 @@ } }, "consequent": { - "type": "ArrowFunctionExpression", - "start": 272, - "end": 286, + "type": "ExpressionStatement", + "start": 254, + "end": 265, "loc": { "start": { "line": 8, @@ -1120,27 +1084,21 @@ }, "end": { "line": 8, - "column": 43 + "column": 40 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "StringLiteral", - "start": 275, - "end": 286, + "start": 254, + "end": 265, "loc": { "start": { "line": 8, - "column": 32 + "column": 29 }, "end": { "line": 8, - "column": 43 + "column": 40 } }, "extra": { diff --git a/test/fixtures/lightscript/match/bitwise-or-consequent-inline/actual.js b/test/fixtures/lightscript/match/bitwise-or-consequent-inline/actual.js index 56386219b5..409f1d0dbf 100644 --- a/test/fixtures/lightscript/match/bitwise-or-consequent-inline/actual.js +++ b/test/fixtures/lightscript/match/bitwise-or-consequent-inline/actual.js @@ -1,2 +1,2 @@ a = match x: - | 3, -> x | 1 + | 3: x | 1 diff --git a/test/fixtures/lightscript/match/bitwise-or-consequent-inline/expected.json b/test/fixtures/lightscript/match/bitwise-or-consequent-inline/expected.json deleted file mode 100644 index 067347ad4d..0000000000 --- a/test/fixtures/lightscript/match/bitwise-or-consequent-inline/expected.json +++ /dev/null @@ -1,230 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 28, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 2, - "column": 15 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 28, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 2, - "column": 15 - } - }, - "sourceType": "script", - "body": [ - { - "type": "VariableDeclaration", - "start": 0, - "end": 28, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 2, - "column": 15 - } - }, - "kind": "const", - "extra": { - "implicit": true - }, - "declarations": [ - { - "type": "VariableDeclarator", - "start": 0, - "end": 28, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 2, - "column": 15 - } - }, - "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": 28, - "loc": { - "start": { - "line": 1, - "column": 4 - }, - "end": { - "line": 2, - "column": 15 - } - }, - "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": 3, - "raw": "3" - }, - "value": 3 - }, - "consequent": { - "type": "ArrowFunctionExpression", - "start": 20, - "end": 28, - "loc": { - "start": { - "line": 2, - "column": 7 - }, - "end": { - "line": 2, - "column": 15 - } - }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { - "type": "BinaryExpression", - "start": 23, - "end": 28, - "loc": { - "start": { - "line": 2, - "column": 10 - }, - "end": { - "line": 2, - "column": 15 - } - }, - "left": { - "type": "Identifier", - "start": 23, - "end": 24, - "loc": { - "start": { - "line": 2, - "column": 10 - }, - "end": { - "line": 2, - "column": 11 - }, - "identifierName": "x" - }, - "name": "x" - }, - "operator": "|", - "right": { - "type": "NumericLiteral", - "start": 27, - "end": 28, - "loc": { - "start": { - "line": 2, - "column": 14 - }, - "end": { - "line": 2, - "column": 15 - } - }, - "extra": { - "rawValue": 1, - "raw": "1" - }, - "value": 1 - } - } - } - } - ] - } - } - ] - } - ], - "directives": [] - } -} \ No newline at end of file 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 index 212e169860..3574a28285 100644 --- a/test/fixtures/lightscript/match/bitwise-or-consequent-newline-illegal/actual.js +++ b/test/fixtures/lightscript/match/bitwise-or-consequent-newline-illegal/actual.js @@ -1,4 +1,4 @@ a = match x: - | 3, -> + | 3: x | 1 diff --git a/test/fixtures/lightscript/match/bitwise-or-test-explicit/expected.json b/test/fixtures/lightscript/match/bitwise-or-test-explicit/expected.json deleted file mode 100644 index 7dade6cc34..0000000000 --- a/test/fixtures/lightscript/match/bitwise-or-test-explicit/expected.json +++ /dev/null @@ -1,230 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 41, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 2, - "column": 28 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 41, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 2, - "column": 28 - } - }, - "sourceType": "script", - "body": [ - { - "type": "VariableDeclaration", - "start": 0, - "end": 41, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 2, - "column": 28 - } - }, - "kind": "const", - "extra": { - "implicit": true - }, - "declarations": [ - { - "type": "VariableDeclarator", - "start": 0, - "end": 41, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 2, - "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": 41, - "loc": { - "start": { - "line": 1, - "column": 4 - }, - "end": { - "line": 2, - "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": 41, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 28 - } - }, - "test": { - "type": "BinaryExpression", - "start": 17, - "end": 22, - "loc": { - "start": { - "line": 2, - "column": 4 - }, - "end": { - "line": 2, - "column": 9 - } - }, - "left": { - "type": "Identifier", - "start": 17, - "end": 18, - "loc": { - "start": { - "line": 2, - "column": 4 - }, - "end": { - "line": 2, - "column": 5 - }, - "identifierName": "x" - }, - "name": "x" - }, - "operator": "|", - "right": { - "type": "NumericLiteral", - "start": 21, - "end": 22, - "loc": { - "start": { - "line": 2, - "column": 8 - }, - "end": { - "line": 2, - "column": 9 - } - }, - "extra": { - "rawValue": 3, - "raw": "3" - }, - "value": 3 - } - }, - "consequent": { - "type": "ArrowFunctionExpression", - "start": 24, - "end": 41, - "loc": { - "start": { - "line": 2, - "column": 11 - }, - "end": { - "line": 2, - "column": 28 - } - }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { - "type": "StringLiteral", - "start": 27, - "end": 41, - "loc": { - "start": { - "line": 2, - "column": 14 - }, - "end": { - "line": 2, - "column": 28 - } - }, - "extra": { - "rawValue": "bitwise or 3", - "raw": "\"bitwise or 3\"" - }, - "value": "bitwise or 3" - } - } - } - ] - } - } - ] - } - ], - "directives": [] - } -} \ No newline at end of file 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/curlies-parens/actual.js b/test/fixtures/lightscript/match/curlies-parens/actual.js index aa828624dd..b66cfe13e0 100644 --- a/test/fixtures/lightscript/match/curlies-parens/actual.js +++ b/test/fixtures/lightscript/match/curlies-parens/actual.js @@ -1,4 +1,4 @@ a = match (x) { -| > 2, -> "bigger than two" -| else, -> "some other thing" +| > 2: "bigger than 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 index c3f7b8422f..be434e3f41 100644 --- a/test/fixtures/lightscript/match/curlies-parens/expected.json +++ b/test/fixtures/lightscript/match/curlies-parens/expected.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 75, + "end": 69, "loc": { "start": { "line": 1, @@ -15,7 +15,7 @@ "program": { "type": "Program", "start": 0, - "end": 75, + "end": 69, "loc": { "start": { "line": 1, @@ -31,7 +31,7 @@ { "type": "VariableDeclaration", "start": 0, - "end": 75, + "end": 69, "loc": { "start": { "line": 1, @@ -50,7 +50,7 @@ { "type": "VariableDeclarator", "start": 0, - "end": 75, + "end": 69, "loc": { "start": { "line": 1, @@ -81,7 +81,7 @@ "init": { "type": "MatchExpression", "start": 4, - "end": 75, + "end": 69, "loc": { "start": { "line": 1, @@ -114,7 +114,7 @@ { "type": "MatchCase", "start": 16, - "end": 43, + "end": 40, "loc": { "start": { "line": 2, @@ -122,7 +122,7 @@ }, "end": { "line": 2, - "column": 27 + "column": 24 } }, "test": { @@ -177,9 +177,9 @@ } }, "consequent": { - "type": "ArrowFunctionExpression", + "type": "ExpressionStatement", "start": 23, - "end": 43, + "end": 40, "loc": { "start": { "line": 2, @@ -187,27 +187,21 @@ }, "end": { "line": 2, - "column": 27 + "column": 24 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "StringLiteral", - "start": 26, - "end": 43, + "start": 23, + "end": 40, "loc": { "start": { "line": 2, - "column": 10 + "column": 7 }, "end": { "line": 2, - "column": 27 + "column": 24 } }, "extra": { @@ -220,8 +214,8 @@ }, { "type": "MatchCase", - "start": 44, - "end": 73, + "start": 41, + "end": 67, "loc": { "start": { "line": 3, @@ -229,13 +223,13 @@ }, "end": { "line": 3, - "column": 29 + "column": 26 } }, "test": { "type": "MatchElse", - "start": 46, - "end": 50, + "start": 43, + "end": 47, "loc": { "start": { "line": 3, @@ -248,9 +242,9 @@ } }, "consequent": { - "type": "ArrowFunctionExpression", - "start": 52, - "end": 73, + "type": "ExpressionStatement", + "start": 49, + "end": 67, "loc": { "start": { "line": 3, @@ -258,27 +252,21 @@ }, "end": { "line": 3, - "column": 29 + "column": 26 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "StringLiteral", - "start": 55, - "end": 73, + "start": 49, + "end": 67, "loc": { "start": { "line": 3, - "column": 11 + "column": 8 }, "end": { "line": 3, - "column": 29 + "column": 26 } }, "extra": { diff --git a/test/fixtures/lightscript/match/curlies/actual.js b/test/fixtures/lightscript/match/curlies/actual.js index 2e45b3aa67..e0523ad8e2 100644 --- a/test/fixtures/lightscript/match/curlies/actual.js +++ b/test/fixtures/lightscript/match/curlies/actual.js @@ -1,4 +1,4 @@ a = match x { -| > 2, -> "bigger than two" -| else, -> "some other thing" +| > 2: "bigger than two" +| else: "some other thing" } diff --git a/test/fixtures/lightscript/match/curlies/expected.json b/test/fixtures/lightscript/match/curlies/expected.json index b832ce560d..629ff940ec 100644 --- a/test/fixtures/lightscript/match/curlies/expected.json +++ b/test/fixtures/lightscript/match/curlies/expected.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 73, + "end": 67, "loc": { "start": { "line": 1, @@ -15,7 +15,7 @@ "program": { "type": "Program", "start": 0, - "end": 73, + "end": 67, "loc": { "start": { "line": 1, @@ -31,7 +31,7 @@ { "type": "VariableDeclaration", "start": 0, - "end": 73, + "end": 67, "loc": { "start": { "line": 1, @@ -50,7 +50,7 @@ { "type": "VariableDeclarator", "start": 0, - "end": 73, + "end": 67, "loc": { "start": { "line": 1, @@ -81,7 +81,7 @@ "init": { "type": "MatchExpression", "start": 4, - "end": 73, + "end": 67, "loc": { "start": { "line": 1, @@ -113,7 +113,7 @@ { "type": "MatchCase", "start": 14, - "end": 41, + "end": 38, "loc": { "start": { "line": 2, @@ -121,7 +121,7 @@ }, "end": { "line": 2, - "column": 27 + "column": 24 } }, "test": { @@ -176,9 +176,9 @@ } }, "consequent": { - "type": "ArrowFunctionExpression", + "type": "ExpressionStatement", "start": 21, - "end": 41, + "end": 38, "loc": { "start": { "line": 2, @@ -186,27 +186,21 @@ }, "end": { "line": 2, - "column": 27 + "column": 24 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "StringLiteral", - "start": 24, - "end": 41, + "start": 21, + "end": 38, "loc": { "start": { "line": 2, - "column": 10 + "column": 7 }, "end": { "line": 2, - "column": 27 + "column": 24 } }, "extra": { @@ -219,8 +213,8 @@ }, { "type": "MatchCase", - "start": 42, - "end": 71, + "start": 39, + "end": 65, "loc": { "start": { "line": 3, @@ -228,13 +222,13 @@ }, "end": { "line": 3, - "column": 29 + "column": 26 } }, "test": { "type": "MatchElse", - "start": 44, - "end": 48, + "start": 41, + "end": 45, "loc": { "start": { "line": 3, @@ -247,9 +241,9 @@ } }, "consequent": { - "type": "ArrowFunctionExpression", - "start": 50, - "end": 71, + "type": "ExpressionStatement", + "start": 47, + "end": 65, "loc": { "start": { "line": 3, @@ -257,27 +251,21 @@ }, "end": { "line": 3, - "column": 29 + "column": 26 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "StringLiteral", - "start": 53, - "end": 71, + "start": 47, + "end": 65, "loc": { "start": { "line": 3, - "column": 11 + "column": 8 }, "end": { "line": 3, - "column": 29 + "column": 26 } }, "extra": { diff --git a/test/fixtures/lightscript/match/dot-then-binary-illegal/actual.js b/test/fixtures/lightscript/match/dot-then-binary-illegal/actual.js index 45dde14f6e..25ab7a780e 100644 --- a/test/fixtures/lightscript/match/dot-then-binary-illegal/actual.js +++ b/test/fixtures/lightscript/match/dot-then-binary-illegal/actual.js @@ -1,2 +1,2 @@ match x: - | . < 4, -> 'bad' + | . < 4: 'bad' diff --git a/test/fixtures/lightscript/match/else-before-case-illegal/actual.js b/test/fixtures/lightscript/match/else-before-case-illegal/actual.js index 1843706a76..43a2e7dad9 100644 --- a/test/fixtures/lightscript/match/else-before-case-illegal/actual.js +++ b/test/fixtures/lightscript/match/else-before-case-illegal/actual.js @@ -1,3 +1,3 @@ match x: - | else, -> "some other thing" - | a, -> b + | else: "some other thing" + | a: b diff --git a/test/fixtures/lightscript/match/else-solo/actual.js b/test/fixtures/lightscript/match/else-solo/actual.js index 6c5825b8df..600d6e2496 100644 --- a/test/fixtures/lightscript/match/else-solo/actual.js +++ b/test/fixtures/lightscript/match/else-solo/actual.js @@ -1,2 +1,2 @@ match x: - | else, -> "some other thing" + | else: "some other thing" diff --git a/test/fixtures/lightscript/match/else-solo/expected.json b/test/fixtures/lightscript/match/else-solo/expected.json index c8a4cdeb5b..11c3c0b573 100644 --- a/test/fixtures/lightscript/match/else-solo/expected.json +++ b/test/fixtures/lightscript/match/else-solo/expected.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 40, + "end": 37, "loc": { "start": { "line": 1, @@ -9,13 +9,13 @@ }, "end": { "line": 2, - "column": 31 + "column": 28 } }, "program": { "type": "Program", "start": 0, - "end": 40, + "end": 37, "loc": { "start": { "line": 1, @@ -23,7 +23,7 @@ }, "end": { "line": 2, - "column": 31 + "column": 28 } }, "sourceType": "script", @@ -31,7 +31,7 @@ { "type": "ExpressionStatement", "start": 0, - "end": 40, + "end": 37, "loc": { "start": { "line": 1, @@ -39,13 +39,13 @@ }, "end": { "line": 2, - "column": 31 + "column": 28 } }, "expression": { "type": "MatchExpression", "start": 0, - "end": 40, + "end": 37, "loc": { "start": { "line": 1, @@ -53,7 +53,7 @@ }, "end": { "line": 2, - "column": 31 + "column": 28 } }, "discriminant": { @@ -77,7 +77,7 @@ { "type": "MatchCase", "start": 11, - "end": 40, + "end": 37, "loc": { "start": { "line": 2, @@ -85,7 +85,7 @@ }, "end": { "line": 2, - "column": 31 + "column": 28 } }, "test": { @@ -104,9 +104,9 @@ } }, "consequent": { - "type": "ArrowFunctionExpression", + "type": "ExpressionStatement", "start": 19, - "end": 40, + "end": 37, "loc": { "start": { "line": 2, @@ -114,27 +114,21 @@ }, "end": { "line": 2, - "column": 31 + "column": 28 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "StringLiteral", - "start": 22, - "end": 40, + "start": 19, + "end": 37, "loc": { "start": { "line": 2, - "column": 13 + "column": 10 }, "end": { "line": 2, - "column": 31 + "column": 28 } }, "extra": { diff --git a/test/fixtures/lightscript/match/else/actual.js b/test/fixtures/lightscript/match/else/actual.js index 3dc3e7fe46..321d37ebcb 100644 --- a/test/fixtures/lightscript/match/else/actual.js +++ b/test/fixtures/lightscript/match/else/actual.js @@ -1,3 +1,3 @@ match x: - | a, -> b - | else, -> c + | a: b + | else: c diff --git a/test/fixtures/lightscript/match/else/expected.json b/test/fixtures/lightscript/match/else/expected.json index 10c56abcd6..e5ce0fb43b 100644 --- a/test/fixtures/lightscript/match/else/expected.json +++ b/test/fixtures/lightscript/match/else/expected.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 35, + "end": 29, "loc": { "start": { "line": 1, @@ -9,13 +9,13 @@ }, "end": { "line": 3, - "column": 14 + "column": 11 } }, "program": { "type": "Program", "start": 0, - "end": 35, + "end": 29, "loc": { "start": { "line": 1, @@ -23,7 +23,7 @@ }, "end": { "line": 3, - "column": 14 + "column": 11 } }, "sourceType": "script", @@ -31,7 +31,7 @@ { "type": "ExpressionStatement", "start": 0, - "end": 35, + "end": 29, "loc": { "start": { "line": 1, @@ -39,13 +39,13 @@ }, "end": { "line": 3, - "column": 14 + "column": 11 } }, "expression": { "type": "MatchExpression", "start": 0, - "end": 35, + "end": 29, "loc": { "start": { "line": 1, @@ -53,7 +53,7 @@ }, "end": { "line": 3, - "column": 14 + "column": 11 } }, "discriminant": { @@ -77,7 +77,7 @@ { "type": "MatchCase", "start": 11, - "end": 20, + "end": 17, "loc": { "start": { "line": 2, @@ -85,7 +85,7 @@ }, "end": { "line": 2, - "column": 11 + "column": 8 } }, "test": { @@ -106,9 +106,9 @@ "name": "a" }, "consequent": { - "type": "ArrowFunctionExpression", + "type": "ExpressionStatement", "start": 16, - "end": 20, + "end": 17, "loc": { "start": { "line": 2, @@ -116,27 +116,21 @@ }, "end": { "line": 2, - "column": 11 + "column": 8 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "Identifier", - "start": 19, - "end": 20, + "start": 16, + "end": 17, "loc": { "start": { "line": 2, - "column": 10 + "column": 7 }, "end": { "line": 2, - "column": 11 + "column": 8 }, "identifierName": "b" }, @@ -146,8 +140,8 @@ }, { "type": "MatchCase", - "start": 23, - "end": 35, + "start": 20, + "end": 29, "loc": { "start": { "line": 3, @@ -155,13 +149,13 @@ }, "end": { "line": 3, - "column": 14 + "column": 11 } }, "test": { "type": "MatchElse", - "start": 25, - "end": 29, + "start": 22, + "end": 26, "loc": { "start": { "line": 3, @@ -174,9 +168,9 @@ } }, "consequent": { - "type": "ArrowFunctionExpression", - "start": 31, - "end": 35, + "type": "ExpressionStatement", + "start": 28, + "end": 29, "loc": { "start": { "line": 3, @@ -184,27 +178,21 @@ }, "end": { "line": 3, - "column": 14 + "column": 11 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "Identifier", - "start": 34, - "end": 35, + "start": 28, + "end": 29, "loc": { "start": { "line": 3, - "column": 13 + "column": 10 }, "end": { "line": 3, - "column": 14 + "column": 11 }, "identifierName": "c" }, diff --git a/test/fixtures/lightscript/match/in-assignment/actual.js b/test/fixtures/lightscript/match/in-assignment/actual.js index 004a8c60bb..babf04660e 100644 --- a/test/fixtures/lightscript/match/in-assignment/actual.js +++ b/test/fixtures/lightscript/match/in-assignment/actual.js @@ -1,3 +1,3 @@ a = match x: - | > 2, -> "bigger than two" - | else, -> "some other thing" + | > 2: "bigger than 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 index d3354afa5d..d6d93ac148 100644 --- a/test/fixtures/lightscript/match/in-assignment/expected.json +++ b/test/fixtures/lightscript/match/in-assignment/expected.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 74, + "end": 68, "loc": { "start": { "line": 1, @@ -9,13 +9,13 @@ }, "end": { "line": 3, - "column": 31 + "column": 28 } }, "program": { "type": "Program", "start": 0, - "end": 74, + "end": 68, "loc": { "start": { "line": 1, @@ -23,7 +23,7 @@ }, "end": { "line": 3, - "column": 31 + "column": 28 } }, "sourceType": "script", @@ -31,7 +31,7 @@ { "type": "VariableDeclaration", "start": 0, - "end": 74, + "end": 68, "loc": { "start": { "line": 1, @@ -39,7 +39,7 @@ }, "end": { "line": 3, - "column": 31 + "column": 28 } }, "kind": "const", @@ -50,7 +50,7 @@ { "type": "VariableDeclarator", "start": 0, - "end": 74, + "end": 68, "loc": { "start": { "line": 1, @@ -58,7 +58,7 @@ }, "end": { "line": 3, - "column": 31 + "column": 28 } }, "id": { @@ -81,7 +81,7 @@ "init": { "type": "MatchExpression", "start": 4, - "end": 74, + "end": 68, "loc": { "start": { "line": 1, @@ -89,7 +89,7 @@ }, "end": { "line": 3, - "column": 31 + "column": 28 } }, "discriminant": { @@ -113,7 +113,7 @@ { "type": "MatchCase", "start": 15, - "end": 42, + "end": 39, "loc": { "start": { "line": 2, @@ -121,7 +121,7 @@ }, "end": { "line": 2, - "column": 29 + "column": 26 } }, "test": { @@ -176,9 +176,9 @@ } }, "consequent": { - "type": "ArrowFunctionExpression", + "type": "ExpressionStatement", "start": 22, - "end": 42, + "end": 39, "loc": { "start": { "line": 2, @@ -186,27 +186,21 @@ }, "end": { "line": 2, - "column": 29 + "column": 26 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "StringLiteral", - "start": 25, - "end": 42, + "start": 22, + "end": 39, "loc": { "start": { "line": 2, - "column": 12 + "column": 9 }, "end": { "line": 2, - "column": 29 + "column": 26 } }, "extra": { @@ -219,8 +213,8 @@ }, { "type": "MatchCase", - "start": 45, - "end": 74, + "start": 42, + "end": 68, "loc": { "start": { "line": 3, @@ -228,13 +222,13 @@ }, "end": { "line": 3, - "column": 31 + "column": 28 } }, "test": { "type": "MatchElse", - "start": 47, - "end": 51, + "start": 44, + "end": 48, "loc": { "start": { "line": 3, @@ -247,9 +241,9 @@ } }, "consequent": { - "type": "ArrowFunctionExpression", - "start": 53, - "end": 74, + "type": "ExpressionStatement", + "start": 50, + "end": 68, "loc": { "start": { "line": 3, @@ -257,27 +251,21 @@ }, "end": { "line": 3, - "column": 31 + "column": 28 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "StringLiteral", - "start": 56, - "end": 74, + "start": 50, + "end": 68, "loc": { "start": { "line": 3, - "column": 13 + "column": 10 }, "end": { "line": 3, - "column": 31 + "column": 28 } }, "extra": { diff --git a/test/fixtures/lightscript/match/jsx-result/actual.js b/test/fixtures/lightscript/match/jsx-result/actual.js index d02c205ab5..96ff088f19 100644 --- a/test/fixtures/lightscript/match/jsx-result/actual.js +++ b/test/fixtures/lightscript/match/jsx-result/actual.js @@ -1,2 +1,2 @@ match x: - | y, ->
+ | y:
diff --git a/test/fixtures/lightscript/match/jsx-result/expected.json b/test/fixtures/lightscript/match/jsx-result/expected.json index e43e10dd3d..6f9b2b4b82 100644 --- a/test/fixtures/lightscript/match/jsx-result/expected.json +++ b/test/fixtures/lightscript/match/jsx-result/expected.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 26, + "end": 23, "loc": { "start": { "line": 1, @@ -9,13 +9,13 @@ }, "end": { "line": 2, - "column": 17 + "column": 14 } }, "program": { "type": "Program", "start": 0, - "end": 26, + "end": 23, "loc": { "start": { "line": 1, @@ -23,7 +23,7 @@ }, "end": { "line": 2, - "column": 17 + "column": 14 } }, "sourceType": "script", @@ -31,7 +31,7 @@ { "type": "ExpressionStatement", "start": 0, - "end": 26, + "end": 23, "loc": { "start": { "line": 1, @@ -39,13 +39,13 @@ }, "end": { "line": 2, - "column": 17 + "column": 14 } }, "expression": { "type": "MatchExpression", "start": 0, - "end": 26, + "end": 23, "loc": { "start": { "line": 1, @@ -53,7 +53,7 @@ }, "end": { "line": 2, - "column": 17 + "column": 14 } }, "discriminant": { @@ -77,7 +77,7 @@ { "type": "MatchCase", "start": 11, - "end": 26, + "end": 23, "loc": { "start": { "line": 2, @@ -85,7 +85,7 @@ }, "end": { "line": 2, - "column": 17 + "column": 14 } }, "test": { @@ -106,9 +106,9 @@ "name": "y" }, "consequent": { - "type": "ArrowFunctionExpression", + "type": "ExpressionStatement", "start": 16, - "end": 26, + "end": 23, "loc": { "start": { "line": 2, @@ -116,56 +116,50 @@ }, "end": { "line": 2, - "column": 17 + "column": 14 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "JSXElement", - "start": 19, - "end": 26, + "start": 16, + "end": 23, "loc": { "start": { "line": 2, - "column": 10 + "column": 7 }, "end": { "line": 2, - "column": 17 + "column": 14 } }, "openingElement": { "type": "JSXOpeningElement", - "start": 19, - "end": 26, + "start": 16, + "end": 23, "loc": { "start": { "line": 2, - "column": 10 + "column": 7 }, "end": { "line": 2, - "column": 17 + "column": 14 } }, "attributes": [], "name": { "type": "JSXIdentifier", - "start": 20, - "end": 23, + "start": 17, + "end": 20, "loc": { "start": { "line": 2, - "column": 11 + "column": 8 }, "end": { "line": 2, - "column": 14 + "column": 11 } }, "name": "div" diff --git a/test/fixtures/lightscript/match/jsx-test-illegal/actual.js b/test/fixtures/lightscript/match/jsx-test-illegal/actual.js index 565ab8a3a4..e7b9d76c6a 100644 --- a/test/fixtures/lightscript/match/jsx-test-illegal/actual.js +++ b/test/fixtures/lightscript/match/jsx-test-illegal/actual.js @@ -1,2 +1,2 @@ match x: - |
, -> "does this make sense?" + |
: "does this make sense?" diff --git a/test/fixtures/lightscript/match/less-than/actual.js b/test/fixtures/lightscript/match/less-than/actual.js index 54ba1ab1e3..1d87d891d3 100644 --- a/test/fixtures/lightscript/match/less-than/actual.js +++ b/test/fixtures/lightscript/match/less-than/actual.js @@ -1,3 +1,3 @@ match x: - | < 3, -> "not jsx" - | <3, -> "not jsx" + | < 3: "not jsx" + | <3: "not jsx" diff --git a/test/fixtures/lightscript/match/less-than/expected.json b/test/fixtures/lightscript/match/less-than/expected.json index 8059b81eab..53de30b7cd 100644 --- a/test/fixtures/lightscript/match/less-than/expected.json +++ b/test/fixtures/lightscript/match/less-than/expected.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 51, + "end": 45, "loc": { "start": { "line": 1, @@ -9,13 +9,13 @@ }, "end": { "line": 3, - "column": 20 + "column": 17 } }, "program": { "type": "Program", "start": 0, - "end": 51, + "end": 45, "loc": { "start": { "line": 1, @@ -23,7 +23,7 @@ }, "end": { "line": 3, - "column": 20 + "column": 17 } }, "sourceType": "script", @@ -31,7 +31,7 @@ { "type": "ExpressionStatement", "start": 0, - "end": 51, + "end": 45, "loc": { "start": { "line": 1, @@ -39,13 +39,13 @@ }, "end": { "line": 3, - "column": 20 + "column": 17 } }, "expression": { "type": "MatchExpression", "start": 0, - "end": 51, + "end": 45, "loc": { "start": { "line": 1, @@ -53,7 +53,7 @@ }, "end": { "line": 3, - "column": 20 + "column": 17 } }, "discriminant": { @@ -77,7 +77,7 @@ { "type": "MatchCase", "start": 11, - "end": 30, + "end": 27, "loc": { "start": { "line": 2, @@ -85,7 +85,7 @@ }, "end": { "line": 2, - "column": 21 + "column": 18 } }, "test": { @@ -140,9 +140,9 @@ } }, "consequent": { - "type": "ArrowFunctionExpression", + "type": "ExpressionStatement", "start": 18, - "end": 30, + "end": 27, "loc": { "start": { "line": 2, @@ -150,27 +150,21 @@ }, "end": { "line": 2, - "column": 21 + "column": 18 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "StringLiteral", - "start": 21, - "end": 30, + "start": 18, + "end": 27, "loc": { "start": { "line": 2, - "column": 12 + "column": 9 }, "end": { "line": 2, - "column": 21 + "column": 18 } }, "extra": { @@ -183,8 +177,8 @@ }, { "type": "MatchCase", - "start": 33, - "end": 51, + "start": 30, + "end": 45, "loc": { "start": { "line": 3, @@ -192,13 +186,13 @@ }, "end": { "line": 3, - "column": 20 + "column": 17 } }, "test": { "type": "BinaryExpression", - "start": 35, - "end": 37, + "start": 32, + "end": 34, "loc": { "start": { "line": 3, @@ -211,8 +205,8 @@ }, "left": { "type": "PlaceholderExpression", - "start": 34, - "end": 35, + "start": 31, + "end": 32, "loc": { "start": { "line": 3, @@ -227,8 +221,8 @@ "operator": "<", "right": { "type": "NumericLiteral", - "start": 36, - "end": 37, + "start": 33, + "end": 34, "loc": { "start": { "line": 3, @@ -247,9 +241,9 @@ } }, "consequent": { - "type": "ArrowFunctionExpression", - "start": 39, - "end": 51, + "type": "ExpressionStatement", + "start": 36, + "end": 45, "loc": { "start": { "line": 3, @@ -257,27 +251,21 @@ }, "end": { "line": 3, - "column": 20 + "column": 17 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "StringLiteral", - "start": 42, - "end": 51, + "start": 36, + "end": 45, "loc": { "start": { "line": 3, - "column": 11 + "column": 8 }, "end": { "line": 3, - "column": 20 + "column": 17 } }, "extra": { diff --git a/test/fixtures/lightscript/match/literals/actual.js b/test/fixtures/lightscript/match/literals/actual.js index a708fe5882..dd7f054602 100644 --- a/test/fixtures/lightscript/match/literals/actual.js +++ b/test/fixtures/lightscript/match/literals/actual.js @@ -1,11 +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" + | 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 index 3e15f8f989..bb182cea8e 100644 --- a/test/fixtures/lightscript/match/literals/expected.json +++ b/test/fixtures/lightscript/match/literals/expected.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 265, + "end": 235, "loc": { "start": { "line": 1, @@ -9,13 +9,13 @@ }, "end": { "line": 11, - "column": 28 + "column": 25 } }, "program": { "type": "Program", "start": 0, - "end": 265, + "end": 235, "loc": { "start": { "line": 1, @@ -23,7 +23,7 @@ }, "end": { "line": 11, - "column": 28 + "column": 25 } }, "sourceType": "script", @@ -31,7 +31,7 @@ { "type": "ExpressionStatement", "start": 0, - "end": 265, + "end": 235, "loc": { "start": { "line": 1, @@ -39,13 +39,13 @@ }, "end": { "line": 11, - "column": 28 + "column": 25 } }, "expression": { "type": "MatchExpression", "start": 0, - "end": 265, + "end": 235, "loc": { "start": { "line": 1, @@ -53,7 +53,7 @@ }, "end": { "line": 11, - "column": 28 + "column": 25 } }, "discriminant": { @@ -77,7 +77,7 @@ { "type": "MatchCase", "start": 11, - "end": 24, + "end": 21, "loc": { "start": { "line": 2, @@ -85,7 +85,7 @@ }, "end": { "line": 2, - "column": 15 + "column": 12 } }, "test": { @@ -109,9 +109,9 @@ "value": 2 }, "consequent": { - "type": "ArrowFunctionExpression", + "type": "ExpressionStatement", "start": 16, - "end": 24, + "end": 21, "loc": { "start": { "line": 2, @@ -119,27 +119,21 @@ }, "end": { "line": 2, - "column": 15 + "column": 12 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "StringLiteral", - "start": 19, - "end": 24, + "start": 16, + "end": 21, "loc": { "start": { "line": 2, - "column": 10 + "column": 7 }, "end": { "line": 2, - "column": 15 + "column": 12 } }, "extra": { @@ -152,8 +146,8 @@ }, { "type": "MatchCase", - "start": 27, - "end": 45, + "start": 24, + "end": 39, "loc": { "start": { "line": 3, @@ -161,13 +155,13 @@ }, "end": { "line": 3, - "column": 20 + "column": 17 } }, "test": { "type": "StringLiteral", - "start": 29, - "end": 36, + "start": 26, + "end": 33, "loc": { "start": { "line": 3, @@ -185,9 +179,9 @@ "value": "hello" }, "consequent": { - "type": "ArrowFunctionExpression", - "start": 38, - "end": 45, + "type": "ExpressionStatement", + "start": 35, + "end": 39, "loc": { "start": { "line": 3, @@ -195,27 +189,21 @@ }, "end": { "line": 3, - "column": 20 + "column": 17 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "StringLiteral", - "start": 41, - "end": 45, + "start": 35, + "end": 39, "loc": { "start": { "line": 3, - "column": 16 + "column": 13 }, "end": { "line": 3, - "column": 20 + "column": 17 } }, "extra": { @@ -228,8 +216,8 @@ }, { "type": "MatchCase", - "start": 48, - "end": 66, + "start": 42, + "end": 57, "loc": { "start": { "line": 4, @@ -237,13 +225,13 @@ }, "end": { "line": 4, - "column": 20 + "column": 17 } }, "test": { "type": "RegExpLiteral", - "start": 50, - "end": 55, + "start": 44, + "end": 49, "loc": { "start": { "line": 4, @@ -261,9 +249,9 @@ "flags": "" }, "consequent": { - "type": "ArrowFunctionExpression", - "start": 57, - "end": 66, + "type": "ExpressionStatement", + "start": 51, + "end": 57, "loc": { "start": { "line": 4, @@ -271,27 +259,21 @@ }, "end": { "line": 4, - "column": 20 + "column": 17 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "StringLiteral", - "start": 60, - "end": 66, + "start": 51, + "end": 57, "loc": { "start": { "line": 4, - "column": 14 + "column": 11 }, "end": { "line": 4, - "column": 20 + "column": 17 } }, "extra": { @@ -304,8 +286,8 @@ }, { "type": "MatchCase", - "start": 69, - "end": 89, + "start": 60, + "end": 77, "loc": { "start": { "line": 5, @@ -313,13 +295,13 @@ }, "end": { "line": 5, - "column": 22 + "column": 19 } }, "test": { "type": "RegExpLiteral", - "start": 71, - "end": 78, + "start": 62, + "end": 69, "loc": { "start": { "line": 5, @@ -337,9 +319,9 @@ "flags": "ig" }, "consequent": { - "type": "ArrowFunctionExpression", - "start": 80, - "end": 89, + "type": "ExpressionStatement", + "start": 71, + "end": 77, "loc": { "start": { "line": 5, @@ -347,27 +329,21 @@ }, "end": { "line": 5, - "column": 22 + "column": 19 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "StringLiteral", - "start": 83, - "end": 89, + "start": 71, + "end": 77, "loc": { "start": { "line": 5, - "column": 16 + "column": 13 }, "end": { "line": 5, - "column": 22 + "column": 19 } }, "extra": { @@ -380,8 +356,8 @@ }, { "type": "MatchCase", - "start": 92, - "end": 124, + "start": 80, + "end": 109, "loc": { "start": { "line": 6, @@ -389,13 +365,13 @@ }, "end": { "line": 6, - "column": 34 + "column": 31 } }, "test": { "type": "UnaryExpression", - "start": 94, - "end": 96, + "start": 82, + "end": 84, "loc": { "start": { "line": 6, @@ -410,8 +386,8 @@ "prefix": true, "argument": { "type": "NumericLiteral", - "start": 95, - "end": 96, + "start": 83, + "end": 84, "loc": { "start": { "line": 6, @@ -433,9 +409,9 @@ } }, "consequent": { - "type": "ArrowFunctionExpression", - "start": 98, - "end": 124, + "type": "ExpressionStatement", + "start": 86, + "end": 109, "loc": { "start": { "line": 6, @@ -443,27 +419,21 @@ }, "end": { "line": 6, - "column": 34 + "column": 31 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "StringLiteral", - "start": 101, - "end": 124, + "start": 86, + "end": 109, "loc": { "start": { "line": 6, - "column": 11 + "column": 8 }, "end": { "line": 6, - "column": 34 + "column": 31 } }, "extra": { @@ -476,8 +446,8 @@ }, { "type": "MatchCase", - "start": 127, - "end": 159, + "start": 112, + "end": 141, "loc": { "start": { "line": 7, @@ -485,13 +455,13 @@ }, "end": { "line": 7, - "column": 34 + "column": 31 } }, "test": { "type": "UnaryExpression", - "start": 129, - "end": 131, + "start": 114, + "end": 116, "loc": { "start": { "line": 7, @@ -506,8 +476,8 @@ "prefix": true, "argument": { "type": "NumericLiteral", - "start": 130, - "end": 131, + "start": 115, + "end": 116, "loc": { "start": { "line": 7, @@ -529,9 +499,9 @@ } }, "consequent": { - "type": "ArrowFunctionExpression", - "start": 133, - "end": 159, + "type": "ExpressionStatement", + "start": 118, + "end": 141, "loc": { "start": { "line": 7, @@ -539,27 +509,21 @@ }, "end": { "line": 7, - "column": 34 + "column": 31 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "StringLiteral", - "start": 136, - "end": 159, + "start": 118, + "end": 141, "loc": { "start": { "line": 7, - "column": 11 + "column": 8 }, "end": { "line": 7, - "column": 34 + "column": 31 } }, "extra": { @@ -572,8 +536,8 @@ }, { "type": "MatchCase", - "start": 162, - "end": 179, + "start": 144, + "end": 158, "loc": { "start": { "line": 8, @@ -581,13 +545,13 @@ }, "end": { "line": 8, - "column": 19 + "column": 16 } }, "test": { "type": "NullLiteral", - "start": 164, - "end": 168, + "start": 146, + "end": 150, "loc": { "start": { "line": 8, @@ -600,9 +564,9 @@ } }, "consequent": { - "type": "ArrowFunctionExpression", - "start": 170, - "end": 179, + "type": "ExpressionStatement", + "start": 152, + "end": 158, "loc": { "start": { "line": 8, @@ -610,27 +574,21 @@ }, "end": { "line": 8, - "column": 19 + "column": 16 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "StringLiteral", - "start": 173, - "end": 179, + "start": 152, + "end": 158, "loc": { "start": { "line": 8, - "column": 13 + "column": 10 }, "end": { "line": 8, - "column": 19 + "column": 16 } }, "extra": { @@ -643,8 +601,8 @@ }, { "type": "MatchCase", - "start": 182, - "end": 209, + "start": 161, + "end": 185, "loc": { "start": { "line": 9, @@ -652,13 +610,13 @@ }, "end": { "line": 9, - "column": 29 + "column": 26 } }, "test": { "type": "Identifier", - "start": 184, - "end": 193, + "start": 163, + "end": 172, "loc": { "start": { "line": 9, @@ -673,9 +631,9 @@ "name": "undefined" }, "consequent": { - "type": "ArrowFunctionExpression", - "start": 195, - "end": 209, + "type": "ExpressionStatement", + "start": 174, + "end": 185, "loc": { "start": { "line": 9, @@ -683,27 +641,21 @@ }, "end": { "line": 9, - "column": 29 + "column": 26 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "StringLiteral", - "start": 198, - "end": 209, + "start": 174, + "end": 185, "loc": { "start": { "line": 9, - "column": 18 + "column": 15 }, "end": { "line": 9, - "column": 29 + "column": 26 } }, "extra": { @@ -716,8 +668,8 @@ }, { "type": "MatchCase", - "start": 212, - "end": 236, + "start": 188, + "end": 209, "loc": { "start": { "line": 10, @@ -725,13 +677,13 @@ }, "end": { "line": 10, - "column": 26 + "column": 23 } }, "test": { "type": "BooleanLiteral", - "start": 214, - "end": 218, + "start": 190, + "end": 194, "loc": { "start": { "line": 10, @@ -745,9 +697,9 @@ "value": true }, "consequent": { - "type": "ArrowFunctionExpression", - "start": 220, - "end": 236, + "type": "ExpressionStatement", + "start": 196, + "end": 209, "loc": { "start": { "line": 10, @@ -755,27 +707,21 @@ }, "end": { "line": 10, - "column": 26 + "column": 23 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "StringLiteral", - "start": 223, - "end": 236, + "start": 196, + "end": 209, "loc": { "start": { "line": 10, - "column": 13 + "column": 10 }, "end": { "line": 10, - "column": 26 + "column": 23 } }, "extra": { @@ -788,8 +734,8 @@ }, { "type": "MatchCase", - "start": 239, - "end": 265, + "start": 212, + "end": 235, "loc": { "start": { "line": 11, @@ -797,13 +743,13 @@ }, "end": { "line": 11, - "column": 28 + "column": 25 } }, "test": { "type": "BooleanLiteral", - "start": 241, - "end": 246, + "start": 214, + "end": 219, "loc": { "start": { "line": 11, @@ -817,9 +763,9 @@ "value": false }, "consequent": { - "type": "ArrowFunctionExpression", - "start": 248, - "end": 265, + "type": "ExpressionStatement", + "start": 221, + "end": 235, "loc": { "start": { "line": 11, @@ -827,27 +773,21 @@ }, "end": { "line": 11, - "column": 28 + "column": 25 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "StringLiteral", - "start": 251, - "end": 265, + "start": 221, + "end": 235, "loc": { "start": { "line": 11, - "column": 14 + "column": 11 }, "end": { "line": 11, - "column": 28 + "column": 25 } }, "extra": { diff --git a/test/fixtures/lightscript/match/multi-subscripts-illegal/actual.js b/test/fixtures/lightscript/match/multi-subscripts-illegal/actual.js index 33f98acb0b..b30b867cf7 100644 --- a/test/fixtures/lightscript/match/multi-subscripts-illegal/actual.js +++ b/test/fixtures/lightscript/match/multi-subscripts-illegal/actual.js @@ -1,2 +1,2 @@ match x: - | ..d, -> 'its a func' + | ..d: 'nope' diff --git a/test/fixtures/lightscript/match/multi-subscripts-number-WRONG/actual.js b/test/fixtures/lightscript/match/multi-subscripts-number-WRONG/actual.js deleted file mode 100644 index 09029d4ecc..0000000000 --- a/test/fixtures/lightscript/match/multi-subscripts-number-WRONG/actual.js +++ /dev/null @@ -1,3 +0,0 @@ -match x: - | .a and .0, -> 'has a and first child' - | .0.0, -> 'first child of first child' diff --git a/test/fixtures/lightscript/match/multi-subscripts-number-illegal/actual.js b/test/fixtures/lightscript/match/multi-subscripts-number-illegal/actual.js index 1aa2f6bd46..43170a3961 100644 --- a/test/fixtures/lightscript/match/multi-subscripts-number-illegal/actual.js +++ b/test/fixtures/lightscript/match/multi-subscripts-number-illegal/actual.js @@ -1,2 +1,2 @@ match x: - | ..0, -> 'bad' + | ..0: 'bad' diff --git a/test/fixtures/lightscript/match/multi-subscripts-number/actual.js b/test/fixtures/lightscript/match/multi-subscripts-number/actual.js new file mode 100644 index 0000000000..1c0f753907 --- /dev/null +++ b/test/fixtures/lightscript/match/multi-subscripts-number/actual.js @@ -0,0 +1,3 @@ +match x: + | .a and .0: 'has a and first child' + | .0.0: 'first child of first child' diff --git a/test/fixtures/lightscript/match/multi-subscripts-number-WRONG/expected.json b/test/fixtures/lightscript/match/multi-subscripts-number/expected.json similarity index 67% rename from test/fixtures/lightscript/match/multi-subscripts-number-WRONG/expected.json rename to test/fixtures/lightscript/match/multi-subscripts-number/expected.json index 243eac0b1f..7496f03c92 100644 --- a/test/fixtures/lightscript/match/multi-subscripts-number-WRONG/expected.json +++ b/test/fixtures/lightscript/match/multi-subscripts-number/expected.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 92, + "end": 86, "loc": { "start": { "line": 1, @@ -9,13 +9,13 @@ }, "end": { "line": 3, - "column": 41 + "column": 38 } }, "program": { "type": "Program", "start": 0, - "end": 92, + "end": 86, "loc": { "start": { "line": 1, @@ -23,7 +23,7 @@ }, "end": { "line": 3, - "column": 41 + "column": 38 } }, "sourceType": "script", @@ -31,7 +31,7 @@ { "type": "ExpressionStatement", "start": 0, - "end": 92, + "end": 86, "loc": { "start": { "line": 1, @@ -39,13 +39,13 @@ }, "end": { "line": 3, - "column": 41 + "column": 38 } }, "expression": { "type": "MatchExpression", "start": 0, - "end": 92, + "end": 86, "loc": { "start": { "line": 1, @@ -53,7 +53,7 @@ }, "end": { "line": 3, - "column": 41 + "column": 38 } }, "discriminant": { @@ -77,7 +77,7 @@ { "type": "MatchCase", "start": 11, - "end": 50, + "end": 47, "loc": { "start": { "line": 2, @@ -85,7 +85,7 @@ }, "end": { "line": 2, - "column": 41 + "column": 38 } }, "test": { @@ -152,7 +152,7 @@ }, "operator": "&&", "right": { - "type": "NumericLiteral", + "type": "MemberExpression", "start": 20, "end": 22, "loc": { @@ -165,17 +165,48 @@ "column": 13 } }, - "extra": { - "rawValue": 0, - "raw": ".0" + "object": { + "type": "PlaceholderExpression", + "start": 19, + "end": 20, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + } + } }, - "value": 0 + "property": { + "type": "NumericLiteral", + "start": 21, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + }, + "computed": true } }, "consequent": { - "type": "ArrowFunctionExpression", + "type": "ExpressionStatement", "start": 24, - "end": 50, + "end": 47, "loc": { "start": { "line": 2, @@ -183,27 +214,21 @@ }, "end": { "line": 2, - "column": 41 + "column": 38 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "StringLiteral", - "start": 27, - "end": 50, + "start": 24, + "end": 47, "loc": { "start": { "line": 2, - "column": 18 + "column": 15 }, "end": { "line": 2, - "column": 41 + "column": 38 } }, "extra": { @@ -216,8 +241,8 @@ }, { "type": "MatchCase", - "start": 53, - "end": 92, + "start": 50, + "end": 86, "loc": { "start": { "line": 3, @@ -225,13 +250,13 @@ }, "end": { "line": 3, - "column": 41 + "column": 38 } }, "test": { "type": "MemberExpression", - "start": 55, - "end": 59, + "start": 52, + "end": 56, "loc": { "start": { "line": 3, @@ -243,9 +268,9 @@ } }, "object": { - "type": "NumericLiteral", - "start": 55, - "end": 57, + "type": "MemberExpression", + "start": 52, + "end": 54, "loc": { "start": { "line": 3, @@ -256,20 +281,51 @@ "column": 6 } }, - "extra": { - "rawValue": 0, - "raw": ".0" + "object": { + "type": "PlaceholderExpression", + "start": 51, + "end": 52, + "loc": { + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 4 + } + } }, - "value": 0 + "property": { + "type": "NumericLiteral", + "start": 53, + "end": 54, + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 6 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + }, + "computed": true }, "property": { "type": "NumericLiteral", - "start": 57, - "end": 59, + "start": 55, + "end": 56, "loc": { "start": { "line": 3, - "column": 6 + "column": 7 }, "end": { "line": 3, @@ -285,9 +341,9 @@ "computed": true }, "consequent": { - "type": "ArrowFunctionExpression", - "start": 61, - "end": 92, + "type": "ExpressionStatement", + "start": 58, + "end": 86, "loc": { "start": { "line": 3, @@ -295,27 +351,21 @@ }, "end": { "line": 3, - "column": 41 + "column": 38 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "StringLiteral", - "start": 64, - "end": 92, + "start": 58, + "end": 86, "loc": { "start": { "line": 3, - "column": 13 + "column": 10 }, "end": { "line": 3, - "column": 41 + "column": 38 } }, "extra": { diff --git a/test/fixtures/lightscript/match/multi-subscripts/actual.js b/test/fixtures/lightscript/match/multi-subscripts/actual.js index a538d7d946..77489eb1e0 100644 --- a/test/fixtures/lightscript/match/multi-subscripts/actual.js +++ b/test/fixtures/lightscript/match/multi-subscripts/actual.js @@ -1,3 +1,3 @@ match x: - | .a and .b, -> 'has a and b' - | ~c() or ~d(), -> 'its a func' + | .a and .b.c: 'has a and b.c' + | ~c() or ~d(): 'its a func' diff --git a/test/fixtures/lightscript/match/multi-subscripts/expected.json b/test/fixtures/lightscript/match/multi-subscripts/expected.json index c26c00b3fe..518d4f15e6 100644 --- a/test/fixtures/lightscript/match/multi-subscripts/expected.json +++ b/test/fixtures/lightscript/match/multi-subscripts/expected.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 74, + "end": 72, "loc": { "start": { "line": 1, @@ -9,13 +9,13 @@ }, "end": { "line": 3, - "column": 33 + "column": 30 } }, "program": { "type": "Program", "start": 0, - "end": 74, + "end": 72, "loc": { "start": { "line": 1, @@ -23,7 +23,7 @@ }, "end": { "line": 3, - "column": 33 + "column": 30 } }, "sourceType": "script", @@ -31,7 +31,7 @@ { "type": "ExpressionStatement", "start": 0, - "end": 74, + "end": 72, "loc": { "start": { "line": 1, @@ -39,13 +39,13 @@ }, "end": { "line": 3, - "column": 33 + "column": 30 } }, "expression": { "type": "MatchExpression", "start": 0, - "end": 74, + "end": 72, "loc": { "start": { "line": 1, @@ -53,7 +53,7 @@ }, "end": { "line": 3, - "column": 33 + "column": 30 } }, "discriminant": { @@ -77,7 +77,7 @@ { "type": "MatchCase", "start": 11, - "end": 40, + "end": 41, "loc": { "start": { "line": 2, @@ -85,13 +85,13 @@ }, "end": { "line": 2, - "column": 31 + "column": 32 } }, "test": { "type": "LogicalExpression", "start": 13, - "end": 22, + "end": 24, "loc": { "start": { "line": 2, @@ -99,7 +99,7 @@ }, "end": { "line": 2, - "column": 13 + "column": 15 } }, "left": { @@ -154,7 +154,7 @@ "right": { "type": "MemberExpression", "start": 20, - "end": 22, + "end": 24, "loc": { "start": { "line": 2, @@ -162,90 +162,117 @@ }, "end": { "line": 2, - "column": 13 + "column": 15 } }, "object": { - "type": "PlaceholderExpression", - "start": 19, - "end": 20, + "type": "MemberExpression", + "start": 20, + "end": 22, "loc": { "start": { "line": 2, - "column": 10 + "column": 11 }, "end": { "line": 2, - "column": 11 + "column": 13 } - } + }, + "object": { + "type": "PlaceholderExpression", + "start": 19, + "end": 20, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + } + } + }, + "property": { + "type": "Identifier", + "start": 21, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 13 + }, + "identifierName": "b" + }, + "name": "b" + }, + "computed": false }, "property": { "type": "Identifier", - "start": 21, - "end": 22, + "start": 23, + "end": 24, "loc": { "start": { "line": 2, - "column": 12 + "column": 14 }, "end": { "line": 2, - "column": 13 + "column": 15 }, - "identifierName": "b" + "identifierName": "c" }, - "name": "b" + "name": "c" }, "computed": false } }, "consequent": { - "type": "ArrowFunctionExpression", - "start": 24, - "end": 40, + "type": "ExpressionStatement", + "start": 26, + "end": 41, "loc": { "start": { "line": 2, - "column": 15 + "column": 17 }, "end": { "line": 2, - "column": 31 + "column": 32 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "StringLiteral", - "start": 27, - "end": 40, + "start": 26, + "end": 41, "loc": { "start": { "line": 2, - "column": 18 + "column": 17 }, "end": { "line": 2, - "column": 31 + "column": 32 } }, "extra": { - "rawValue": "has a and b", - "raw": "'has a and b'" + "rawValue": "has a and b.c", + "raw": "'has a and b.c'" }, - "value": "has a and b" + "value": "has a and b.c" } } }, { "type": "MatchCase", - "start": 43, - "end": 74, + "start": 44, + "end": 72, "loc": { "start": { "line": 3, @@ -253,13 +280,13 @@ }, "end": { "line": 3, - "column": 33 + "column": 30 } }, "test": { "type": "LogicalExpression", - "start": 45, - "end": 57, + "start": 46, + "end": 58, "loc": { "start": { "line": 3, @@ -272,8 +299,8 @@ }, "left": { "type": "TildeCallExpression", - "start": 45, - "end": 49, + "start": 46, + "end": 50, "loc": { "start": { "line": 3, @@ -286,8 +313,8 @@ }, "left": { "type": "PlaceholderExpression", - "start": 44, - "end": 45, + "start": 45, + "end": 46, "loc": { "start": { "line": 3, @@ -301,8 +328,8 @@ }, "right": { "type": "Identifier", - "start": 46, - "end": 47, + "start": 47, + "end": 48, "loc": { "start": { "line": 3, @@ -321,8 +348,8 @@ "operator": "||", "right": { "type": "TildeCallExpression", - "start": 53, - "end": 57, + "start": 54, + "end": 58, "loc": { "start": { "line": 3, @@ -335,8 +362,8 @@ }, "left": { "type": "PlaceholderExpression", - "start": 52, - "end": 53, + "start": 53, + "end": 54, "loc": { "start": { "line": 3, @@ -350,8 +377,8 @@ }, "right": { "type": "Identifier", - "start": 54, - "end": 55, + "start": 55, + "end": 56, "loc": { "start": { "line": 3, @@ -369,9 +396,9 @@ } }, "consequent": { - "type": "ArrowFunctionExpression", - "start": 59, - "end": 74, + "type": "ExpressionStatement", + "start": 60, + "end": 72, "loc": { "start": { "line": 3, @@ -379,27 +406,21 @@ }, "end": { "line": 3, - "column": 33 + "column": 30 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "StringLiteral", - "start": 62, - "end": 74, + "start": 60, + "end": 72, "loc": { "start": { "line": 3, - "column": 21 + "column": 18 }, "end": { "line": 3, - "column": 33 + "column": 30 } }, "extra": { diff --git a/test/fixtures/lightscript/match/nested/actual.js b/test/fixtures/lightscript/match/nested/actual.js index d0b680155e..2b273e8b75 100644 --- a/test/fixtures/lightscript/match/nested/actual.js +++ b/test/fixtures/lightscript/match/nested/actual.js @@ -1,6 +1,6 @@ match x: - | > 2, (y) -> match y: - | > 10, -> "soo big" - | > 5, -> "still pretty big" - | else, -> "kinda big" - | else, -> "some other thing" + | > 2 with y: match y: + | > 10: "soo big" + | > 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 index 47813f720e..d28049b71f 100644 --- a/test/fixtures/lightscript/match/nested/expected.json +++ b/test/fixtures/lightscript/match/nested/expected.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 150, + "end": 138, "loc": { "start": { "line": 1, @@ -9,13 +9,13 @@ }, "end": { "line": 6, - "column": 31 + "column": 28 } }, "program": { "type": "Program", "start": 0, - "end": 150, + "end": 138, "loc": { "start": { "line": 1, @@ -23,7 +23,7 @@ }, "end": { "line": 6, - "column": 31 + "column": 28 } }, "sourceType": "script", @@ -31,7 +31,7 @@ { "type": "ExpressionStatement", "start": 0, - "end": 150, + "end": 138, "loc": { "start": { "line": 1, @@ -39,13 +39,13 @@ }, "end": { "line": 6, - "column": 31 + "column": 28 } }, "expression": { "type": "MatchExpression", "start": 0, - "end": 150, + "end": 138, "loc": { "start": { "line": 1, @@ -53,7 +53,7 @@ }, "end": { "line": 6, - "column": 31 + "column": 28 } }, "discriminant": { @@ -77,7 +77,7 @@ { "type": "MatchCase", "start": 11, - "end": 118, + "end": 109, "loc": { "start": { "line": 2, @@ -85,7 +85,7 @@ }, "end": { "line": 5, - "column": 26 + "column": 23 } }, "test": { @@ -139,48 +139,41 @@ "value": 2 } }, + "binding": { + "type": "Identifier", + "start": 22, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 14 + }, + "identifierName": "y" + }, + "name": "y" + }, "consequent": { - "type": "ArrowFunctionExpression", - "start": 18, - "end": 118, + "type": "ExpressionStatement", + "start": 25, + "end": 109, "loc": { "start": { "line": 2, - "column": 9 + "column": 16 }, "end": { "line": 5, - "column": 26 + "column": 23 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [ - { - "type": "Identifier", - "start": 19, - "end": 20, - "loc": { - "start": { - "line": 2, - "column": 10 - }, - "end": { - "line": 2, - "column": 11 - }, - "identifierName": "y" - }, - "name": "y" - } - ], - "skinny": true, - "body": { + "expression": { "type": "MatchExpression", "start": 25, - "end": 118, + "end": 109, "loc": { "start": { "line": 2, @@ -188,7 +181,7 @@ }, "end": { "line": 5, - "column": 26 + "column": 23 } }, "discriminant": { @@ -212,7 +205,7 @@ { "type": "MatchCase", "start": 38, - "end": 58, + "end": 55, "loc": { "start": { "line": 3, @@ -220,7 +213,7 @@ }, "end": { "line": 3, - "column": 24 + "column": 21 } }, "test": { @@ -275,9 +268,9 @@ } }, "consequent": { - "type": "ArrowFunctionExpression", + "type": "ExpressionStatement", "start": 46, - "end": 58, + "end": 55, "loc": { "start": { "line": 3, @@ -285,27 +278,21 @@ }, "end": { "line": 3, - "column": 24 + "column": 21 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "StringLiteral", - "start": 49, - "end": 58, + "start": 46, + "end": 55, "loc": { "start": { "line": 3, - "column": 15 + "column": 12 }, "end": { "line": 3, - "column": 24 + "column": 21 } }, "extra": { @@ -318,8 +305,8 @@ }, { "type": "MatchCase", - "start": 63, - "end": 91, + "start": 60, + "end": 85, "loc": { "start": { "line": 4, @@ -327,13 +314,13 @@ }, "end": { "line": 4, - "column": 32 + "column": 29 } }, "test": { "type": "BinaryExpression", - "start": 65, - "end": 68, + "start": 62, + "end": 65, "loc": { "start": { "line": 4, @@ -346,8 +333,8 @@ }, "left": { "type": "PlaceholderExpression", - "start": 64, - "end": 65, + "start": 61, + "end": 62, "loc": { "start": { "line": 4, @@ -362,8 +349,8 @@ "operator": ">", "right": { "type": "NumericLiteral", - "start": 67, - "end": 68, + "start": 64, + "end": 65, "loc": { "start": { "line": 4, @@ -382,9 +369,9 @@ } }, "consequent": { - "type": "ArrowFunctionExpression", - "start": 70, - "end": 91, + "type": "ExpressionStatement", + "start": 67, + "end": 85, "loc": { "start": { "line": 4, @@ -392,27 +379,21 @@ }, "end": { "line": 4, - "column": 32 + "column": 29 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "StringLiteral", - "start": 73, - "end": 91, + "start": 67, + "end": 85, "loc": { "start": { "line": 4, - "column": 14 + "column": 11 }, "end": { "line": 4, - "column": 32 + "column": 29 } }, "extra": { @@ -425,8 +406,8 @@ }, { "type": "MatchCase", - "start": 96, - "end": 118, + "start": 90, + "end": 109, "loc": { "start": { "line": 5, @@ -434,13 +415,13 @@ }, "end": { "line": 5, - "column": 26 + "column": 23 } }, "test": { "type": "MatchElse", - "start": 98, - "end": 102, + "start": 92, + "end": 96, "loc": { "start": { "line": 5, @@ -453,9 +434,9 @@ } }, "consequent": { - "type": "ArrowFunctionExpression", - "start": 104, - "end": 118, + "type": "ExpressionStatement", + "start": 98, + "end": 109, "loc": { "start": { "line": 5, @@ -463,27 +444,21 @@ }, "end": { "line": 5, - "column": 26 + "column": 23 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "StringLiteral", - "start": 107, - "end": 118, + "start": 98, + "end": 109, "loc": { "start": { "line": 5, - "column": 15 + "column": 12 }, "end": { "line": 5, - "column": 26 + "column": 23 } }, "extra": { @@ -500,8 +475,8 @@ }, { "type": "MatchCase", - "start": 121, - "end": 150, + "start": 112, + "end": 138, "loc": { "start": { "line": 6, @@ -509,13 +484,13 @@ }, "end": { "line": 6, - "column": 31 + "column": 28 } }, "test": { "type": "MatchElse", - "start": 123, - "end": 127, + "start": 114, + "end": 118, "loc": { "start": { "line": 6, @@ -528,9 +503,9 @@ } }, "consequent": { - "type": "ArrowFunctionExpression", - "start": 129, - "end": 150, + "type": "ExpressionStatement", + "start": 120, + "end": 138, "loc": { "start": { "line": 6, @@ -538,27 +513,21 @@ }, "end": { "line": 6, - "column": 31 + "column": 28 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "StringLiteral", - "start": 132, - "end": 150, + "start": 120, + "end": 138, "loc": { "start": { "line": 6, - "column": 13 + "column": 10 }, "end": { "line": 6, - "column": 31 + "column": 28 } }, "extra": { diff --git a/test/fixtures/lightscript/match/newline-after-pipe-illegal/actual.js b/test/fixtures/lightscript/match/newline-after-pipe-illegal/actual.js index 527e589796..c8c3c0b9ca 100644 --- a/test/fixtures/lightscript/match/newline-after-pipe-illegal/actual.js +++ b/test/fixtures/lightscript/match/newline-after-pipe-illegal/actual.js @@ -1,3 +1,3 @@ match x: | - d, -> 'its a func' + d: 'its a func' diff --git a/test/fixtures/lightscript/match/parens-arent-calls/actual.js b/test/fixtures/lightscript/match/parens-arent-calls/actual.js index 64eaeb2bf4..41e01ef13d 100644 --- a/test/fixtures/lightscript/match/parens-arent-calls/actual.js +++ b/test/fixtures/lightscript/match/parens-arent-calls/actual.js @@ -1,2 +1,2 @@ a = match x: - | (y), -> "bigger than two" + | (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 index 6c4945ff71..d85a596994 100644 --- a/test/fixtures/lightscript/match/parens-arent-calls/expected.json +++ b/test/fixtures/lightscript/match/parens-arent-calls/expected.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 42, + "end": 39, "loc": { "start": { "line": 1, @@ -9,13 +9,13 @@ }, "end": { "line": 2, - "column": 29 + "column": 26 } }, "program": { "type": "Program", "start": 0, - "end": 42, + "end": 39, "loc": { "start": { "line": 1, @@ -23,7 +23,7 @@ }, "end": { "line": 2, - "column": 29 + "column": 26 } }, "sourceType": "script", @@ -31,7 +31,7 @@ { "type": "VariableDeclaration", "start": 0, - "end": 42, + "end": 39, "loc": { "start": { "line": 1, @@ -39,7 +39,7 @@ }, "end": { "line": 2, - "column": 29 + "column": 26 } }, "kind": "const", @@ -50,7 +50,7 @@ { "type": "VariableDeclarator", "start": 0, - "end": 42, + "end": 39, "loc": { "start": { "line": 1, @@ -58,7 +58,7 @@ }, "end": { "line": 2, - "column": 29 + "column": 26 } }, "id": { @@ -81,7 +81,7 @@ "init": { "type": "MatchExpression", "start": 4, - "end": 42, + "end": 39, "loc": { "start": { "line": 1, @@ -89,7 +89,7 @@ }, "end": { "line": 2, - "column": 29 + "column": 26 } }, "discriminant": { @@ -113,7 +113,7 @@ { "type": "MatchCase", "start": 15, - "end": 42, + "end": 39, "loc": { "start": { "line": 2, @@ -121,7 +121,7 @@ }, "end": { "line": 2, - "column": 29 + "column": 26 } }, "test": { @@ -146,9 +146,9 @@ } }, "consequent": { - "type": "ArrowFunctionExpression", + "type": "ExpressionStatement", "start": 22, - "end": 42, + "end": 39, "loc": { "start": { "line": 2, @@ -156,27 +156,21 @@ }, "end": { "line": 2, - "column": 29 + "column": 26 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "StringLiteral", - "start": 25, - "end": 42, + "start": 22, + "end": 39, "loc": { "start": { "line": 2, - "column": 12 + "column": 9 }, "end": { "line": 2, - "column": 29 + "column": 26 } }, "extra": { 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 index 886c29fd3c..3e3f3d123d 100644 --- 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 @@ -1 +1 @@ -a = match (x) | > 2, -> "bigger than two" +a = match (x) | > 2: "bigger than two" diff --git a/test/fixtures/lightscript/match/parens-no-curlies/actual.js b/test/fixtures/lightscript/match/parens-no-curlies/actual.js index 047e5e7344..47af3d40ad 100644 --- a/test/fixtures/lightscript/match/parens-no-curlies/actual.js +++ b/test/fixtures/lightscript/match/parens-no-curlies/actual.js @@ -1,3 +1,3 @@ a = match (x): - | > 2, -> "bigger than two" - | else, -> "some other thing" + | > 2: "bigger than 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 index 45d8369207..c57f23c768 100644 --- a/test/fixtures/lightscript/match/parens-no-curlies/expected.json +++ b/test/fixtures/lightscript/match/parens-no-curlies/expected.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 76, + "end": 70, "loc": { "start": { "line": 1, @@ -9,13 +9,13 @@ }, "end": { "line": 3, - "column": 31 + "column": 28 } }, "program": { "type": "Program", "start": 0, - "end": 76, + "end": 70, "loc": { "start": { "line": 1, @@ -23,7 +23,7 @@ }, "end": { "line": 3, - "column": 31 + "column": 28 } }, "sourceType": "script", @@ -31,7 +31,7 @@ { "type": "VariableDeclaration", "start": 0, - "end": 76, + "end": 70, "loc": { "start": { "line": 1, @@ -39,7 +39,7 @@ }, "end": { "line": 3, - "column": 31 + "column": 28 } }, "kind": "const", @@ -50,7 +50,7 @@ { "type": "VariableDeclarator", "start": 0, - "end": 76, + "end": 70, "loc": { "start": { "line": 1, @@ -58,7 +58,7 @@ }, "end": { "line": 3, - "column": 31 + "column": 28 } }, "id": { @@ -81,7 +81,7 @@ "init": { "type": "MatchExpression", "start": 4, - "end": 76, + "end": 70, "loc": { "start": { "line": 1, @@ -89,7 +89,7 @@ }, "end": { "line": 3, - "column": 31 + "column": 28 } }, "discriminant": { @@ -114,7 +114,7 @@ { "type": "MatchCase", "start": 17, - "end": 44, + "end": 41, "loc": { "start": { "line": 2, @@ -122,7 +122,7 @@ }, "end": { "line": 2, - "column": 29 + "column": 26 } }, "test": { @@ -177,9 +177,9 @@ } }, "consequent": { - "type": "ArrowFunctionExpression", + "type": "ExpressionStatement", "start": 24, - "end": 44, + "end": 41, "loc": { "start": { "line": 2, @@ -187,27 +187,21 @@ }, "end": { "line": 2, - "column": 29 + "column": 26 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "StringLiteral", - "start": 27, - "end": 44, + "start": 24, + "end": 41, "loc": { "start": { "line": 2, - "column": 12 + "column": 9 }, "end": { "line": 2, - "column": 29 + "column": 26 } }, "extra": { @@ -220,8 +214,8 @@ }, { "type": "MatchCase", - "start": 47, - "end": 76, + "start": 44, + "end": 70, "loc": { "start": { "line": 3, @@ -229,13 +223,13 @@ }, "end": { "line": 3, - "column": 31 + "column": 28 } }, "test": { "type": "MatchElse", - "start": 49, - "end": 53, + "start": 46, + "end": 50, "loc": { "start": { "line": 3, @@ -248,9 +242,9 @@ } }, "consequent": { - "type": "ArrowFunctionExpression", - "start": 55, - "end": 76, + "type": "ExpressionStatement", + "start": 52, + "end": 70, "loc": { "start": { "line": 3, @@ -258,27 +252,21 @@ }, "end": { "line": 3, - "column": 31 + "column": 28 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "StringLiteral", - "start": 58, - "end": 76, + "start": 52, + "end": 70, "loc": { "start": { "line": 3, - "column": 13 + "column": 10 }, "end": { "line": 3, - "column": 31 + "column": 28 } }, "extra": { diff --git a/test/fixtures/lightscript/match/subscript-in-tilde/actual.js b/test/fixtures/lightscript/match/subscript-in-tilde/actual.js index 8a58cab69f..9e4dfee2f1 100644 --- a/test/fixtures/lightscript/match/subscript-in-tilde/actual.js +++ b/test/fixtures/lightscript/match/subscript-in-tilde/actual.js @@ -1,2 +1,2 @@ match x: - | ~c(.d), -> 'its a func' + | ~c(.d): 'its a func' diff --git a/test/fixtures/lightscript/match/subscript-in-tilde/expected.json b/test/fixtures/lightscript/match/subscript-in-tilde/expected.json index e699a3926d..a6217fde94 100644 --- a/test/fixtures/lightscript/match/subscript-in-tilde/expected.json +++ b/test/fixtures/lightscript/match/subscript-in-tilde/expected.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 36, + "end": 33, "loc": { "start": { "line": 1, @@ -9,13 +9,13 @@ }, "end": { "line": 2, - "column": 27 + "column": 24 } }, "program": { "type": "Program", "start": 0, - "end": 36, + "end": 33, "loc": { "start": { "line": 1, @@ -23,7 +23,7 @@ }, "end": { "line": 2, - "column": 27 + "column": 24 } }, "sourceType": "script", @@ -31,7 +31,7 @@ { "type": "ExpressionStatement", "start": 0, - "end": 36, + "end": 33, "loc": { "start": { "line": 1, @@ -39,13 +39,13 @@ }, "end": { "line": 2, - "column": 27 + "column": 24 } }, "expression": { "type": "MatchExpression", "start": 0, - "end": 36, + "end": 33, "loc": { "start": { "line": 1, @@ -53,7 +53,7 @@ }, "end": { "line": 2, - "column": 27 + "column": 24 } }, "discriminant": { @@ -77,7 +77,7 @@ { "type": "MatchCase", "start": 11, - "end": 36, + "end": 33, "loc": { "start": { "line": 2, @@ -85,7 +85,7 @@ }, "end": { "line": 2, - "column": 27 + "column": 24 } }, "test": { @@ -186,9 +186,9 @@ ] }, "consequent": { - "type": "ArrowFunctionExpression", + "type": "ExpressionStatement", "start": 21, - "end": 36, + "end": 33, "loc": { "start": { "line": 2, @@ -196,27 +196,21 @@ }, "end": { "line": 2, - "column": 27 + "column": 24 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "StringLiteral", - "start": 24, - "end": 36, + "start": 21, + "end": 33, "loc": { "start": { "line": 2, - "column": 15 + "column": 12 }, "end": { "line": 2, - "column": 27 + "column": 24 } }, "extra": { diff --git a/test/fixtures/lightscript/match/subscripts/actual.js b/test/fixtures/lightscript/match/subscripts/actual.js index 5257531524..e0a896a349 100644 --- a/test/fixtures/lightscript/match/subscripts/actual.js +++ b/test/fixtures/lightscript/match/subscripts/actual.js @@ -1,7 +1,7 @@ match x: - | .a, -> 'has a' - | ['b'], -> 'has b' - | ?.c, -> 'has c' - | ?[d], -> 'has d' - | .0, -> 'has first elem' - | ~isFunction(), -> 'its a func' + | .a: 'has a' + | ['b']: 'has b' + | ?.c: 'has c' + | ?[d]: 'has d' + | .0: 'has first elem' + | ~isFunction(): 'its a func' diff --git a/test/fixtures/lightscript/match/subscripts/expected.json b/test/fixtures/lightscript/match/subscripts/expected.json index c4fe95bc0d..8525f8fadd 100644 --- a/test/fixtures/lightscript/match/subscripts/expected.json +++ b/test/fixtures/lightscript/match/subscripts/expected.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 153, + "end": 135, "loc": { "start": { "line": 1, @@ -9,13 +9,13 @@ }, "end": { "line": 7, - "column": 34 + "column": 31 } }, "program": { "type": "Program", "start": 0, - "end": 153, + "end": 135, "loc": { "start": { "line": 1, @@ -23,7 +23,7 @@ }, "end": { "line": 7, - "column": 34 + "column": 31 } }, "sourceType": "script", @@ -31,7 +31,7 @@ { "type": "ExpressionStatement", "start": 0, - "end": 153, + "end": 135, "loc": { "start": { "line": 1, @@ -39,13 +39,13 @@ }, "end": { "line": 7, - "column": 34 + "column": 31 } }, "expression": { "type": "MatchExpression", "start": 0, - "end": 153, + "end": 135, "loc": { "start": { "line": 1, @@ -53,7 +53,7 @@ }, "end": { "line": 7, - "column": 34 + "column": 31 } }, "discriminant": { @@ -77,7 +77,7 @@ { "type": "MatchCase", "start": 11, - "end": 27, + "end": 24, "loc": { "start": { "line": 2, @@ -85,7 +85,7 @@ }, "end": { "line": 2, - "column": 18 + "column": 15 } }, "test": { @@ -137,9 +137,9 @@ "computed": false }, "consequent": { - "type": "ArrowFunctionExpression", + "type": "ExpressionStatement", "start": 17, - "end": 27, + "end": 24, "loc": { "start": { "line": 2, @@ -147,27 +147,21 @@ }, "end": { "line": 2, - "column": 18 + "column": 15 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "StringLiteral", - "start": 20, - "end": 27, + "start": 17, + "end": 24, "loc": { "start": { "line": 2, - "column": 11 + "column": 8 }, "end": { "line": 2, - "column": 18 + "column": 15 } }, "extra": { @@ -180,8 +174,8 @@ }, { "type": "MatchCase", - "start": 30, - "end": 49, + "start": 27, + "end": 43, "loc": { "start": { "line": 3, @@ -189,13 +183,13 @@ }, "end": { "line": 3, - "column": 21 + "column": 18 } }, "test": { "type": "ArrayExpression", - "start": 32, - "end": 37, + "start": 29, + "end": 34, "loc": { "start": { "line": 3, @@ -209,8 +203,8 @@ "elements": [ { "type": "StringLiteral", - "start": 33, - "end": 36, + "start": 30, + "end": 33, "loc": { "start": { "line": 3, @@ -230,9 +224,9 @@ ] }, "consequent": { - "type": "ArrowFunctionExpression", - "start": 39, - "end": 49, + "type": "ExpressionStatement", + "start": 36, + "end": 43, "loc": { "start": { "line": 3, @@ -240,27 +234,21 @@ }, "end": { "line": 3, - "column": 21 + "column": 18 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "StringLiteral", - "start": 42, - "end": 49, + "start": 36, + "end": 43, "loc": { "start": { "line": 3, - "column": 14 + "column": 11 }, "end": { "line": 3, - "column": 21 + "column": 18 } }, "extra": { @@ -273,8 +261,8 @@ }, { "type": "MatchCase", - "start": 52, - "end": 69, + "start": 46, + "end": 60, "loc": { "start": { "line": 4, @@ -282,13 +270,13 @@ }, "end": { "line": 4, - "column": 19 + "column": 16 } }, "test": { "type": "SafeMemberExpression", - "start": 54, - "end": 57, + "start": 48, + "end": 51, "loc": { "start": { "line": 4, @@ -301,8 +289,8 @@ }, "object": { "type": "PlaceholderExpression", - "start": 53, - "end": 54, + "start": 47, + "end": 48, "loc": { "start": { "line": 4, @@ -316,8 +304,8 @@ }, "property": { "type": "Identifier", - "start": 56, - "end": 57, + "start": 50, + "end": 51, "loc": { "start": { "line": 4, @@ -334,9 +322,9 @@ "computed": false }, "consequent": { - "type": "ArrowFunctionExpression", - "start": 59, - "end": 69, + "type": "ExpressionStatement", + "start": 53, + "end": 60, "loc": { "start": { "line": 4, @@ -344,27 +332,21 @@ }, "end": { "line": 4, - "column": 19 + "column": 16 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "StringLiteral", - "start": 62, - "end": 69, + "start": 53, + "end": 60, "loc": { "start": { "line": 4, - "column": 12 + "column": 9 }, "end": { "line": 4, - "column": 19 + "column": 16 } }, "extra": { @@ -377,8 +359,8 @@ }, { "type": "MatchCase", - "start": 72, - "end": 90, + "start": 63, + "end": 78, "loc": { "start": { "line": 5, @@ -386,13 +368,13 @@ }, "end": { "line": 5, - "column": 20 + "column": 17 } }, "test": { "type": "SafeMemberExpression", - "start": 74, - "end": 78, + "start": 65, + "end": 69, "loc": { "start": { "line": 5, @@ -405,8 +387,8 @@ }, "object": { "type": "PlaceholderExpression", - "start": 73, - "end": 74, + "start": 64, + "end": 65, "loc": { "start": { "line": 5, @@ -420,8 +402,8 @@ }, "property": { "type": "Identifier", - "start": 76, - "end": 77, + "start": 67, + "end": 68, "loc": { "start": { "line": 5, @@ -438,9 +420,9 @@ "computed": true }, "consequent": { - "type": "ArrowFunctionExpression", - "start": 80, - "end": 90, + "type": "ExpressionStatement", + "start": 71, + "end": 78, "loc": { "start": { "line": 5, @@ -448,27 +430,21 @@ }, "end": { "line": 5, - "column": 20 + "column": 17 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "StringLiteral", - "start": 83, - "end": 90, + "start": 71, + "end": 78, "loc": { "start": { "line": 5, - "column": 13 + "column": 10 }, "end": { "line": 5, - "column": 20 + "column": 17 } }, "extra": { @@ -481,8 +457,8 @@ }, { "type": "MatchCase", - "start": 93, - "end": 118, + "start": 81, + "end": 103, "loc": { "start": { "line": 6, @@ -490,13 +466,13 @@ }, "end": { "line": 6, - "column": 27 + "column": 24 } }, "test": { - "type": "NumericLiteral", - "start": 95, - "end": 97, + "type": "MemberExpression", + "start": 83, + "end": 85, "loc": { "start": { "line": 6, @@ -507,16 +483,47 @@ "column": 6 } }, - "extra": { - "rawValue": 0, - "raw": ".0" + "object": { + "type": "PlaceholderExpression", + "start": 82, + "end": 83, + "loc": { + "start": { + "line": 6, + "column": 3 + }, + "end": { + "line": 6, + "column": 4 + } + } + }, + "property": { + "type": "NumericLiteral", + "start": 84, + "end": 85, + "loc": { + "start": { + "line": 6, + "column": 5 + }, + "end": { + "line": 6, + "column": 6 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 }, - "value": 0 + "computed": true }, "consequent": { - "type": "ArrowFunctionExpression", - "start": 99, - "end": 118, + "type": "ExpressionStatement", + "start": 87, + "end": 103, "loc": { "start": { "line": 6, @@ -524,27 +531,21 @@ }, "end": { "line": 6, - "column": 27 + "column": 24 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "StringLiteral", - "start": 102, - "end": 118, + "start": 87, + "end": 103, "loc": { "start": { "line": 6, - "column": 11 + "column": 8 }, "end": { "line": 6, - "column": 27 + "column": 24 } }, "extra": { @@ -557,8 +558,8 @@ }, { "type": "MatchCase", - "start": 121, - "end": 153, + "start": 106, + "end": 135, "loc": { "start": { "line": 7, @@ -566,13 +567,13 @@ }, "end": { "line": 7, - "column": 34 + "column": 31 } }, "test": { "type": "TildeCallExpression", - "start": 123, - "end": 136, + "start": 108, + "end": 121, "loc": { "start": { "line": 7, @@ -585,8 +586,8 @@ }, "left": { "type": "PlaceholderExpression", - "start": 122, - "end": 123, + "start": 107, + "end": 108, "loc": { "start": { "line": 7, @@ -600,8 +601,8 @@ }, "right": { "type": "Identifier", - "start": 124, - "end": 134, + "start": 109, + "end": 119, "loc": { "start": { "line": 7, @@ -618,9 +619,9 @@ "arguments": [] }, "consequent": { - "type": "ArrowFunctionExpression", - "start": 138, - "end": 153, + "type": "ExpressionStatement", + "start": 123, + "end": 135, "loc": { "start": { "line": 7, @@ -628,27 +629,21 @@ }, "end": { "line": 7, - "column": 34 + "column": 31 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "StringLiteral", - "start": 141, - "end": 153, + "start": 123, + "end": 135, "loc": { "start": { "line": 7, - "column": 22 + "column": 19 }, "end": { "line": 7, - "column": 34 + "column": 31 } }, "extra": { diff --git a/test/fixtures/lightscript/match/tag-literal/actual.js b/test/fixtures/lightscript/match/tag-literal/actual.js index e6811e4078..05c725a01e 100644 --- a/test/fixtures/lightscript/match/tag-literal/actual.js +++ b/test/fixtures/lightscript/match/tag-literal/actual.js @@ -1,3 +1,3 @@ match x: - | `a`, -> 'is "a"' - | `${b}`, -> 'is str of b' + | `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 index 608f0c9180..9f6adc3c15 100644 --- a/test/fixtures/lightscript/match/tag-literal/expected.json +++ b/test/fixtures/lightscript/match/tag-literal/expected.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 58, + "end": 52, "loc": { "start": { "line": 1, @@ -9,13 +9,13 @@ }, "end": { "line": 3, - "column": 28 + "column": 25 } }, "program": { "type": "Program", "start": 0, - "end": 58, + "end": 52, "loc": { "start": { "line": 1, @@ -23,7 +23,7 @@ }, "end": { "line": 3, - "column": 28 + "column": 25 } }, "sourceType": "script", @@ -31,7 +31,7 @@ { "type": "ExpressionStatement", "start": 0, - "end": 58, + "end": 52, "loc": { "start": { "line": 1, @@ -39,13 +39,13 @@ }, "end": { "line": 3, - "column": 28 + "column": 25 } }, "expression": { "type": "MatchExpression", "start": 0, - "end": 58, + "end": 52, "loc": { "start": { "line": 1, @@ -53,7 +53,7 @@ }, "end": { "line": 3, - "column": 28 + "column": 25 } }, "discriminant": { @@ -77,7 +77,7 @@ { "type": "MatchCase", "start": 11, - "end": 29, + "end": 26, "loc": { "start": { "line": 2, @@ -85,7 +85,7 @@ }, "end": { "line": 2, - "column": 20 + "column": 17 } }, "test": { @@ -127,9 +127,9 @@ ] }, "consequent": { - "type": "ArrowFunctionExpression", + "type": "ExpressionStatement", "start": 18, - "end": 29, + "end": 26, "loc": { "start": { "line": 2, @@ -137,27 +137,21 @@ }, "end": { "line": 2, - "column": 20 + "column": 17 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "StringLiteral", - "start": 21, - "end": 29, + "start": 18, + "end": 26, "loc": { "start": { "line": 2, - "column": 12 + "column": 9 }, "end": { "line": 2, - "column": 20 + "column": 17 } }, "extra": { @@ -170,8 +164,8 @@ }, { "type": "MatchCase", - "start": 32, - "end": 58, + "start": 29, + "end": 52, "loc": { "start": { "line": 3, @@ -179,13 +173,13 @@ }, "end": { "line": 3, - "column": 28 + "column": 25 } }, "test": { "type": "TemplateLiteral", - "start": 34, - "end": 40, + "start": 31, + "end": 37, "loc": { "start": { "line": 3, @@ -199,8 +193,8 @@ "expressions": [ { "type": "Identifier", - "start": 37, - "end": 38, + "start": 34, + "end": 35, "loc": { "start": { "line": 3, @@ -218,8 +212,8 @@ "quasis": [ { "type": "TemplateElement", - "start": 35, - "end": 35, + "start": 32, + "end": 32, "loc": { "start": { "line": 3, @@ -238,8 +232,8 @@ }, { "type": "TemplateElement", - "start": 39, - "end": 39, + "start": 36, + "end": 36, "loc": { "start": { "line": 3, @@ -259,9 +253,9 @@ ] }, "consequent": { - "type": "ArrowFunctionExpression", - "start": 42, - "end": 58, + "type": "ExpressionStatement", + "start": 39, + "end": 52, "loc": { "start": { "line": 3, @@ -269,27 +263,21 @@ }, "end": { "line": 3, - "column": 28 + "column": 25 } }, - "id": null, - "generator": false, - "expression": true, - "async": false, - "params": [], - "skinny": true, - "body": { + "expression": { "type": "StringLiteral", - "start": 45, - "end": 58, + "start": 39, + "end": 52, "loc": { "start": { "line": 3, - "column": 15 + "column": 12 }, "end": { "line": 3, - "column": 28 + "column": 25 } }, "extra": { 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 From fe18036a2c49b70b9198bfb82f38f1a387f9adf2 Mon Sep 17 00:00:00 2001 From: Alex Rattray Date: Thu, 1 Jun 2017 15:08:26 -0700 Subject: [PATCH 03/12] MatchStatement --- src/parser/expression.js | 3 +- src/parser/statement.js | 3 + src/plugins/lightscript.js | 32 +- .../match/basic-destructuring/expected.json | 1079 +++++++------- .../binary-both-subscripts/expected.json | 245 ++-- .../lightscript/match/binary/expected.json | 1285 ++++++++--------- .../match/curly-consequent/actual.js | 12 + .../match/curly-consequent/expected.json | 520 +++++++ .../lightscript/match/else-solo/expected.json | 115 +- .../lightscript/match/else/expected.json | 187 ++- .../match/expression-break-illegal/actual.js | 3 + .../expression-break-illegal/options.json | 3 + .../match/expression-return-illegal/actual.js | 5 + .../expression-return-illegal/options.json | 3 + .../match/jsx-result/expected.json | 135 +- .../lightscript/match/less-than/expected.json | 297 ++-- .../lightscript/match/literals/expected.json | 951 ++++++------ .../multi-subscripts-number/expected.json | 403 +++--- .../match/multi-subscripts/expected.json | 479 +++--- .../lightscript/match/nested/expected.json | 722 +++++---- .../actual.js | 2 + .../options.json | 3 + .../actual.js | 4 + .../options.json | 3 + .../match/statement-break/actual.js | 3 + .../match/statement-break/expected.json | 171 +++ .../match/statement-return/actual.js | 3 + .../match/statement-return/expected.json | 177 +++ .../match/subscript-in-tilde/expected.json | 227 ++- .../match/subscripts/expected.json | 797 +++++----- .../match/tag-literal/expected.json | 347 +++-- 31 files changed, 4465 insertions(+), 3754 deletions(-) create mode 100644 test/fixtures/lightscript/match/curly-consequent/actual.js create mode 100644 test/fixtures/lightscript/match/curly-consequent/expected.json create mode 100644 test/fixtures/lightscript/match/expression-break-illegal/actual.js create mode 100644 test/fixtures/lightscript/match/expression-break-illegal/options.json create mode 100644 test/fixtures/lightscript/match/expression-return-illegal/actual.js create mode 100644 test/fixtures/lightscript/match/expression-return-illegal/options.json create mode 100644 test/fixtures/lightscript/match/paren-no-curly-consequent-illegal/actual.js create mode 100644 test/fixtures/lightscript/match/paren-no-curly-consequent-illegal/options.json create mode 100644 test/fixtures/lightscript/match/parenthesized-destructuring-illegal/actual.js create mode 100644 test/fixtures/lightscript/match/parenthesized-destructuring-illegal/options.json create mode 100644 test/fixtures/lightscript/match/statement-break/actual.js create mode 100644 test/fixtures/lightscript/match/statement-break/expected.json create mode 100644 test/fixtures/lightscript/match/statement-return/actual.js create mode 100644 test/fixtures/lightscript/match/statement-return/expected.json diff --git a/src/parser/expression.js b/src/parser/expression.js index 76ca02777c..654b6684ed 100644 --- a/src/parser/expression.js +++ b/src/parser/expression.js @@ -726,7 +726,8 @@ pp.parseExprAtom = function (refShorthandDefaultPos) { case tt._match: if (this.hasPlugin("lightscript")) { - return this.parseMatch(); + node = this.startNode(); + return this.parseMatchExpression(node); } case tt.arrow: 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/lightscript.js b/src/plugins/lightscript.js index a7752ce85e..8ca9858f61 100644 --- a/src/plugins/lightscript.js +++ b/src/plugins/lightscript.js @@ -550,8 +550,15 @@ pp.isBitwiseOp = function () { ); }; -pp.parseMatch = function () { - const node = this.startNode(); +pp.parseMatchExpression = function (node) { + return this.parseMatch(node, true); +}; + +pp.parseMatchStatement = function (node) { + return this.parseMatch(node, false); +}; + +pp.parseMatch = function (node, isExpression) { this.expect(tt._match); node.discriminant = this.parseParenExpression(); @@ -572,17 +579,17 @@ pp.parseMatch = function () { this.unexpected(null, "`else` must be last case."); } - const matchCase = this.parseMatchCase(); + const matchCase = this.parseMatchCase(isExpression); if (matchCase.test.type === "MatchElse") { hasUsedElse = true; } node.cases.push(matchCase); } - return this.finishNode(node, "MatchExpression"); + return this.finishNode(node, isExpression ? "MatchExpression" : "MatchStatement"); }; -pp.parseMatchCase = function () { +pp.parseMatchCase = function (isExpression) { const node = this.startNode(); node.test = this.parseMatchCaseTest(); @@ -591,7 +598,20 @@ pp.parseMatchCase = function () { node.binding = this.parseBindingAtom(); } - node.consequent = this.parseBlock(false); + 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"); }; diff --git a/test/fixtures/lightscript/match/basic-destructuring/expected.json b/test/fixtures/lightscript/match/basic-destructuring/expected.json index 952605c481..415a472e75 100644 --- a/test/fixtures/lightscript/match/basic-destructuring/expected.json +++ b/test/fixtures/lightscript/match/basic-destructuring/expected.json @@ -29,7 +29,7 @@ "sourceType": "script", "body": [ { - "type": "ExpressionStatement", + "type": "MatchStatement", "start": 0, "end": 130, "loc": { @@ -42,71 +42,71 @@ "column": 23 } }, - "expression": { - "type": "MatchExpression", - "start": 0, - "end": 130, + "discriminant": { + "type": "Identifier", + "start": 6, + "end": 7, "loc": { "start": { "line": 1, - "column": 0 + "column": 6 }, "end": { - "line": 8, - "column": 23 - } + "line": 1, + "column": 7 + }, + "identifierName": "x" }, - "discriminant": { - "type": "Identifier", - "start": 6, - "end": 7, + "name": "x" + }, + "cases": [ + { + "type": "MatchCase", + "start": 11, + "end": 17, "loc": { "start": { - "line": 1, - "column": 6 + "line": 2, + "column": 2 }, "end": { - "line": 1, - "column": 7 + "line": 2, + "column": 8 + } + }, + "test": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + }, + "identifierName": "a" }, - "identifierName": "x" + "name": "a" }, - "name": "x" - }, - "cases": [ - { - "type": "MatchCase", - "start": 11, + "consequent": { + "type": "ExpressionStatement", + "start": 16, "end": 17, "loc": { "start": { "line": 2, - "column": 2 + "column": 7 }, "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", + "expression": { + "type": "NumericLiteral", "start": 16, "end": 17, "loc": { @@ -119,61 +119,61 @@ "column": 8 } }, - "expression": { - "type": "NumericLiteral", - "start": 16, - "end": 17, - "loc": { - "start": { - "line": 2, - "column": 7 - }, - "end": { - "line": 2, - "column": 8 - } - }, - "extra": { - "rawValue": 1, - "raw": "1" - }, - "value": 1 - } + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + }, + { + "type": "MatchCase", + "start": 20, + "end": 26, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 8 } }, - { - "type": "MatchCase", - "start": 20, + "test": { + "type": "Identifier", + "start": 22, + "end": 23, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 5 + }, + "identifierName": "b" + }, + "name": "b" + }, + "consequent": { + "type": "ExpressionStatement", + "start": 25, "end": 26, "loc": { "start": { "line": 3, - "column": 2 + "column": 7 }, "end": { "line": 3, "column": 8 } }, - "test": { + "expression": { "type": "Identifier", - "start": 22, - "end": 23, - "loc": { - "start": { - "line": 3, - "column": 4 - }, - "end": { - "line": 3, - "column": 5 - }, - "identifierName": "b" - }, - "name": "b" - }, - "consequent": { - "type": "ExpressionStatement", "start": 25, "end": 26, "loc": { @@ -184,482 +184,482 @@ "end": { "line": 3, "column": 8 - } - }, - "expression": { - "type": "Identifier", - "start": 25, - "end": 26, - "loc": { - "start": { - "line": 3, - "column": 7 - }, - "end": { - "line": 3, - "column": 8 - }, - "identifierName": "b" }, - "name": "b" - } + "identifierName": "b" + }, + "name": "b" + } + } + }, + { + "type": "MatchCase", + "start": 29, + "end": 42, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 15 } }, - { - "type": "MatchCase", - "start": 29, + "test": { + "type": "Identifier", + "start": 31, + "end": 32, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 5 + }, + "identifierName": "c" + }, + "name": "c" + }, + "binding": { + "type": "Identifier", + "start": 38, + "end": 39, + "loc": { + "start": { + "line": 4, + "column": 11 + }, + "end": { + "line": 4, + "column": 12 + }, + "identifierName": "c" + }, + "name": "c" + }, + "consequent": { + "type": "ExpressionStatement", + "start": 41, "end": 42, "loc": { "start": { "line": 4, - "column": 2 + "column": 14 }, "end": { "line": 4, "column": 15 } }, - "test": { + "expression": { "type": "Identifier", - "start": 31, - "end": 32, + "start": 41, + "end": 42, "loc": { "start": { "line": 4, - "column": 4 + "column": 14 }, "end": { "line": 4, - "column": 5 + "column": 15 }, "identifierName": "c" }, "name": "c" + } + } + }, + { + "type": "MatchCase", + "start": 45, + "end": 62, + "loc": { + "start": { + "line": 5, + "column": 2 }, - "binding": { - "type": "Identifier", - "start": 38, - "end": 39, - "loc": { - "start": { - "line": 4, - "column": 11 - }, - "end": { - "line": 4, - "column": 12 - }, - "identifierName": "c" + "end": { + "line": 5, + "column": 19 + } + }, + "test": { + "type": "Identifier", + "start": 47, + "end": 48, + "loc": { + "start": { + "line": 5, + "column": 4 }, - "name": "c" + "end": { + "line": 5, + "column": 5 + }, + "identifierName": "d" }, - "consequent": { - "type": "ExpressionStatement", - "start": 41, - "end": 42, - "loc": { - "start": { - "line": 4, - "column": 14 - }, - "end": { - "line": 4, - "column": 15 - } + "name": "d" + }, + "binding": { + "type": "ObjectPattern", + "start": 54, + "end": 59, + "loc": { + "start": { + "line": 5, + "column": 11 }, - "expression": { - "type": "Identifier", - "start": 41, - "end": 42, + "end": { + "line": 5, + "column": 16 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 56, + "end": 57, "loc": { "start": { - "line": 4, - "column": 14 + "line": 5, + "column": 13 }, "end": { - "line": 4, - "column": 15 + "line": 5, + "column": 14 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 56, + "end": 57, + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 14 + }, + "identifierName": "d" + }, + "name": "d" + }, + "value": { + "type": "Identifier", + "start": 56, + "end": 57, + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 14 + }, + "identifierName": "d" }, - "identifierName": "c" + "name": "d" }, - "name": "c" + "extra": { + "shorthand": true + } } - } + ] }, - { - "type": "MatchCase", - "start": 45, + "consequent": { + "type": "ExpressionStatement", + "start": 61, "end": 62, "loc": { "start": { "line": 5, - "column": 2 + "column": 18 }, "end": { "line": 5, "column": 19 } }, - "test": { + "expression": { "type": "Identifier", - "start": 47, - "end": 48, + "start": 61, + "end": 62, "loc": { "start": { "line": 5, - "column": 4 + "column": 18 }, "end": { "line": 5, - "column": 5 + "column": 19 }, "identifierName": "d" }, "name": "d" + } + } + }, + { + "type": "MatchCase", + "start": 65, + "end": 86, + "loc": { + "start": { + "line": 6, + "column": 2 }, - "binding": { - "type": "ObjectPattern", - "start": 54, - "end": 59, - "loc": { - "start": { - "line": 5, - "column": 11 - }, - "end": { - "line": 5, - "column": 16 - } + "end": { + "line": 6, + "column": 23 + } + }, + "test": { + "type": "Identifier", + "start": 67, + "end": 68, + "loc": { + "start": { + "line": 6, + "column": 4 }, - "properties": [ - { - "type": "ObjectProperty", - "start": 56, - "end": 57, + "end": { + "line": 6, + "column": 5 + }, + "identifierName": "e" + }, + "name": "e" + }, + "binding": { + "type": "ObjectPattern", + "start": 74, + "end": 83, + "loc": { + "start": { + "line": 6, + "column": 11 + }, + "end": { + "line": 6, + "column": 20 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 76, + "end": 81, + "loc": { + "start": { + "line": 6, + "column": 13 + }, + "end": { + "line": 6, + "column": 18 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 76, + "end": 77, "loc": { "start": { - "line": 5, + "line": 6, "column": 13 }, "end": { - "line": 5, + "line": 6, "column": 14 + }, + "identifierName": "e" + }, + "name": "e" + }, + "value": { + "type": "AssignmentPattern", + "start": 76, + "end": 81, + "loc": { + "start": { + "line": 6, + "column": 13 + }, + "end": { + "line": 6, + "column": 18 } }, - "method": false, - "shorthand": true, - "computed": false, - "key": { + "left": { "type": "Identifier", - "start": 56, - "end": 57, + "start": 76, + "end": 77, "loc": { "start": { - "line": 5, + "line": 6, "column": 13 }, "end": { - "line": 5, + "line": 6, "column": 14 }, - "identifierName": "d" + "identifierName": "e" }, - "name": "d" + "name": "e" }, - "value": { - "type": "Identifier", - "start": 56, - "end": 57, - "loc": { + "right": { + "type": "NumericLiteral", + "start": 80, + "end": 81, + "loc": { "start": { - "line": 5, - "column": 13 + "line": 6, + "column": 17 }, "end": { - "line": 5, - "column": 14 - }, - "identifierName": "d" + "line": 6, + "column": 18 + } }, - "name": "d" - }, - "extra": { - "shorthand": true + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 } - } - ] - }, - "consequent": { - "type": "ExpressionStatement", - "start": 61, - "end": 62, - "loc": { - "start": { - "line": 5, - "column": 18 }, - "end": { - "line": 5, - "column": 19 + "extra": { + "shorthand": true } - }, - "expression": { - "type": "Identifier", - "start": 61, - "end": 62, - "loc": { - "start": { - "line": 5, - "column": 18 - }, - "end": { - "line": 5, - "column": 19 - }, - "identifierName": "d" - }, - "name": "d" } - } + ] }, - { - "type": "MatchCase", - "start": 65, + "consequent": { + "type": "ExpressionStatement", + "start": 85, "end": 86, "loc": { "start": { "line": 6, - "column": 2 + "column": 22 }, "end": { "line": 6, "column": 23 } }, - "test": { + "expression": { "type": "Identifier", - "start": 67, - "end": 68, + "start": 85, + "end": 86, "loc": { "start": { "line": 6, - "column": 4 + "column": 22 }, "end": { "line": 6, - "column": 5 + "column": 23 }, "identifierName": "e" }, "name": "e" + } + } + }, + { + "type": "MatchCase", + "start": 89, + "end": 106, + "loc": { + "start": { + "line": 7, + "column": 2 }, - "binding": { - "type": "ObjectPattern", - "start": 74, - "end": 83, - "loc": { - "start": { - "line": 6, - "column": 11 - }, - "end": { - "line": 6, - "column": 20 - } + "end": { + "line": 7, + "column": 19 + } + }, + "test": { + "type": "Identifier", + "start": 91, + "end": 92, + "loc": { + "start": { + "line": 7, + "column": 4 }, - "properties": [ - { - "type": "ObjectProperty", - "start": 76, - "end": 81, - "loc": { - "start": { - "line": 6, - "column": 13 - }, - "end": { - "line": 6, - "column": 18 - } - }, - "method": false, - "shorthand": true, - "computed": false, - "key": { - "type": "Identifier", - "start": 76, - "end": 77, - "loc": { - "start": { - "line": 6, - "column": 13 - }, - "end": { - "line": 6, - "column": 14 - }, - "identifierName": "e" - }, - "name": "e" - }, - "value": { - "type": "AssignmentPattern", - "start": 76, - "end": 81, - "loc": { - "start": { - "line": 6, - "column": 13 - }, - "end": { - "line": 6, - "column": 18 - } - }, - "left": { - "type": "Identifier", - "start": 76, - "end": 77, - "loc": { - "start": { - "line": 6, - "column": 13 - }, - "end": { - "line": 6, - "column": 14 - }, - "identifierName": "e" - }, - "name": "e" - }, - "right": { - "type": "NumericLiteral", - "start": 80, - "end": 81, - "loc": { - "start": { - "line": 6, - "column": 17 - }, - "end": { - "line": 6, - "column": 18 - } - }, - "extra": { - "rawValue": 1, - "raw": "1" - }, - "value": 1 - } - }, - "extra": { - "shorthand": true - } - } - ] + "end": { + "line": 7, + "column": 5 + }, + "identifierName": "f" }, - "consequent": { - "type": "ExpressionStatement", - "start": 85, - "end": 86, - "loc": { - "start": { - "line": 6, - "column": 22 - }, - "end": { - "line": 6, - "column": 23 - } + "name": "f" + }, + "binding": { + "type": "ArrayPattern", + "start": 98, + "end": 103, + "loc": { + "start": { + "line": 7, + "column": 11 }, - "expression": { + "end": { + "line": 7, + "column": 16 + } + }, + "elements": [ + { "type": "Identifier", - "start": 85, - "end": 86, + "start": 100, + "end": 101, "loc": { "start": { - "line": 6, - "column": 22 + "line": 7, + "column": 13 }, "end": { - "line": 6, - "column": 23 + "line": 7, + "column": 14 }, - "identifierName": "e" + "identifierName": "f" }, - "name": "e" + "name": "f" } - } + ] }, - { - "type": "MatchCase", - "start": 89, + "consequent": { + "type": "ExpressionStatement", + "start": 105, "end": 106, "loc": { "start": { "line": 7, - "column": 2 + "column": 18 }, "end": { "line": 7, "column": 19 } }, - "test": { + "expression": { "type": "Identifier", - "start": 91, - "end": 92, - "loc": { - "start": { - "line": 7, - "column": 4 - }, - "end": { - "line": 7, - "column": 5 - }, - "identifierName": "f" - }, - "name": "f" - }, - "binding": { - "type": "ArrayPattern", - "start": 98, - "end": 103, - "loc": { - "start": { - "line": 7, - "column": 11 - }, - "end": { - "line": 7, - "column": 16 - } - }, - "elements": [ - { - "type": "Identifier", - "start": 100, - "end": 101, - "loc": { - "start": { - "line": 7, - "column": 13 - }, - "end": { - "line": 7, - "column": 14 - }, - "identifierName": "f" - }, - "name": "f" - } - ] - }, - "consequent": { - "type": "ExpressionStatement", "start": 105, "end": 106, "loc": { @@ -670,129 +670,129 @@ "end": { "line": 7, "column": 19 - } - }, - "expression": { - "type": "Identifier", - "start": 105, - "end": 106, - "loc": { - "start": { - "line": 7, - "column": 18 - }, - "end": { - "line": 7, - "column": 19 - }, - "identifierName": "f" }, - "name": "f" - } + "identifierName": "f" + }, + "name": "f" + } + } + }, + { + "type": "MatchCase", + "start": 109, + "end": 130, + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 23 } }, - { - "type": "MatchCase", - "start": 109, - "end": 130, + "test": { + "type": "Identifier", + "start": 111, + "end": 112, "loc": { "start": { "line": 8, - "column": 2 + "column": 4 }, "end": { "line": 8, - "column": 23 - } + "column": 5 + }, + "identifierName": "g" }, - "test": { - "type": "Identifier", - "start": 111, - "end": 112, - "loc": { - "start": { - "line": 8, - "column": 4 - }, - "end": { - "line": 8, - "column": 5 - }, - "identifierName": "g" + "name": "g" + }, + "binding": { + "type": "ArrayPattern", + "start": 118, + "end": 127, + "loc": { + "start": { + "line": 8, + "column": 11 }, - "name": "g" + "end": { + "line": 8, + "column": 20 + } }, - "binding": { - "type": "ArrayPattern", - "start": 118, - "end": 127, - "loc": { - "start": { - "line": 8, - "column": 11 + "elements": [ + { + "type": "AssignmentPattern", + "start": 120, + "end": 125, + "loc": { + "start": { + "line": 8, + "column": 13 + }, + "end": { + "line": 8, + "column": 18 + } }, - "end": { - "line": 8, - "column": 20 - } - }, - "elements": [ - { - "type": "AssignmentPattern", + "left": { + "type": "Identifier", "start": 120, - "end": 125, + "end": 121, "loc": { "start": { "line": 8, "column": 13 }, + "end": { + "line": 8, + "column": 14 + }, + "identifierName": "g" + }, + "name": "g" + }, + "right": { + "type": "NumericLiteral", + "start": 124, + "end": 125, + "loc": { + "start": { + "line": 8, + "column": 17 + }, "end": { "line": 8, "column": 18 } }, - "left": { - "type": "Identifier", - "start": 120, - "end": 121, - "loc": { - "start": { - "line": 8, - "column": 13 - }, - "end": { - "line": 8, - "column": 14 - }, - "identifierName": "g" - }, - "name": "g" + "extra": { + "rawValue": 1, + "raw": "1" }, - "right": { - "type": "NumericLiteral", - "start": 124, - "end": 125, - "loc": { - "start": { - "line": 8, - "column": 17 - }, - "end": { - "line": 8, - "column": 18 - } - }, - "extra": { - "rawValue": 1, - "raw": "1" - }, - "value": 1 - } + "value": 1 } - ] + } + ] + }, + "consequent": { + "type": "ExpressionStatement", + "start": 129, + "end": 130, + "loc": { + "start": { + "line": 8, + "column": 22 + }, + "end": { + "line": 8, + "column": 23 + } }, - "consequent": { - "type": "ExpressionStatement", + "expression": { + "type": "Identifier", "start": 129, "end": 130, "loc": { @@ -803,29 +803,14 @@ "end": { "line": 8, "column": 23 - } - }, - "expression": { - "type": "Identifier", - "start": 129, - "end": 130, - "loc": { - "start": { - "line": 8, - "column": 22 - }, - "end": { - "line": 8, - "column": 23 - }, - "identifierName": "g" }, - "name": "g" - } + "identifierName": "g" + }, + "name": "g" } } - ] - } + } + ] } ], "directives": [] diff --git a/test/fixtures/lightscript/match/binary-both-subscripts/expected.json b/test/fixtures/lightscript/match/binary-both-subscripts/expected.json index 129c0e2054..eeff4263d5 100644 --- a/test/fixtures/lightscript/match/binary-both-subscripts/expected.json +++ b/test/fixtures/lightscript/match/binary-both-subscripts/expected.json @@ -29,7 +29,7 @@ "sourceType": "script", "body": [ { - "type": "ExpressionStatement", + "type": "MatchStatement", "start": 0, "end": 35, "loc": { @@ -42,56 +42,56 @@ "column": 26 } }, - "expression": { - "type": "MatchExpression", - "start": 0, - "end": 35, + "discriminant": { + "type": "Identifier", + "start": 6, + "end": 7, "loc": { "start": { "line": 1, - "column": 0 + "column": 6 }, "end": { - "line": 2, - "column": 26 - } + "line": 1, + "column": 7 + }, + "identifierName": "x" }, - "discriminant": { - "type": "Identifier", - "start": 6, - "end": 7, + "name": "x" + }, + "cases": [ + { + "type": "MatchCase", + "start": 11, + "end": 35, "loc": { "start": { - "line": 1, - "column": 6 + "line": 2, + "column": 2 }, "end": { - "line": 1, - "column": 7 - }, - "identifierName": "x" + "line": 2, + "column": 26 + } }, - "name": "x" - }, - "cases": [ - { - "type": "MatchCase", - "start": 11, - "end": 35, + "test": { + "type": "BinaryExpression", + "start": 13, + "end": 20, "loc": { "start": { "line": 2, - "column": 2 + "column": 4 }, "end": { "line": 2, - "column": 26 + "column": 11 } }, - "test": { - "type": "BinaryExpression", + "left": { + "type": "MemberExpression", "start": 13, - "end": 20, + "end": 15, "loc": { "start": { "line": 2, @@ -99,109 +99,109 @@ }, "end": { "line": 2, - "column": 11 + "column": 6 } }, - "left": { - "type": "MemberExpression", - "start": 13, - "end": 15, + "object": { + "type": "PlaceholderExpression", + "start": 12, + "end": 13, "loc": { "start": { + "line": 2, + "column": 3 + }, + "end": { "line": 2, "column": 4 + } + } + }, + "property": { + "type": "Identifier", + "start": 14, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 5 }, "end": { "line": 2, "column": 6 - } + }, + "identifierName": "a" }, - "object": { - "type": "PlaceholderExpression", - "start": 12, - "end": 13, - "loc": { - "start": { - "line": 2, - "column": 3 - }, - "end": { - "line": 2, - "column": 4 - } - } + "name": "a" + }, + "computed": false + }, + "operator": "+", + "right": { + "type": "MemberExpression", + "start": 18, + "end": 20, + "loc": { + "start": { + "line": 2, + "column": 9 }, - "property": { - "type": "Identifier", - "start": 14, - "end": 15, - "loc": { - "start": { - "line": 2, - "column": 5 - }, - "end": { - "line": 2, - "column": 6 - }, - "identifierName": "a" + "end": { + "line": 2, + "column": 11 + } + }, + "object": { + "type": "PlaceholderExpression", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 8 }, - "name": "a" - }, - "computed": false + "end": { + "line": 2, + "column": 9 + } + } }, - "operator": "+", - "right": { - "type": "MemberExpression", - "start": 18, + "property": { + "type": "Identifier", + "start": 19, "end": 20, "loc": { "start": { "line": 2, - "column": 9 + "column": 10 }, "end": { "line": 2, "column": 11 - } - }, - "object": { - "type": "PlaceholderExpression", - "start": 17, - "end": 18, - "loc": { - "start": { - "line": 2, - "column": 8 - }, - "end": { - "line": 2, - "column": 9 - } - } - }, - "property": { - "type": "Identifier", - "start": 19, - "end": 20, - "loc": { - "start": { - "line": 2, - "column": 10 - }, - "end": { - "line": 2, - "column": 11 - }, - "identifierName": "b" }, - "name": "b" + "identifierName": "b" }, - "computed": false + "name": "b" + }, + "computed": false + } + }, + "consequent": { + "type": "ExpressionStatement", + "start": 22, + "end": 35, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 26 } }, - "consequent": { - "type": "ExpressionStatement", + "expression": { + "type": "StringLiteral", "start": 22, "end": 35, "loc": { @@ -214,30 +214,15 @@ "column": 26 } }, - "expression": { - "type": "StringLiteral", - "start": 22, - "end": 35, - "loc": { - "start": { - "line": 2, - "column": 13 - }, - "end": { - "line": 2, - "column": 26 - } - }, - "extra": { - "rawValue": "has a and b", - "raw": "'has a and b'" - }, - "value": "has a and b" - } + "extra": { + "rawValue": "has a and b", + "raw": "'has a and b'" + }, + "value": "has a and b" } } - ] - } + } + ] } ], "directives": [] diff --git a/test/fixtures/lightscript/match/binary/expected.json b/test/fixtures/lightscript/match/binary/expected.json index 071eac56e1..eb3700d5ce 100644 --- a/test/fixtures/lightscript/match/binary/expected.json +++ b/test/fixtures/lightscript/match/binary/expected.json @@ -29,7 +29,7 @@ "sourceType": "script", "body": [ { - "type": "ExpressionStatement", + "type": "MatchStatement", "start": 0, "end": 265, "loc": { @@ -42,105 +42,105 @@ "column": 40 } }, - "expression": { - "type": "MatchExpression", - "start": 0, - "end": 265, + "discriminant": { + "type": "Identifier", + "start": 6, + "end": 7, "loc": { "start": { "line": 1, - "column": 0 + "column": 6 }, "end": { - "line": 8, - "column": 40 - } + "line": 1, + "column": 7 + }, + "identifierName": "x" }, - "discriminant": { - "type": "Identifier", - "start": 6, - "end": 7, + "name": "x" + }, + "cases": [ + { + "type": "MatchCase", + "start": 11, + "end": 35, "loc": { "start": { - "line": 1, - "column": 6 + "line": 2, + "column": 2 }, "end": { - "line": 1, - "column": 7 - }, - "identifierName": "x" + "line": 2, + "column": 26 + } }, - "name": "x" - }, - "cases": [ - { - "type": "MatchCase", - "start": 11, - "end": 35, + "test": { + "type": "BinaryExpression", + "start": 13, + "end": 16, "loc": { "start": { "line": 2, - "column": 2 + "column": 4 }, "end": { "line": 2, - "column": 26 + "column": 7 } }, - "test": { - "type": "BinaryExpression", - "start": 13, - "end": 16, + "left": { + "type": "PlaceholderExpression", + "start": 12, + "end": 13, "loc": { "start": { + "line": 2, + "column": 3 + }, + "end": { "line": 2, "column": 4 + } + } + }, + "operator": ">", + "right": { + "type": "NumericLiteral", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 6 }, "end": { "line": 2, "column": 7 } }, - "left": { - "type": "PlaceholderExpression", - "start": 12, - "end": 13, - "loc": { - "start": { - "line": 2, - "column": 3 - }, - "end": { - "line": 2, - "column": 4 - } - } + "extra": { + "rawValue": 2, + "raw": "2" }, - "operator": ">", - "right": { - "type": "NumericLiteral", - "start": 15, - "end": 16, - "loc": { - "start": { - "line": 2, - "column": 6 - }, - "end": { - "line": 2, - "column": 7 - } - }, - "extra": { - "rawValue": 2, - "raw": "2" - }, - "value": 2 + "value": 2 + } + }, + "consequent": { + "type": "ExpressionStatement", + "start": 18, + "end": 35, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 26 } }, - "consequent": { - "type": "ExpressionStatement", + "expression": { + "type": "StringLiteral", "start": 18, "end": 35, "loc": { @@ -153,46 +153,46 @@ "column": 26 } }, - "expression": { - "type": "StringLiteral", - "start": 18, - "end": 35, - "loc": { - "start": { - "line": 2, - "column": 9 - }, - "end": { - "line": 2, - "column": 26 - } - }, - "extra": { - "rawValue": "bigger than two", - "raw": "\"bigger than two\"" - }, - "value": "bigger than two" - } + "extra": { + "rawValue": "bigger than two", + "raw": "\"bigger than two\"" + }, + "value": "bigger than two" + } + } + }, + { + "type": "MatchCase", + "start": 38, + "end": 62, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 26 } }, - { - "type": "MatchCase", - "start": 38, - "end": 62, + "test": { + "type": "LogicalExpression", + "start": 40, + "end": 51, "loc": { "start": { "line": 3, - "column": 2 + "column": 4 }, "end": { "line": 3, - "column": 26 + "column": 15 } }, - "test": { - "type": "LogicalExpression", + "left": { + "type": "BinaryExpression", "start": 40, - "end": 51, + "end": 43, "loc": { "start": { "line": 3, @@ -200,167 +200,167 @@ }, "end": { "line": 3, - "column": 15 + "column": 7 } }, "left": { - "type": "BinaryExpression", - "start": 40, - "end": 43, + "type": "PlaceholderExpression", + "start": 39, + "end": 40, "loc": { "start": { "line": 3, - "column": 4 + "column": 3 }, "end": { "line": 3, - "column": 7 - } - }, - "left": { - "type": "PlaceholderExpression", - "start": 39, - "end": 40, - "loc": { - "start": { - "line": 3, - "column": 3 - }, - "end": { - "line": 3, - "column": 4 - } + "column": 4 } - }, - "operator": ">", - "right": { - "type": "NumericLiteral", - "start": 42, - "end": 43, - "loc": { - "start": { - "line": 3, - "column": 6 - }, - "end": { - "line": 3, - "column": 7 - } - }, - "extra": { - "rawValue": 3, - "raw": "3" - }, - "value": 3 } }, - "operator": "&&", + "operator": ">", "right": { - "type": "BinaryExpression", - "start": 48, - "end": 51, + "type": "NumericLiteral", + "start": 42, + "end": 43, "loc": { "start": { "line": 3, - "column": 12 + "column": 6 }, "end": { "line": 3, - "column": 15 + "column": 7 } }, - "left": { - "type": "PlaceholderExpression", - "start": 47, - "end": 48, - "loc": { - "start": { - "line": 3, - "column": 11 - }, - "end": { - "line": 3, - "column": 12 - } - } + "extra": { + "rawValue": 3, + "raw": "3" }, - "operator": ">", - "right": { - "type": "NumericLiteral", - "start": 50, - "end": 51, - "loc": { - "start": { - "line": 3, - "column": 14 - }, - "end": { - "line": 3, - "column": 15 - } - }, - "extra": { - "rawValue": 2, - "raw": "2" - }, - "value": 2 - } + "value": 3 } }, - "consequent": { - "type": "ExpressionStatement", - "start": 53, - "end": 62, + "operator": "&&", + "right": { + "type": "BinaryExpression", + "start": 48, + "end": 51, "loc": { "start": { "line": 3, - "column": 17 + "column": 12 }, "end": { "line": 3, - "column": 26 + "column": 15 } }, - "expression": { - "type": "StringLiteral", - "start": 53, - "end": 62, + "left": { + "type": "PlaceholderExpression", + "start": 47, + "end": 48, "loc": { "start": { "line": 3, - "column": 17 + "column": 11 }, "end": { "line": 3, - "column": 26 + "column": 12 + } + } + }, + "operator": ">", + "right": { + "type": "NumericLiteral", + "start": 50, + "end": 51, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 } }, "extra": { - "rawValue": "so cool", - "raw": "\"so cool\"" + "rawValue": 2, + "raw": "2" }, - "value": "so cool" + "value": 2 } } }, - { - "type": "MatchCase", - "start": 65, - "end": 91, + "consequent": { + "type": "ExpressionStatement", + "start": 53, + "end": 62, + "loc": { + "start": { + "line": 3, + "column": 17 + }, + "end": { + "line": 3, + "column": 26 + } + }, + "expression": { + "type": "StringLiteral", + "start": 53, + "end": 62, + "loc": { + "start": { + "line": 3, + "column": 17 + }, + "end": { + "line": 3, + "column": 26 + } + }, + "extra": { + "rawValue": "so cool", + "raw": "\"so cool\"" + }, + "value": "so cool" + } + } + }, + { + "type": "MatchCase", + "start": 65, + "end": 91, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 28 + } + }, + "test": { + "type": "BinaryExpression", + "start": 67, + "end": 75, "loc": { "start": { "line": 4, - "column": 2 + "column": 4 }, "end": { "line": 4, - "column": 28 + "column": 12 } }, - "test": { + "left": { "type": "BinaryExpression", "start": 67, - "end": 75, + "end": 70, "loc": { "start": { "line": 4, @@ -368,84 +368,84 @@ }, "end": { "line": 4, - "column": 12 + "column": 7 } }, "left": { - "type": "BinaryExpression", - "start": 67, - "end": 70, + "type": "PlaceholderExpression", + "start": 66, + "end": 67, "loc": { "start": { "line": 4, - "column": 4 + "column": 3 }, "end": { "line": 4, - "column": 7 - } - }, - "left": { - "type": "PlaceholderExpression", - "start": 66, - "end": 67, - "loc": { - "start": { - "line": 4, - "column": 3 - }, - "end": { - "line": 4, - "column": 4 - } + "column": 4 } - }, - "operator": "+", - "right": { - "type": "NumericLiteral", - "start": 69, - "end": 70, - "loc": { - "start": { - "line": 4, - "column": 6 - }, - "end": { - "line": 4, - "column": 7 - } - }, - "extra": { - "rawValue": 3, - "raw": "3" - }, - "value": 3 } }, - "operator": "===", + "operator": "+", "right": { "type": "NumericLiteral", - "start": 74, - "end": 75, + "start": 69, + "end": 70, "loc": { "start": { "line": 4, - "column": 11 + "column": 6 }, "end": { "line": 4, - "column": 12 + "column": 7 } }, "extra": { - "rawValue": 4, - "raw": "4" + "rawValue": 3, + "raw": "3" }, - "value": 4 + "value": 3 } }, - "consequent": { - "type": "ExpressionStatement", + "operator": "===", + "right": { + "type": "NumericLiteral", + "start": 74, + "end": 75, + "loc": { + "start": { + "line": 4, + "column": 11 + }, + "end": { + "line": 4, + "column": 12 + } + }, + "extra": { + "rawValue": 4, + "raw": "4" + }, + "value": 4 + } + }, + "consequent": { + "type": "ExpressionStatement", + "start": 77, + "end": 91, + "loc": { + "start": { + "line": 4, + "column": 14 + }, + "end": { + "line": 4, + "column": 28 + } + }, + "expression": { + "type": "StringLiteral", "start": 77, "end": 91, "loc": { @@ -458,46 +458,46 @@ "column": 28 } }, - "expression": { - "type": "StringLiteral", - "start": 77, - "end": 91, - "loc": { - "start": { - "line": 4, - "column": 14 - }, - "end": { - "line": 4, - "column": 28 - } - }, - "extra": { - "rawValue": "its one shhh", - "raw": "\"its one shhh\"" - }, - "value": "its one shhh" - } + "extra": { + "rawValue": "its one shhh", + "raw": "\"its one shhh\"" + }, + "value": "its one shhh" + } + } + }, + { + "type": "MatchCase", + "start": 94, + "end": 136, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 44 } }, - { - "type": "MatchCase", - "start": 94, - "end": 136, + "test": { + "type": "LogicalExpression", + "start": 96, + "end": 104, "loc": { "start": { "line": 5, - "column": 2 + "column": 4 }, "end": { "line": 5, - "column": 44 + "column": 12 } }, - "test": { - "type": "LogicalExpression", + "left": { + "type": "UnaryExpression", "start": 96, - "end": 104, + "end": 98, "loc": { "start": { "line": 5, @@ -505,93 +505,93 @@ }, "end": { "line": 5, - "column": 12 + "column": 6 } }, - "left": { - "type": "UnaryExpression", - "start": 96, + "operator": "+", + "prefix": true, + "argument": { + "type": "NumericLiteral", + "start": 97, "end": 98, "loc": { "start": { "line": 5, - "column": 4 + "column": 5 }, "end": { "line": 5, "column": 6 } }, - "operator": "+", - "prefix": true, - "argument": { - "type": "NumericLiteral", - "start": 97, - "end": 98, - "loc": { - "start": { - "line": 5, - "column": 5 - }, - "end": { - "line": 5, - "column": 6 - } - }, - "extra": { - "rawValue": 1, - "raw": "1" - }, - "value": 1 - }, "extra": { - "parenthesizedArgument": false + "rawValue": 1, + "raw": "1" + }, + "value": 1 + }, + "extra": { + "parenthesizedArgument": false + } + }, + "operator": "||", + "right": { + "type": "UnaryExpression", + "start": 102, + "end": 104, + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 12 } }, - "operator": "||", - "right": { - "type": "UnaryExpression", - "start": 102, + "operator": "-", + "prefix": true, + "argument": { + "type": "NumericLiteral", + "start": 103, "end": 104, "loc": { "start": { "line": 5, - "column": 10 + "column": 11 }, "end": { "line": 5, "column": 12 } }, - "operator": "-", - "prefix": true, - "argument": { - "type": "NumericLiteral", - "start": 103, - "end": 104, - "loc": { - "start": { - "line": 5, - "column": 11 - }, - "end": { - "line": 5, - "column": 12 - } - }, - "extra": { - "rawValue": 1, - "raw": "1" - }, - "value": 1 - }, "extra": { - "parenthesizedArgument": false - } + "rawValue": 1, + "raw": "1" + }, + "value": 1 + }, + "extra": { + "parenthesizedArgument": false + } + } + }, + "consequent": { + "type": "ExpressionStatement", + "start": 106, + "end": 136, + "loc": { + "start": { + "line": 5, + "column": 14 + }, + "end": { + "line": 5, + "column": 44 } }, - "consequent": { - "type": "ExpressionStatement", + "expression": { + "type": "StringLiteral", "start": 106, "end": 136, "loc": { @@ -603,47 +603,47 @@ "line": 5, "column": 44 } - }, - "expression": { - "type": "StringLiteral", - "start": 106, - "end": 136, - "loc": { - "start": { - "line": 5, - "column": 14 - }, - "end": { - "line": 5, - "column": 44 - } - }, - "extra": { - "rawValue": "equal to one or negative one", - "raw": "\"equal to one or negative one\"" - }, - "value": "equal to one or negative one" - } + }, + "extra": { + "rawValue": "equal to one or negative one", + "raw": "\"equal to one or negative one\"" + }, + "value": "equal to one or negative one" + } + } + }, + { + "type": "MatchCase", + "start": 139, + "end": 181, + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 44 } }, - { - "type": "MatchCase", - "start": 139, - "end": 181, + "test": { + "type": "LogicalExpression", + "start": 141, + "end": 149, "loc": { "start": { "line": 6, - "column": 2 + "column": 4 }, "end": { "line": 6, - "column": 44 + "column": 12 } }, - "test": { - "type": "LogicalExpression", + "left": { + "type": "UnaryExpression", "start": 141, - "end": 149, + "end": 143, "loc": { "start": { "line": 6, @@ -651,93 +651,93 @@ }, "end": { "line": 6, - "column": 12 + "column": 6 } }, - "left": { - "type": "UnaryExpression", - "start": 141, + "operator": "-", + "prefix": true, + "argument": { + "type": "NumericLiteral", + "start": 142, "end": 143, "loc": { "start": { "line": 6, - "column": 4 + "column": 5 }, "end": { "line": 6, "column": 6 } }, - "operator": "-", - "prefix": true, - "argument": { - "type": "NumericLiteral", - "start": 142, - "end": 143, - "loc": { - "start": { - "line": 6, - "column": 5 - }, - "end": { - "line": 6, - "column": 6 - } - }, - "extra": { - "rawValue": 1, - "raw": "1" - }, - "value": 1 - }, "extra": { - "parenthesizedArgument": false + "rawValue": 1, + "raw": "1" + }, + "value": 1 + }, + "extra": { + "parenthesizedArgument": false + } + }, + "operator": "||", + "right": { + "type": "UnaryExpression", + "start": 147, + "end": 149, + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 12 } }, - "operator": "||", - "right": { - "type": "UnaryExpression", - "start": 147, + "operator": "+", + "prefix": true, + "argument": { + "type": "NumericLiteral", + "start": 148, "end": 149, "loc": { "start": { "line": 6, - "column": 10 + "column": 11 }, "end": { "line": 6, "column": 12 } }, - "operator": "+", - "prefix": true, - "argument": { - "type": "NumericLiteral", - "start": 148, - "end": 149, - "loc": { - "start": { - "line": 6, - "column": 11 - }, - "end": { - "line": 6, - "column": 12 - } - }, - "extra": { - "rawValue": 1, - "raw": "1" - }, - "value": 1 - }, "extra": { - "parenthesizedArgument": false - } + "rawValue": 1, + "raw": "1" + }, + "value": 1 + }, + "extra": { + "parenthesizedArgument": false + } + } + }, + "consequent": { + "type": "ExpressionStatement", + "start": 151, + "end": 181, + "loc": { + "start": { + "line": 6, + "column": 14 + }, + "end": { + "line": 6, + "column": 44 } }, - "consequent": { - "type": "ExpressionStatement", + "expression": { + "type": "StringLiteral", "start": 151, "end": 181, "loc": { @@ -750,92 +750,92 @@ "column": 44 } }, - "expression": { - "type": "StringLiteral", - "start": 151, - "end": 181, - "loc": { - "start": { - "line": 6, - "column": 14 - }, - "end": { - "line": 6, - "column": 44 - } - }, - "extra": { - "rawValue": "equal to one or negative one", - "raw": "\"equal to one or negative one\"" - }, - "value": "equal to one or negative one" - } + "extra": { + "rawValue": "equal to one or negative one", + "raw": "\"equal to one or negative one\"" + }, + "value": "equal to one or negative one" + } + } + }, + { + "type": "MatchCase", + "start": 184, + "end": 224, + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 42 } }, - { - "type": "MatchCase", - "start": 184, - "end": 224, + "test": { + "type": "BinaryExpression", + "start": 186, + "end": 202, "loc": { "start": { "line": 7, - "column": 2 + "column": 4 }, "end": { "line": 7, - "column": 42 + "column": 20 } }, - "test": { - "type": "BinaryExpression", - "start": 186, - "end": 202, + "left": { + "type": "PlaceholderExpression", + "start": 185, + "end": 186, "loc": { "start": { + "line": 7, + "column": 3 + }, + "end": { "line": 7, "column": 4 + } + } + }, + "operator": "instanceof", + "right": { + "type": "Identifier", + "start": 197, + "end": 202, + "loc": { + "start": { + "line": 7, + "column": 15 }, "end": { "line": 7, "column": 20 - } + }, + "identifierName": "Class" }, - "left": { - "type": "PlaceholderExpression", - "start": 185, - "end": 186, - "loc": { - "start": { - "line": 7, - "column": 3 - }, - "end": { - "line": 7, - "column": 4 - } - } + "name": "Class" + } + }, + "consequent": { + "type": "ExpressionStatement", + "start": 204, + "end": 224, + "loc": { + "start": { + "line": 7, + "column": 22 }, - "operator": "instanceof", - "right": { - "type": "Identifier", - "start": 197, - "end": 202, - "loc": { - "start": { - "line": 7, - "column": 15 - }, - "end": { - "line": 7, - "column": 20 - }, - "identifierName": "Class" - }, - "name": "Class" + "end": { + "line": 7, + "column": 42 } }, - "consequent": { - "type": "ExpressionStatement", + "expression": { + "type": "StringLiteral", "start": 204, "end": 224, "loc": { @@ -848,46 +848,46 @@ "column": 42 } }, - "expression": { - "type": "StringLiteral", - "start": 204, - "end": 224, - "loc": { - "start": { - "line": 7, - "column": 22 - }, - "end": { - "line": 7, - "column": 42 - } - }, - "extra": { - "rawValue": "its a Class thing!", - "raw": "\"its a Class thing!\"" - }, - "value": "its a Class thing!" - } + "extra": { + "rawValue": "its a Class thing!", + "raw": "\"its a Class thing!\"" + }, + "value": "its a Class thing!" + } + } + }, + { + "type": "MatchCase", + "start": 227, + "end": 265, + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 40 } }, - { - "type": "MatchCase", - "start": 227, - "end": 265, + "test": { + "type": "BinaryExpression", + "start": 229, + "end": 252, "loc": { "start": { "line": 8, - "column": 2 + "column": 4 }, "end": { "line": 8, - "column": 40 + "column": 27 } }, - "test": { + "left": { "type": "BinaryExpression", "start": 229, - "end": 252, + "end": 233, "loc": { "start": { "line": 8, @@ -895,51 +895,105 @@ }, "end": { "line": 8, - "column": 27 + "column": 8 } }, "left": { - "type": "BinaryExpression", - "start": 229, - "end": 233, + "type": "PlaceholderExpression", + "start": 228, + "end": 229, "loc": { "start": { + "line": 8, + "column": 3 + }, + "end": { "line": 8, "column": 4 + } + } + }, + "operator": "**", + "right": { + "type": "NumericLiteral", + "start": 232, + "end": 233, + "loc": { + "start": { + "line": 8, + "column": 7 }, "end": { "line": 8, "column": 8 } }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + }, + "operator": "===", + "right": { + "type": "BinaryExpression", + "start": 237, + "end": 252, + "loc": { + "start": { + "line": 8, + "column": 12 + }, + "end": { + "line": 8, + "column": 27 + } + }, + "left": { + "type": "BinaryExpression", + "start": 237, + "end": 243, + "loc": { + "start": { + "line": 8, + "column": 12 + }, + "end": { + "line": 8, + "column": 18 + } + }, "left": { - "type": "PlaceholderExpression", - "start": 228, - "end": 229, + "type": "Identifier", + "start": 237, + "end": 238, "loc": { "start": { "line": 8, - "column": 3 + "column": 12 }, "end": { "line": 8, - "column": 4 - } - } + "column": 13 + }, + "identifierName": "b" + }, + "name": "b" }, "operator": "**", "right": { "type": "NumericLiteral", - "start": 232, - "end": 233, + "start": 242, + "end": 243, "loc": { "start": { "line": 8, - "column": 7 + "column": 17 }, "end": { "line": 8, - "column": 8 + "column": 18 } }, "extra": { @@ -949,15 +1003,15 @@ "value": 2 } }, - "operator": "===", + "operator": "+", "right": { "type": "BinaryExpression", - "start": 237, + "start": 246, "end": 252, "loc": { "start": { "line": 8, - "column": 12 + "column": 21 }, "end": { "line": 8, @@ -965,116 +1019,62 @@ } }, "left": { - "type": "BinaryExpression", - "start": 237, - "end": 243, + "type": "Identifier", + "start": 246, + "end": 247, "loc": { "start": { "line": 8, - "column": 12 + "column": 21 }, "end": { "line": 8, - "column": 18 - } - }, - "left": { - "type": "Identifier", - "start": 237, - "end": 238, - "loc": { - "start": { - "line": 8, - "column": 12 - }, - "end": { - "line": 8, - "column": 13 - }, - "identifierName": "b" + "column": 22 }, - "name": "b" + "identifierName": "c" }, - "operator": "**", - "right": { - "type": "NumericLiteral", - "start": 242, - "end": 243, - "loc": { - "start": { - "line": 8, - "column": 17 - }, - "end": { - "line": 8, - "column": 18 - } - }, - "extra": { - "rawValue": 2, - "raw": "2" - }, - "value": 2 - } + "name": "c" }, - "operator": "+", + "operator": "**", "right": { - "type": "BinaryExpression", - "start": 246, + "type": "NumericLiteral", + "start": 251, "end": 252, "loc": { "start": { "line": 8, - "column": 21 + "column": 26 }, "end": { "line": 8, "column": 27 } }, - "left": { - "type": "Identifier", - "start": 246, - "end": 247, - "loc": { - "start": { - "line": 8, - "column": 21 - }, - "end": { - "line": 8, - "column": 22 - }, - "identifierName": "c" - }, - "name": "c" + "extra": { + "rawValue": 2, + "raw": "2" }, - "operator": "**", - "right": { - "type": "NumericLiteral", - "start": 251, - "end": 252, - "loc": { - "start": { - "line": 8, - "column": 26 - }, - "end": { - "line": 8, - "column": 27 - } - }, - "extra": { - "rawValue": 2, - "raw": "2" - }, - "value": 2 - } + "value": 2 } } + } + }, + "consequent": { + "type": "ExpressionStatement", + "start": 254, + "end": 265, + "loc": { + "start": { + "line": 8, + "column": 29 + }, + "end": { + "line": 8, + "column": 40 + } }, - "consequent": { - "type": "ExpressionStatement", + "expression": { + "type": "StringLiteral", "start": 254, "end": 265, "loc": { @@ -1087,30 +1087,15 @@ "column": 40 } }, - "expression": { - "type": "StringLiteral", - "start": 254, - "end": 265, - "loc": { - "start": { - "line": 8, - "column": 29 - }, - "end": { - "line": 8, - "column": 40 - } - }, - "extra": { - "rawValue": "triangle?", - "raw": "\"triangle?\"" - }, - "value": "triangle?" - } + "extra": { + "rawValue": "triangle?", + "raw": "\"triangle?\"" + }, + "value": "triangle?" } } - ] - } + } + ] } ], "directives": [] 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..fdd561e298 --- /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..d25a2b7d98 --- /dev/null +++ b/test/fixtures/lightscript/match/curly-consequent/expected.json @@ -0,0 +1,520 @@ +{ + "type": "File", + "start": 0, + "end": 97, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 12, + "column": 3 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 97, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 12, + "column": 3 + } + }, + "sourceType": "script", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 97, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 12, + "column": 3 + } + }, + "kind": "const", + "extra": { + "implicit": true + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 0, + "end": 97, + "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": 97, + "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": 77, + "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": "Identifier", + "start": 58, + "end": 59, + "loc": { + "start": { + "line": 6, + "column": 11 + }, + "end": { + "line": 6, + "column": 12 + }, + "identifierName": "b" + }, + "name": "b" + }, + "consequent": { + "type": "BlockStatement", + "start": 60, + "end": 77, + "loc": { + "start": { + "line": 6, + "column": 13 + }, + "end": { + "line": 9, + "column": 3 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 66, + "end": 67, + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 5 + } + }, + "expression": { + "type": "Identifier", + "start": 66, + "end": 67, + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 5 + }, + "identifierName": "b" + }, + "name": "b" + } + }, + { + "type": "ExpressionStatement", + "start": 72, + "end": 73, + "loc": { + "start": { + "line": 8, + "column": 4 + }, + "end": { + "line": 8, + "column": 5 + } + }, + "expression": { + "type": "Identifier", + "start": 72, + "end": 73, + "loc": { + "start": { + "line": 8, + "column": 4 + }, + "end": { + "line": 8, + "column": 5 + }, + "identifierName": "b" + }, + "name": "b" + } + } + ], + "directives": [], + "extra": { + "curly": true + } + } + }, + { + "type": "MatchCase", + "start": 80, + "end": 97, + "loc": { + "start": { + "line": 10, + "column": 2 + }, + "end": { + "line": 12, + "column": 3 + } + }, + "test": { + "type": "Identifier", + "start": 83, + "end": 84, + "loc": { + "start": { + "line": 10, + "column": 5 + }, + "end": { + "line": 10, + "column": 6 + }, + "identifierName": "c" + }, + "name": "c", + "extra": { + "parenthesized": true, + "parenStart": 82 + } + }, + "consequent": { + "type": "BlockStatement", + "start": 86, + "end": 97, + "loc": { + "start": { + "line": 10, + "column": 8 + }, + "end": { + "line": 12, + "column": 3 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 92, + "end": 93, + "loc": { + "start": { + "line": 11, + "column": 4 + }, + "end": { + "line": 11, + "column": 5 + } + }, + "expression": { + "type": "Identifier", + "start": 92, + "end": 93, + "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/else-solo/expected.json b/test/fixtures/lightscript/match/else-solo/expected.json index 11c3c0b573..486d864b11 100644 --- a/test/fixtures/lightscript/match/else-solo/expected.json +++ b/test/fixtures/lightscript/match/else-solo/expected.json @@ -29,7 +29,7 @@ "sourceType": "script", "body": [ { - "type": "ExpressionStatement", + "type": "MatchStatement", "start": 0, "end": 37, "loc": { @@ -42,69 +42,69 @@ "column": 28 } }, - "expression": { - "type": "MatchExpression", - "start": 0, - "end": 37, + "discriminant": { + "type": "Identifier", + "start": 6, + "end": 7, "loc": { "start": { "line": 1, - "column": 0 + "column": 6 }, "end": { - "line": 2, - "column": 28 - } + "line": 1, + "column": 7 + }, + "identifierName": "x" }, - "discriminant": { - "type": "Identifier", - "start": 6, - "end": 7, + "name": "x" + }, + "cases": [ + { + "type": "MatchCase", + "start": 11, + "end": 37, "loc": { "start": { - "line": 1, - "column": 6 + "line": 2, + "column": 2 }, "end": { - "line": 1, - "column": 7 - }, - "identifierName": "x" + "line": 2, + "column": 28 + } }, - "name": "x" - }, - "cases": [ - { - "type": "MatchCase", - "start": 11, + "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": 2 + "column": 10 }, "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", + "expression": { + "type": "StringLiteral", "start": 19, "end": 37, "loc": { @@ -117,30 +117,15 @@ "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" - } + "extra": { + "rawValue": "some other thing", + "raw": "\"some other thing\"" + }, + "value": "some other thing" } } - ] - } + } + ] } ], "directives": [] diff --git a/test/fixtures/lightscript/match/else/expected.json b/test/fixtures/lightscript/match/else/expected.json index e5ce0fb43b..2afdb8cf87 100644 --- a/test/fixtures/lightscript/match/else/expected.json +++ b/test/fixtures/lightscript/match/else/expected.json @@ -29,7 +29,7 @@ "sourceType": "script", "body": [ { - "type": "ExpressionStatement", + "type": "MatchStatement", "start": 0, "end": 29, "loc": { @@ -42,71 +42,71 @@ "column": 11 } }, - "expression": { - "type": "MatchExpression", - "start": 0, - "end": 29, + "discriminant": { + "type": "Identifier", + "start": 6, + "end": 7, "loc": { "start": { "line": 1, - "column": 0 + "column": 6 }, "end": { - "line": 3, - "column": 11 - } + "line": 1, + "column": 7 + }, + "identifierName": "x" }, - "discriminant": { - "type": "Identifier", - "start": 6, - "end": 7, + "name": "x" + }, + "cases": [ + { + "type": "MatchCase", + "start": 11, + "end": 17, "loc": { "start": { - "line": 1, - "column": 6 + "line": 2, + "column": 2 }, "end": { - "line": 1, - "column": 7 + "line": 2, + "column": 8 + } + }, + "test": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + }, + "identifierName": "a" }, - "identifierName": "x" + "name": "a" }, - "name": "x" - }, - "cases": [ - { - "type": "MatchCase", - "start": 11, + "consequent": { + "type": "ExpressionStatement", + "start": 16, "end": 17, "loc": { "start": { "line": 2, - "column": 2 + "column": 7 }, "end": { "line": 2, "column": 8 } }, - "test": { + "expression": { "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": { @@ -117,58 +117,58 @@ "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" + "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 } } }, - { - "type": "MatchCase", - "start": 20, + "consequent": { + "type": "ExpressionStatement", + "start": 28, "end": 29, "loc": { "start": { "line": 3, - "column": 2 + "column": 10 }, "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", + "expression": { + "type": "Identifier", "start": 28, "end": 29, "loc": { @@ -179,29 +179,14 @@ "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" - } + "identifierName": "c" + }, + "name": "c" } } - ] - } + } + ] } ], "directives": [] 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/jsx-result/expected.json b/test/fixtures/lightscript/match/jsx-result/expected.json index 6f9b2b4b82..f0e7cd06a5 100644 --- a/test/fixtures/lightscript/match/jsx-result/expected.json +++ b/test/fixtures/lightscript/match/jsx-result/expected.json @@ -29,7 +29,7 @@ "sourceType": "script", "body": [ { - "type": "ExpressionStatement", + "type": "MatchStatement", "start": 0, "end": 23, "loc": { @@ -42,71 +42,71 @@ "column": 14 } }, - "expression": { - "type": "MatchExpression", - "start": 0, - "end": 23, + "discriminant": { + "type": "Identifier", + "start": 6, + "end": 7, "loc": { "start": { "line": 1, - "column": 0 + "column": 6 }, "end": { - "line": 2, - "column": 14 - } + "line": 1, + "column": 7 + }, + "identifierName": "x" }, - "discriminant": { - "type": "Identifier", - "start": 6, - "end": 7, + "name": "x" + }, + "cases": [ + { + "type": "MatchCase", + "start": 11, + "end": 23, "loc": { "start": { - "line": 1, - "column": 6 + "line": 2, + "column": 2 }, "end": { - "line": 1, - "column": 7 + "line": 2, + "column": 14 + } + }, + "test": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + }, + "identifierName": "y" }, - "identifierName": "x" + "name": "y" }, - "name": "x" - }, - "cases": [ - { - "type": "MatchCase", - "start": 11, + "consequent": { + "type": "ExpressionStatement", + "start": 16, "end": 23, "loc": { "start": { "line": 2, - "column": 2 + "column": 7 }, "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", + "expression": { + "type": "JSXElement", "start": 16, "end": 23, "loc": { @@ -119,8 +119,8 @@ "column": 14 } }, - "expression": { - "type": "JSXElement", + "openingElement": { + "type": "JSXOpeningElement", "start": 16, "end": 23, "loc": { @@ -133,46 +133,31 @@ "column": 14 } }, - "openingElement": { - "type": "JSXOpeningElement", - "start": 16, - "end": 23, + "attributes": [], + "name": { + "type": "JSXIdentifier", + "start": 17, + "end": 20, "loc": { "start": { "line": 2, - "column": 7 + "column": 8 }, "end": { "line": 2, - "column": 14 + "column": 11 } }, - "attributes": [], - "name": { - "type": "JSXIdentifier", - "start": 17, - "end": 20, - "loc": { - "start": { - "line": 2, - "column": 8 - }, - "end": { - "line": 2, - "column": 11 - } - }, - "name": "div" - }, - "selfClosing": true + "name": "div" }, - "closingElement": null, - "children": [] - } + "selfClosing": true + }, + "closingElement": null, + "children": [] } } - ] - } + } + ] } ], "directives": [] diff --git a/test/fixtures/lightscript/match/less-than/expected.json b/test/fixtures/lightscript/match/less-than/expected.json index 53de30b7cd..98dc23bb80 100644 --- a/test/fixtures/lightscript/match/less-than/expected.json +++ b/test/fixtures/lightscript/match/less-than/expected.json @@ -29,7 +29,7 @@ "sourceType": "script", "body": [ { - "type": "ExpressionStatement", + "type": "MatchStatement", "start": 0, "end": 45, "loc": { @@ -42,105 +42,105 @@ "column": 17 } }, - "expression": { - "type": "MatchExpression", - "start": 0, - "end": 45, + "discriminant": { + "type": "Identifier", + "start": 6, + "end": 7, "loc": { "start": { "line": 1, - "column": 0 + "column": 6 }, "end": { - "line": 3, - "column": 17 - } + "line": 1, + "column": 7 + }, + "identifierName": "x" }, - "discriminant": { - "type": "Identifier", - "start": 6, - "end": 7, + "name": "x" + }, + "cases": [ + { + "type": "MatchCase", + "start": 11, + "end": 27, "loc": { "start": { - "line": 1, - "column": 6 + "line": 2, + "column": 2 }, "end": { - "line": 1, - "column": 7 - }, - "identifierName": "x" + "line": 2, + "column": 18 + } }, - "name": "x" - }, - "cases": [ - { - "type": "MatchCase", - "start": 11, - "end": 27, + "test": { + "type": "BinaryExpression", + "start": 13, + "end": 16, "loc": { "start": { "line": 2, - "column": 2 + "column": 4 }, "end": { "line": 2, - "column": 18 + "column": 7 } }, - "test": { - "type": "BinaryExpression", - "start": 13, - "end": 16, + "left": { + "type": "PlaceholderExpression", + "start": 12, + "end": 13, "loc": { "start": { + "line": 2, + "column": 3 + }, + "end": { "line": 2, "column": 4 + } + } + }, + "operator": "<", + "right": { + "type": "NumericLiteral", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 6 }, "end": { "line": 2, "column": 7 } }, - "left": { - "type": "PlaceholderExpression", - "start": 12, - "end": 13, - "loc": { - "start": { - "line": 2, - "column": 3 - }, - "end": { - "line": 2, - "column": 4 - } - } + "extra": { + "rawValue": 3, + "raw": "3" }, - "operator": "<", - "right": { - "type": "NumericLiteral", - "start": 15, - "end": 16, - "loc": { - "start": { - "line": 2, - "column": 6 - }, - "end": { - "line": 2, - "column": 7 - } - }, - "extra": { - "rawValue": 3, - "raw": "3" - }, - "value": 3 + "value": 3 + } + }, + "consequent": { + "type": "ExpressionStatement", + "start": 18, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 18 } }, - "consequent": { - "type": "ExpressionStatement", + "expression": { + "type": "StringLiteral", "start": 18, "end": 27, "loc": { @@ -153,95 +153,95 @@ "column": 18 } }, - "expression": { - "type": "StringLiteral", - "start": 18, - "end": 27, - "loc": { - "start": { - "line": 2, - "column": 9 - }, - "end": { - "line": 2, - "column": 18 - } - }, - "extra": { - "rawValue": "not jsx", - "raw": "\"not jsx\"" - }, - "value": "not jsx" - } + "extra": { + "rawValue": "not jsx", + "raw": "\"not jsx\"" + }, + "value": "not jsx" + } + } + }, + { + "type": "MatchCase", + "start": 30, + "end": 45, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 17 } }, - { - "type": "MatchCase", - "start": 30, - "end": 45, + "test": { + "type": "BinaryExpression", + "start": 32, + "end": 34, "loc": { "start": { "line": 3, - "column": 2 + "column": 4 }, "end": { "line": 3, - "column": 17 + "column": 6 } }, - "test": { - "type": "BinaryExpression", - "start": 32, - "end": 34, + "left": { + "type": "PlaceholderExpression", + "start": 31, + "end": 32, "loc": { "start": { + "line": 3, + "column": 3 + }, + "end": { "line": 3, "column": 4 + } + } + }, + "operator": "<", + "right": { + "type": "NumericLiteral", + "start": 33, + "end": 34, + "loc": { + "start": { + "line": 3, + "column": 5 }, "end": { "line": 3, "column": 6 } }, - "left": { - "type": "PlaceholderExpression", - "start": 31, - "end": 32, - "loc": { - "start": { - "line": 3, - "column": 3 - }, - "end": { - "line": 3, - "column": 4 - } - } + "extra": { + "rawValue": 3, + "raw": "3" }, - "operator": "<", - "right": { - "type": "NumericLiteral", - "start": 33, - "end": 34, - "loc": { - "start": { - "line": 3, - "column": 5 - }, - "end": { - "line": 3, - "column": 6 - } - }, - "extra": { - "rawValue": 3, - "raw": "3" - }, - "value": 3 + "value": 3 + } + }, + "consequent": { + "type": "ExpressionStatement", + "start": 36, + "end": 45, + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 17 } }, - "consequent": { - "type": "ExpressionStatement", + "expression": { + "type": "StringLiteral", "start": 36, "end": 45, "loc": { @@ -254,30 +254,15 @@ "column": 17 } }, - "expression": { - "type": "StringLiteral", - "start": 36, - "end": 45, - "loc": { - "start": { - "line": 3, - "column": 8 - }, - "end": { - "line": 3, - "column": 17 - } - }, - "extra": { - "rawValue": "not jsx", - "raw": "\"not jsx\"" - }, - "value": "not jsx" - } + "extra": { + "rawValue": "not jsx", + "raw": "\"not jsx\"" + }, + "value": "not jsx" } } - ] - } + } + ] } ], "directives": [] diff --git a/test/fixtures/lightscript/match/literals/expected.json b/test/fixtures/lightscript/match/literals/expected.json index bb182cea8e..0b2f2ce487 100644 --- a/test/fixtures/lightscript/match/literals/expected.json +++ b/test/fixtures/lightscript/match/literals/expected.json @@ -29,7 +29,7 @@ "sourceType": "script", "body": [ { - "type": "ExpressionStatement", + "type": "MatchStatement", "start": 0, "end": 235, "loc": { @@ -42,74 +42,74 @@ "column": 25 } }, - "expression": { - "type": "MatchExpression", - "start": 0, - "end": 235, + "discriminant": { + "type": "Identifier", + "start": 6, + "end": 7, "loc": { "start": { "line": 1, - "column": 0 + "column": 6 }, "end": { - "line": 11, - "column": 25 - } + "line": 1, + "column": 7 + }, + "identifierName": "x" }, - "discriminant": { - "type": "Identifier", - "start": 6, - "end": 7, + "name": "x" + }, + "cases": [ + { + "type": "MatchCase", + "start": 11, + "end": 21, "loc": { "start": { - "line": 1, - "column": 6 + "line": 2, + "column": 2 }, "end": { - "line": 1, - "column": 7 + "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" }, - "identifierName": "x" + "value": 2 }, - "name": "x" - }, - "cases": [ - { - "type": "MatchCase", - "start": 11, + "consequent": { + "type": "ExpressionStatement", + "start": 16, "end": 21, "loc": { "start": { "line": 2, - "column": 2 + "column": 7 }, "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", + "expression": { + "type": "StringLiteral", "start": 16, "end": 21, "loc": { @@ -122,64 +122,64 @@ "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" - } + "extra": { + "rawValue": "two", + "raw": "\"two\"" + }, + "value": "two" + } + } + }, + { + "type": "MatchCase", + "start": 24, + "end": 39, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 17 } }, - { - "type": "MatchCase", - "start": 24, + "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": 2 + "column": 13 }, "end": { "line": 3, "column": 17 } }, - "test": { + "expression": { "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": { @@ -192,64 +192,64 @@ "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" - } + "extra": { + "rawValue": "hi", + "raw": "\"hi\"" + }, + "value": "hi" + } + } + }, + { + "type": "MatchCase", + "start": 42, + "end": 57, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 17 } }, - { - "type": "MatchCase", - "start": 42, - "end": 57, + "test": { + "type": "RegExpLiteral", + "start": 44, + "end": 49, "loc": { "start": { "line": 4, - "column": 2 + "column": 4 }, "end": { "line": 4, - "column": 17 + "column": 9 } }, - "test": { - "type": "RegExpLiteral", - "start": 44, - "end": 49, - "loc": { - "start": { - "line": 4, - "column": 4 - }, - "end": { - "line": 4, - "column": 9 - } - }, - "extra": { - "raw": "/\\w+/" + "extra": { + "raw": "/\\w+/" + }, + "pattern": "\\w+", + "flags": "" + }, + "consequent": { + "type": "ExpressionStatement", + "start": 51, + "end": 57, + "loc": { + "start": { + "line": 4, + "column": 11 }, - "pattern": "\\w+", - "flags": "" + "end": { + "line": 4, + "column": 17 + } }, - "consequent": { - "type": "ExpressionStatement", + "expression": { + "type": "StringLiteral", "start": 51, "end": 57, "loc": { @@ -262,64 +262,64 @@ "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" - } + "extra": { + "rawValue": "word", + "raw": "\"word\"" + }, + "value": "word" + } + } + }, + { + "type": "MatchCase", + "start": 60, + "end": 77, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 19 } }, - { - "type": "MatchCase", - "start": 60, - "end": 77, + "test": { + "type": "RegExpLiteral", + "start": 62, + "end": 69, "loc": { "start": { "line": 5, - "column": 2 + "column": 4 }, "end": { "line": 5, - "column": 19 + "column": 11 } }, - "test": { - "type": "RegExpLiteral", - "start": 62, - "end": 69, - "loc": { - "start": { - "line": 5, - "column": 4 - }, - "end": { - "line": 5, - "column": 11 - } - }, - "extra": { - "raw": "/\\w+/ig" + "extra": { + "raw": "/\\w+/ig" + }, + "pattern": "\\w+", + "flags": "ig" + }, + "consequent": { + "type": "ExpressionStatement", + "start": 71, + "end": 77, + "loc": { + "start": { + "line": 5, + "column": 13 }, - "pattern": "\\w+", - "flags": "ig" + "end": { + "line": 5, + "column": 19 + } }, - "consequent": { - "type": "ExpressionStatement", + "expression": { + "type": "StringLiteral", "start": 71, "end": 77, "loc": { @@ -332,84 +332,84 @@ "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" - } + "extra": { + "rawValue": "word", + "raw": "\"word\"" + }, + "value": "word" + } + } + }, + { + "type": "MatchCase", + "start": 80, + "end": 109, + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 31 } }, - { - "type": "MatchCase", - "start": 80, - "end": 109, + "test": { + "type": "UnaryExpression", + "start": 82, + "end": 84, "loc": { "start": { "line": 6, - "column": 2 + "column": 4 }, "end": { "line": 6, - "column": 31 + "column": 6 } }, - "test": { - "type": "UnaryExpression", - "start": 82, + "operator": "+", + "prefix": true, + "argument": { + "type": "NumericLiteral", + "start": 83, "end": 84, "loc": { "start": { "line": 6, - "column": 4 + "column": 5 }, "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 + "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 } }, - "consequent": { - "type": "ExpressionStatement", + "expression": { + "type": "StringLiteral", "start": 86, "end": 109, "loc": { @@ -422,84 +422,84 @@ "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" - } + "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 } }, - { - "type": "MatchCase", - "start": 112, - "end": 141, + "test": { + "type": "UnaryExpression", + "start": 114, + "end": 116, "loc": { "start": { "line": 7, - "column": 2 + "column": 4 }, "end": { "line": 7, - "column": 31 + "column": 6 } }, - "test": { - "type": "UnaryExpression", - "start": 114, + "operator": "-", + "prefix": true, + "argument": { + "type": "NumericLiteral", + "start": 115, "end": 116, "loc": { "start": { "line": 7, - "column": 4 + "column": 5 }, "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 + "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 } }, - "consequent": { - "type": "ExpressionStatement", + "expression": { + "type": "StringLiteral", "start": 118, "end": 141, "loc": { @@ -512,59 +512,59 @@ "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" + "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 } } }, - { - "type": "MatchCase", - "start": 144, + "consequent": { + "type": "ExpressionStatement", + "start": 152, "end": 158, "loc": { "start": { "line": 8, - "column": 2 + "column": 10 }, "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", + "expression": { + "type": "StringLiteral", "start": 152, "end": 158, "loc": { @@ -577,61 +577,61 @@ "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" - } + "extra": { + "rawValue": "null", + "raw": "\"null\"" + }, + "value": "null" + } + } + }, + { + "type": "MatchCase", + "start": 161, + "end": 185, + "loc": { + "start": { + "line": 9, + "column": 2 + }, + "end": { + "line": 9, + "column": 26 } }, - { - "type": "MatchCase", - "start": 161, + "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": 2 + "column": 15 }, "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", + "expression": { + "type": "StringLiteral", "start": 174, "end": 185, "loc": { @@ -644,60 +644,60 @@ "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" - } + "extra": { + "rawValue": "undefined", + "raw": "\"undefined\"" + }, + "value": "undefined" + } + } + }, + { + "type": "MatchCase", + "start": 188, + "end": 209, + "loc": { + "start": { + "line": 10, + "column": 2 + }, + "end": { + "line": 10, + "column": 23 } }, - { - "type": "MatchCase", - "start": 188, - "end": 209, + "test": { + "type": "BooleanLiteral", + "start": 190, + "end": 194, "loc": { "start": { "line": 10, - "column": 2 + "column": 4 }, "end": { "line": 10, - "column": 23 + "column": 8 } }, - "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 }, - "value": true + "end": { + "line": 10, + "column": 23 + } }, - "consequent": { - "type": "ExpressionStatement", + "expression": { + "type": "StringLiteral", "start": 196, "end": 209, "loc": { @@ -710,60 +710,60 @@ "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" - } + "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 } }, - { - "type": "MatchCase", - "start": 212, - "end": 235, + "test": { + "type": "BooleanLiteral", + "start": 214, + "end": 219, "loc": { "start": { "line": 11, - "column": 2 + "column": 4 }, "end": { "line": 11, - "column": 25 + "column": 9 } }, - "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 }, - "value": false + "end": { + "line": 11, + "column": 25 + } }, - "consequent": { - "type": "ExpressionStatement", + "expression": { + "type": "StringLiteral", "start": 221, "end": 235, "loc": { @@ -776,30 +776,15 @@ "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" - } + "extra": { + "rawValue": "strict false", + "raw": "\"strict false\"" + }, + "value": "strict false" } } - ] - } + } + ] } ], "directives": [] diff --git a/test/fixtures/lightscript/match/multi-subscripts-number/expected.json b/test/fixtures/lightscript/match/multi-subscripts-number/expected.json index 7496f03c92..aa3b1ef5eb 100644 --- a/test/fixtures/lightscript/match/multi-subscripts-number/expected.json +++ b/test/fixtures/lightscript/match/multi-subscripts-number/expected.json @@ -29,7 +29,7 @@ "sourceType": "script", "body": [ { - "type": "ExpressionStatement", + "type": "MatchStatement", "start": 0, "end": 86, "loc": { @@ -42,56 +42,56 @@ "column": 38 } }, - "expression": { - "type": "MatchExpression", - "start": 0, - "end": 86, + "discriminant": { + "type": "Identifier", + "start": 6, + "end": 7, "loc": { "start": { "line": 1, - "column": 0 + "column": 6 }, "end": { - "line": 3, - "column": 38 - } + "line": 1, + "column": 7 + }, + "identifierName": "x" }, - "discriminant": { - "type": "Identifier", - "start": 6, - "end": 7, + "name": "x" + }, + "cases": [ + { + "type": "MatchCase", + "start": 11, + "end": 47, "loc": { "start": { - "line": 1, - "column": 6 + "line": 2, + "column": 2 }, "end": { - "line": 1, - "column": 7 - }, - "identifierName": "x" + "line": 2, + "column": 38 + } }, - "name": "x" - }, - "cases": [ - { - "type": "MatchCase", - "start": 11, - "end": 47, + "test": { + "type": "LogicalExpression", + "start": 13, + "end": 22, "loc": { "start": { "line": 2, - "column": 2 + "column": 4 }, "end": { "line": 2, - "column": 38 + "column": 13 } }, - "test": { - "type": "LogicalExpression", + "left": { + "type": "MemberExpression", "start": 13, - "end": 22, + "end": 15, "loc": { "start": { "line": 2, @@ -99,112 +99,112 @@ }, "end": { "line": 2, - "column": 13 + "column": 6 } }, - "left": { - "type": "MemberExpression", - "start": 13, - "end": 15, + "object": { + "type": "PlaceholderExpression", + "start": 12, + "end": 13, "loc": { "start": { + "line": 2, + "column": 3 + }, + "end": { "line": 2, "column": 4 + } + } + }, + "property": { + "type": "Identifier", + "start": 14, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 5 }, "end": { "line": 2, "column": 6 - } + }, + "identifierName": "a" }, - "object": { - "type": "PlaceholderExpression", - "start": 12, - "end": 13, - "loc": { - "start": { - "line": 2, - "column": 3 - }, - "end": { - "line": 2, - "column": 4 - } - } + "name": "a" + }, + "computed": false + }, + "operator": "&&", + "right": { + "type": "MemberExpression", + "start": 20, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 11 }, - "property": { - "type": "Identifier", - "start": 14, - "end": 15, - "loc": { - "start": { - "line": 2, - "column": 5 - }, - "end": { - "line": 2, - "column": 6 - }, - "identifierName": "a" + "end": { + "line": 2, + "column": 13 + } + }, + "object": { + "type": "PlaceholderExpression", + "start": 19, + "end": 20, + "loc": { + "start": { + "line": 2, + "column": 10 }, - "name": "a" - }, - "computed": false + "end": { + "line": 2, + "column": 11 + } + } }, - "operator": "&&", - "right": { - "type": "MemberExpression", - "start": 20, + "property": { + "type": "NumericLiteral", + "start": 21, "end": 22, "loc": { "start": { "line": 2, - "column": 11 + "column": 12 }, "end": { "line": 2, "column": 13 } }, - "object": { - "type": "PlaceholderExpression", - "start": 19, - "end": 20, - "loc": { - "start": { - "line": 2, - "column": 10 - }, - "end": { - "line": 2, - "column": 11 - } - } - }, - "property": { - "type": "NumericLiteral", - "start": 21, - "end": 22, - "loc": { - "start": { - "line": 2, - "column": 12 - }, - "end": { - "line": 2, - "column": 13 - } - }, - "extra": { - "rawValue": 0, - "raw": "0" - }, - "value": 0 + "extra": { + "rawValue": 0, + "raw": "0" }, - "computed": true + "value": 0 + }, + "computed": true + } + }, + "consequent": { + "type": "ExpressionStatement", + "start": 24, + "end": 47, + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 38 } }, - "consequent": { - "type": "ExpressionStatement", + "expression": { + "type": "StringLiteral", "start": 24, "end": 47, "loc": { @@ -217,46 +217,46 @@ "column": 38 } }, - "expression": { - "type": "StringLiteral", - "start": 24, - "end": 47, - "loc": { - "start": { - "line": 2, - "column": 15 - }, - "end": { - "line": 2, - "column": 38 - } - }, - "extra": { - "rawValue": "has a and first child", - "raw": "'has a and first child'" - }, - "value": "has a and first child" - } + "extra": { + "rawValue": "has a and first child", + "raw": "'has a and first child'" + }, + "value": "has a and first child" + } + } + }, + { + "type": "MatchCase", + "start": 50, + "end": 86, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 38 } }, - { - "type": "MatchCase", - "start": 50, - "end": 86, + "test": { + "type": "MemberExpression", + "start": 52, + "end": 56, "loc": { "start": { "line": 3, - "column": 2 + "column": 4 }, "end": { "line": 3, - "column": 38 + "column": 8 } }, - "test": { + "object": { "type": "MemberExpression", "start": 52, - "end": 56, + "end": 54, "loc": { "start": { "line": 3, @@ -264,72 +264,36 @@ }, "end": { "line": 3, - "column": 8 + "column": 6 } }, "object": { - "type": "MemberExpression", - "start": 52, - "end": 54, + "type": "PlaceholderExpression", + "start": 51, + "end": 52, "loc": { "start": { "line": 3, - "column": 4 + "column": 3 }, "end": { "line": 3, - "column": 6 - } - }, - "object": { - "type": "PlaceholderExpression", - "start": 51, - "end": 52, - "loc": { - "start": { - "line": 3, - "column": 3 - }, - "end": { - "line": 3, - "column": 4 - } + "column": 4 } - }, - "property": { - "type": "NumericLiteral", - "start": 53, - "end": 54, - "loc": { - "start": { - "line": 3, - "column": 5 - }, - "end": { - "line": 3, - "column": 6 - } - }, - "extra": { - "rawValue": 0, - "raw": "0" - }, - "value": 0 - }, - "computed": true + } }, "property": { "type": "NumericLiteral", - "start": 55, - "end": 56, + "start": 53, + "end": 54, "loc": { "start": { "line": 3, - "column": 7 + "column": 5 }, "end": { "line": 3, - "column": 8 + "column": 6 } }, "extra": { @@ -340,8 +304,44 @@ }, "computed": true }, - "consequent": { - "type": "ExpressionStatement", + "property": { + "type": "NumericLiteral", + "start": 55, + "end": 56, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + }, + "computed": true + }, + "consequent": { + "type": "ExpressionStatement", + "start": 58, + "end": 86, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 38 + } + }, + "expression": { + "type": "StringLiteral", "start": 58, "end": 86, "loc": { @@ -354,30 +354,15 @@ "column": 38 } }, - "expression": { - "type": "StringLiteral", - "start": 58, - "end": 86, - "loc": { - "start": { - "line": 3, - "column": 10 - }, - "end": { - "line": 3, - "column": 38 - } - }, - "extra": { - "rawValue": "first child of first child", - "raw": "'first child of first child'" - }, - "value": "first child of first child" - } + "extra": { + "rawValue": "first child of first child", + "raw": "'first child of first child'" + }, + "value": "first child of first child" } } - ] - } + } + ] } ], "directives": [] diff --git a/test/fixtures/lightscript/match/multi-subscripts/expected.json b/test/fixtures/lightscript/match/multi-subscripts/expected.json index 518d4f15e6..25980932df 100644 --- a/test/fixtures/lightscript/match/multi-subscripts/expected.json +++ b/test/fixtures/lightscript/match/multi-subscripts/expected.json @@ -29,7 +29,7 @@ "sourceType": "script", "body": [ { - "type": "ExpressionStatement", + "type": "MatchStatement", "start": 0, "end": 72, "loc": { @@ -42,56 +42,56 @@ "column": 30 } }, - "expression": { - "type": "MatchExpression", - "start": 0, - "end": 72, + "discriminant": { + "type": "Identifier", + "start": 6, + "end": 7, "loc": { "start": { "line": 1, - "column": 0 + "column": 6 }, "end": { - "line": 3, - "column": 30 - } + "line": 1, + "column": 7 + }, + "identifierName": "x" }, - "discriminant": { - "type": "Identifier", - "start": 6, - "end": 7, + "name": "x" + }, + "cases": [ + { + "type": "MatchCase", + "start": 11, + "end": 41, "loc": { "start": { - "line": 1, - "column": 6 + "line": 2, + "column": 2 }, "end": { - "line": 1, - "column": 7 - }, - "identifierName": "x" + "line": 2, + "column": 32 + } }, - "name": "x" - }, - "cases": [ - { - "type": "MatchCase", - "start": 11, - "end": 41, + "test": { + "type": "LogicalExpression", + "start": 13, + "end": 24, "loc": { "start": { "line": 2, - "column": 2 + "column": 4 }, "end": { "line": 2, - "column": 32 + "column": 15 } }, - "test": { - "type": "LogicalExpression", + "left": { + "type": "MemberExpression", "start": 13, - "end": 24, + "end": 15, "loc": { "start": { "line": 2, @@ -99,142 +99,142 @@ }, "end": { "line": 2, - "column": 15 + "column": 6 } }, - "left": { - "type": "MemberExpression", - "start": 13, - "end": 15, + "object": { + "type": "PlaceholderExpression", + "start": 12, + "end": 13, "loc": { "start": { + "line": 2, + "column": 3 + }, + "end": { "line": 2, "column": 4 + } + } + }, + "property": { + "type": "Identifier", + "start": 14, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 5 }, "end": { "line": 2, "column": 6 + }, + "identifierName": "a" + }, + "name": "a" + }, + "computed": false + }, + "operator": "&&", + "right": { + "type": "MemberExpression", + "start": 20, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "object": { + "type": "MemberExpression", + "start": 20, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 13 } }, "object": { "type": "PlaceholderExpression", - "start": 12, - "end": 13, + "start": 19, + "end": 20, "loc": { "start": { "line": 2, - "column": 3 + "column": 10 }, "end": { "line": 2, - "column": 4 + "column": 11 } } }, "property": { "type": "Identifier", - "start": 14, - "end": 15, + "start": 21, + "end": 22, "loc": { "start": { "line": 2, - "column": 5 + "column": 12 }, "end": { "line": 2, - "column": 6 + "column": 13 }, - "identifierName": "a" + "identifierName": "b" }, - "name": "a" + "name": "b" }, "computed": false }, - "operator": "&&", - "right": { - "type": "MemberExpression", - "start": 20, + "property": { + "type": "Identifier", + "start": 23, "end": 24, "loc": { "start": { "line": 2, - "column": 11 + "column": 14 }, "end": { "line": 2, "column": 15 - } - }, - "object": { - "type": "MemberExpression", - "start": 20, - "end": 22, - "loc": { - "start": { - "line": 2, - "column": 11 - }, - "end": { - "line": 2, - "column": 13 - } - }, - "object": { - "type": "PlaceholderExpression", - "start": 19, - "end": 20, - "loc": { - "start": { - "line": 2, - "column": 10 - }, - "end": { - "line": 2, - "column": 11 - } - } - }, - "property": { - "type": "Identifier", - "start": 21, - "end": 22, - "loc": { - "start": { - "line": 2, - "column": 12 - }, - "end": { - "line": 2, - "column": 13 - }, - "identifierName": "b" - }, - "name": "b" }, - "computed": false + "identifierName": "c" }, - "property": { - "type": "Identifier", - "start": 23, - "end": 24, - "loc": { - "start": { - "line": 2, - "column": 14 - }, - "end": { - "line": 2, - "column": 15 - }, - "identifierName": "c" - }, - "name": "c" - }, - "computed": false + "name": "c" + }, + "computed": false + } + }, + "consequent": { + "type": "ExpressionStatement", + "start": 26, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 32 } }, - "consequent": { - "type": "ExpressionStatement", + "expression": { + "type": "StringLiteral", "start": 26, "end": 41, "loc": { @@ -247,46 +247,46 @@ "column": 32 } }, - "expression": { - "type": "StringLiteral", - "start": 26, - "end": 41, - "loc": { - "start": { - "line": 2, - "column": 17 - }, - "end": { - "line": 2, - "column": 32 - } - }, - "extra": { - "rawValue": "has a and b.c", - "raw": "'has a and b.c'" - }, - "value": "has a and b.c" - } + "extra": { + "rawValue": "has a and b.c", + "raw": "'has a and b.c'" + }, + "value": "has a and b.c" + } + } + }, + { + "type": "MatchCase", + "start": 44, + "end": 72, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 30 } }, - { - "type": "MatchCase", - "start": 44, - "end": 72, + "test": { + "type": "LogicalExpression", + "start": 46, + "end": 58, "loc": { "start": { "line": 3, - "column": 2 + "column": 4 }, "end": { "line": 3, - "column": 30 + "column": 16 } }, - "test": { - "type": "LogicalExpression", + "left": { + "type": "TildeCallExpression", "start": 46, - "end": 58, + "end": 50, "loc": { "start": { "line": 3, @@ -294,145 +294,130 @@ }, "end": { "line": 3, - "column": 16 + "column": 8 } }, "left": { - "type": "TildeCallExpression", - "start": 46, - "end": 50, + "type": "PlaceholderExpression", + "start": 45, + "end": 46, "loc": { "start": { "line": 3, - "column": 4 + "column": 3 }, "end": { "line": 3, - "column": 8 - } - }, - "left": { - "type": "PlaceholderExpression", - "start": 45, - "end": 46, - "loc": { - "start": { - "line": 3, - "column": 3 - }, - "end": { - "line": 3, - "column": 4 - } + "column": 4 } - }, - "right": { - "type": "Identifier", - "start": 47, - "end": 48, - "loc": { - "start": { - "line": 3, - "column": 5 - }, - "end": { - "line": 3, - "column": 6 - }, - "identifierName": "c" - }, - "name": "c" - }, - "arguments": [] + } }, - "operator": "||", "right": { - "type": "TildeCallExpression", - "start": 54, - "end": 58, + "type": "Identifier", + "start": 47, + "end": 48, "loc": { "start": { "line": 3, - "column": 12 + "column": 5 }, "end": { "line": 3, - "column": 16 - } - }, - "left": { - "type": "PlaceholderExpression", - "start": 53, - "end": 54, - "loc": { - "start": { - "line": 3, - "column": 11 - }, - "end": { - "line": 3, - "column": 12 - } - } - }, - "right": { - "type": "Identifier", - "start": 55, - "end": 56, - "loc": { - "start": { - "line": 3, - "column": 13 - }, - "end": { - "line": 3, - "column": 14 - }, - "identifierName": "d" + "column": 6 }, - "name": "d" + "identifierName": "c" }, - "arguments": [] - } + "name": "c" + }, + "arguments": [] }, - "consequent": { - "type": "ExpressionStatement", - "start": 60, - "end": 72, + "operator": "||", + "right": { + "type": "TildeCallExpression", + "start": 54, + "end": 58, "loc": { "start": { "line": 3, - "column": 18 + "column": 12 }, "end": { "line": 3, - "column": 30 + "column": 16 } }, - "expression": { - "type": "StringLiteral", - "start": 60, - "end": 72, + "left": { + "type": "PlaceholderExpression", + "start": 53, + "end": 54, "loc": { "start": { "line": 3, - "column": 18 + "column": 11 }, "end": { "line": 3, - "column": 30 + "column": 12 } + } + }, + "right": { + "type": "Identifier", + "start": 55, + "end": 56, + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 14 + }, + "identifierName": "d" }, - "extra": { - "rawValue": "its a func", - "raw": "'its a func'" - }, - "value": "its a func" + "name": "d" + }, + "arguments": [] + } + }, + "consequent": { + "type": "ExpressionStatement", + "start": 60, + "end": 72, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 30 } + }, + "expression": { + "type": "StringLiteral", + "start": 60, + "end": 72, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 30 + } + }, + "extra": { + "rawValue": "its a func", + "raw": "'its a func'" + }, + "value": "its a func" } } - ] - } + } + ] } ], "directives": [] diff --git a/test/fixtures/lightscript/match/nested/expected.json b/test/fixtures/lightscript/match/nested/expected.json index d28049b71f..75d517152a 100644 --- a/test/fixtures/lightscript/match/nested/expected.json +++ b/test/fixtures/lightscript/match/nested/expected.json @@ -29,7 +29,7 @@ "sourceType": "script", "body": [ { - "type": "ExpressionStatement", + "type": "MatchStatement", "start": 0, "end": 138, "loc": { @@ -42,468 +42,453 @@ "column": 28 } }, - "expression": { - "type": "MatchExpression", - "start": 0, - "end": 138, + "discriminant": { + "type": "Identifier", + "start": 6, + "end": 7, "loc": { "start": { "line": 1, - "column": 0 + "column": 6 }, "end": { - "line": 6, - "column": 28 - } + "line": 1, + "column": 7 + }, + "identifierName": "x" }, - "discriminant": { - "type": "Identifier", - "start": 6, - "end": 7, + "name": "x" + }, + "cases": [ + { + "type": "MatchCase", + "start": 11, + "end": 109, "loc": { "start": { - "line": 1, - "column": 6 + "line": 2, + "column": 2 }, "end": { - "line": 1, - "column": 7 - }, - "identifierName": "x" + "line": 5, + "column": 23 + } }, - "name": "x" - }, - "cases": [ - { - "type": "MatchCase", - "start": 11, - "end": 109, + "test": { + "type": "BinaryExpression", + "start": 13, + "end": 16, "loc": { "start": { "line": 2, - "column": 2 + "column": 4 }, "end": { - "line": 5, - "column": 23 + "line": 2, + "column": 7 } }, - "test": { - "type": "BinaryExpression", - "start": 13, - "end": 16, + "left": { + "type": "PlaceholderExpression", + "start": 12, + "end": 13, "loc": { "start": { + "line": 2, + "column": 3 + }, + "end": { "line": 2, "column": 4 + } + } + }, + "operator": ">", + "right": { + "type": "NumericLiteral", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 6 }, "end": { "line": 2, "column": 7 } }, - "left": { - "type": "PlaceholderExpression", - "start": 12, - "end": 13, - "loc": { - "start": { - "line": 2, - "column": 3 - }, - "end": { - "line": 2, - "column": 4 - } - } + "extra": { + "rawValue": 2, + "raw": "2" }, - "operator": ">", - "right": { - "type": "NumericLiteral", - "start": 15, - "end": 16, - "loc": { - "start": { - "line": 2, - "column": 6 - }, - "end": { - "line": 2, - "column": 7 - } - }, - "extra": { - "rawValue": 2, - "raw": "2" - }, - "value": 2 + "value": 2 + } + }, + "binding": { + "type": "Identifier", + "start": 22, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 14 + }, + "identifierName": "y" + }, + "name": "y" + }, + "consequent": { + "type": "MatchStatement", + "start": 25, + "end": 109, + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 5, + "column": 23 } }, - "binding": { + "discriminant": { "type": "Identifier", - "start": 22, - "end": 23, + "start": 31, + "end": 32, "loc": { "start": { "line": 2, - "column": 13 + "column": 22 }, "end": { "line": 2, - "column": 14 + "column": 23 }, "identifierName": "y" }, "name": "y" }, - "consequent": { - "type": "ExpressionStatement", - "start": 25, - "end": 109, - "loc": { - "start": { - "line": 2, - "column": 16 - }, - "end": { - "line": 5, - "column": 23 - } - }, - "expression": { - "type": "MatchExpression", - "start": 25, - "end": 109, + "cases": [ + { + "type": "MatchCase", + "start": 38, + "end": 55, "loc": { "start": { - "line": 2, - "column": 16 + "line": 3, + "column": 4 }, "end": { - "line": 5, - "column": 23 + "line": 3, + "column": 21 } }, - "discriminant": { - "type": "Identifier", - "start": 31, - "end": 32, + "test": { + "type": "BinaryExpression", + "start": 40, + "end": 44, "loc": { "start": { - "line": 2, - "column": 22 + "line": 3, + "column": 6 }, "end": { - "line": 2, - "column": 23 - }, - "identifierName": "y" + "line": 3, + "column": 10 + } }, - "name": "y" + "left": { + "type": "PlaceholderExpression", + "start": 39, + "end": 40, + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 6 + } + } + }, + "operator": ">", + "right": { + "type": "NumericLiteral", + "start": 42, + "end": 44, + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "extra": { + "rawValue": 10, + "raw": "10" + }, + "value": 10 + } }, - "cases": [ - { - "type": "MatchCase", - "start": 38, + "consequent": { + "type": "ExpressionStatement", + "start": 46, + "end": 55, + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 21 + } + }, + "expression": { + "type": "StringLiteral", + "start": 46, "end": 55, "loc": { "start": { "line": 3, - "column": 4 + "column": 12 }, "end": { "line": 3, "column": 21 } }, - "test": { - "type": "BinaryExpression", - "start": 40, - "end": 44, - "loc": { - "start": { - "line": 3, - "column": 6 - }, - "end": { - "line": 3, - "column": 10 - } - }, - "left": { - "type": "PlaceholderExpression", - "start": 39, - "end": 40, - "loc": { - "start": { - "line": 3, - "column": 5 - }, - "end": { - "line": 3, - "column": 6 - } - } + "extra": { + "rawValue": "soo big", + "raw": "\"soo big\"" + }, + "value": "soo big" + } + } + }, + { + "type": "MatchCase", + "start": 60, + "end": 85, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 29 + } + }, + "test": { + "type": "BinaryExpression", + "start": 62, + "end": 65, + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 9 + } + }, + "left": { + "type": "PlaceholderExpression", + "start": 61, + "end": 62, + "loc": { + "start": { + "line": 4, + "column": 5 }, - "operator": ">", - "right": { - "type": "NumericLiteral", - "start": 42, - "end": 44, - "loc": { - "start": { - "line": 3, - "column": 8 - }, - "end": { - "line": 3, - "column": 10 - } - }, - "extra": { - "rawValue": 10, - "raw": "10" - }, - "value": 10 + "end": { + "line": 4, + "column": 6 } - }, - "consequent": { - "type": "ExpressionStatement", - "start": 46, - "end": 55, - "loc": { - "start": { - "line": 3, - "column": 12 - }, - "end": { - "line": 3, - "column": 21 - } + } + }, + "operator": ">", + "right": { + "type": "NumericLiteral", + "start": 64, + "end": 65, + "loc": { + "start": { + "line": 4, + "column": 8 }, - "expression": { - "type": "StringLiteral", - "start": 46, - "end": 55, - "loc": { - "start": { - "line": 3, - "column": 12 - }, - "end": { - "line": 3, - "column": 21 - } - }, - "extra": { - "rawValue": "soo big", - "raw": "\"soo big\"" - }, - "value": "soo big" + "end": { + "line": 4, + "column": 9 } + }, + "extra": { + "rawValue": 5, + "raw": "5" + }, + "value": 5 + } + }, + "consequent": { + "type": "ExpressionStatement", + "start": 67, + "end": 85, + "loc": { + "start": { + "line": 4, + "column": 11 + }, + "end": { + "line": 4, + "column": 29 } }, - { - "type": "MatchCase", - "start": 60, + "expression": { + "type": "StringLiteral", + "start": 67, "end": 85, "loc": { "start": { "line": 4, - "column": 4 + "column": 11 }, "end": { "line": 4, "column": 29 } }, - "test": { - "type": "BinaryExpression", - "start": 62, - "end": 65, - "loc": { - "start": { - "line": 4, - "column": 6 - }, - "end": { - "line": 4, - "column": 9 - } - }, - "left": { - "type": "PlaceholderExpression", - "start": 61, - "end": 62, - "loc": { - "start": { - "line": 4, - "column": 5 - }, - "end": { - "line": 4, - "column": 6 - } - } - }, - "operator": ">", - "right": { - "type": "NumericLiteral", - "start": 64, - "end": 65, - "loc": { - "start": { - "line": 4, - "column": 8 - }, - "end": { - "line": 4, - "column": 9 - } - }, - "extra": { - "rawValue": 5, - "raw": "5" - }, - "value": 5 - } + "extra": { + "rawValue": "still pretty big", + "raw": "\"still pretty big\"" }, - "consequent": { - "type": "ExpressionStatement", - "start": 67, - "end": 85, - "loc": { - "start": { - "line": 4, - "column": 11 - }, - "end": { - "line": 4, - "column": 29 - } - }, - "expression": { - "type": "StringLiteral", - "start": 67, - "end": 85, - "loc": { - "start": { - "line": 4, - "column": 11 - }, - "end": { - "line": 4, - "column": 29 - } - }, - "extra": { - "rawValue": "still pretty big", - "raw": "\"still pretty big\"" - }, - "value": "still pretty big" - } + "value": "still pretty big" + } + } + }, + { + "type": "MatchCase", + "start": 90, + "end": 109, + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 23 + } + }, + "test": { + "type": "MatchElse", + "start": 92, + "end": 96, + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 5, + "column": 10 + } + } + }, + "consequent": { + "type": "ExpressionStatement", + "start": 98, + "end": 109, + "loc": { + "start": { + "line": 5, + "column": 12 + }, + "end": { + "line": 5, + "column": 23 } }, - { - "type": "MatchCase", - "start": 90, + "expression": { + "type": "StringLiteral", + "start": 98, "end": 109, "loc": { "start": { "line": 5, - "column": 4 + "column": 12 }, "end": { "line": 5, "column": 23 } }, - "test": { - "type": "MatchElse", - "start": 92, - "end": 96, - "loc": { - "start": { - "line": 5, - "column": 6 - }, - "end": { - "line": 5, - "column": 10 - } - } + "extra": { + "rawValue": "kinda big", + "raw": "\"kinda big\"" }, - "consequent": { - "type": "ExpressionStatement", - "start": 98, - "end": 109, - "loc": { - "start": { - "line": 5, - "column": 12 - }, - "end": { - "line": 5, - "column": 23 - } - }, - "expression": { - "type": "StringLiteral", - "start": 98, - "end": 109, - "loc": { - "start": { - "line": 5, - "column": 12 - }, - "end": { - "line": 5, - "column": 23 - } - }, - "extra": { - "rawValue": "kinda big", - "raw": "\"kinda big\"" - }, - "value": "kinda big" - } - } + "value": "kinda big" } - ] + } } + ] + } + }, + { + "type": "MatchCase", + "start": 112, + "end": 138, + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 28 } }, - { - "type": "MatchCase", - "start": 112, + "test": { + "type": "MatchElse", + "start": 114, + "end": 118, + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 8 + } + } + }, + "consequent": { + "type": "ExpressionStatement", + "start": 120, "end": 138, "loc": { "start": { "line": 6, - "column": 2 + "column": 10 }, "end": { "line": 6, "column": 28 } }, - "test": { - "type": "MatchElse", - "start": 114, - "end": 118, - "loc": { - "start": { - "line": 6, - "column": 4 - }, - "end": { - "line": 6, - "column": 8 - } - } - }, - "consequent": { - "type": "ExpressionStatement", + "expression": { + "type": "StringLiteral", "start": 120, "end": 138, "loc": { @@ -516,30 +501,15 @@ "column": 28 } }, - "expression": { - "type": "StringLiteral", - "start": 120, - "end": 138, - "loc": { - "start": { - "line": 6, - "column": 10 - }, - "end": { - "line": 6, - "column": 28 - } - }, - "extra": { - "rawValue": "some other thing", - "raw": "\"some other thing\"" - }, - "value": "some other thing" - } + "extra": { + "rawValue": "some other thing", + "raw": "\"some other thing\"" + }, + "value": "some other thing" } } - ] - } + } + ] } ], "directives": [] 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/parenthesized-destructuring-illegal/actual.js b/test/fixtures/lightscript/match/parenthesized-destructuring-illegal/actual.js new file mode 100644 index 0000000000..c9be8589a1 --- /dev/null +++ b/test/fixtures/lightscript/match/parenthesized-destructuring-illegal/actual.js @@ -0,0 +1,4 @@ +a = match x: + | 3 with (three): three + | 4 with ({ four = 4 }): four + | 5 with ({ five = 5 }): five 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/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/subscript-in-tilde/expected.json b/test/fixtures/lightscript/match/subscript-in-tilde/expected.json index a6217fde94..fe3e2ae318 100644 --- a/test/fixtures/lightscript/match/subscript-in-tilde/expected.json +++ b/test/fixtures/lightscript/match/subscript-in-tilde/expected.json @@ -29,7 +29,7 @@ "sourceType": "script", "body": [ { - "type": "ExpressionStatement", + "type": "MatchStatement", "start": 0, "end": 33, "loc": { @@ -42,103 +42,103 @@ "column": 24 } }, - "expression": { - "type": "MatchExpression", - "start": 0, - "end": 33, + "discriminant": { + "type": "Identifier", + "start": 6, + "end": 7, "loc": { "start": { "line": 1, - "column": 0 + "column": 6 }, "end": { - "line": 2, - "column": 24 - } + "line": 1, + "column": 7 + }, + "identifierName": "x" }, - "discriminant": { - "type": "Identifier", - "start": 6, - "end": 7, + "name": "x" + }, + "cases": [ + { + "type": "MatchCase", + "start": 11, + "end": 33, "loc": { "start": { - "line": 1, - "column": 6 + "line": 2, + "column": 2 }, "end": { - "line": 1, - "column": 7 - }, - "identifierName": "x" + "line": 2, + "column": 24 + } }, - "name": "x" - }, - "cases": [ - { - "type": "MatchCase", - "start": 11, - "end": 33, + "test": { + "type": "TildeCallExpression", + "start": 13, + "end": 19, "loc": { "start": { "line": 2, - "column": 2 + "column": 4 }, "end": { "line": 2, - "column": 24 + "column": 10 } }, - "test": { - "type": "TildeCallExpression", - "start": 13, - "end": 19, + "left": { + "type": "PlaceholderExpression", + "start": 12, + "end": 13, "loc": { "start": { "line": 2, - "column": 4 + "column": 3 }, "end": { "line": 2, - "column": 10 + "column": 4 } + } + }, + "right": { + "type": "Identifier", + "start": 14, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 6 + }, + "identifierName": "c" }, - "left": { - "type": "PlaceholderExpression", - "start": 12, - "end": 13, + "name": "c" + }, + "arguments": [ + { + "type": "MemberExpression", + "start": 16, + "end": 18, "loc": { "start": { "line": 2, - "column": 3 + "column": 7 }, "end": { "line": 2, - "column": 4 + "column": 9 } - } - }, - "right": { - "type": "Identifier", - "start": 14, - "end": 15, - "loc": { - "start": { - "line": 2, - "column": 5 - }, - "end": { - "line": 2, - "column": 6 - }, - "identifierName": "c" }, - "name": "c" - }, - "arguments": [ - { - "type": "MemberExpression", + "object": { + "type": "PlaceholderExpression", "start": 16, - "end": 18, + "end": 16, "loc": { "start": { "line": 2, @@ -146,47 +146,47 @@ }, "end": { "line": 2, - "column": 9 - } - }, - "object": { - "type": "PlaceholderExpression", - "start": 16, - "end": 16, - "loc": { - "start": { - "line": 2, - "column": 7 - }, - "end": { - "line": 2, - "column": 7 - } + "column": 7 } - }, - "property": { - "type": "Identifier", - "start": 17, - "end": 18, - "loc": { - "start": { - "line": 2, - "column": 8 - }, - "end": { - "line": 2, - "column": 9 - }, - "identifierName": "d" + } + }, + "property": { + "type": "Identifier", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 9 }, - "name": "d" + "identifierName": "d" }, - "computed": false - } - ] + "name": "d" + }, + "computed": false + } + ] + }, + "consequent": { + "type": "ExpressionStatement", + "start": 21, + "end": 33, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 24 + } }, - "consequent": { - "type": "ExpressionStatement", + "expression": { + "type": "StringLiteral", "start": 21, "end": 33, "loc": { @@ -199,30 +199,15 @@ "column": 24 } }, - "expression": { - "type": "StringLiteral", - "start": 21, - "end": 33, - "loc": { - "start": { - "line": 2, - "column": 12 - }, - "end": { - "line": 2, - "column": 24 - } - }, - "extra": { - "rawValue": "its a func", - "raw": "'its a func'" - }, - "value": "its a func" - } + "extra": { + "rawValue": "its a func", + "raw": "'its a func'" + }, + "value": "its a func" } } - ] - } + } + ] } ], "directives": [] diff --git a/test/fixtures/lightscript/match/subscripts/expected.json b/test/fixtures/lightscript/match/subscripts/expected.json index 8525f8fadd..50cdba6448 100644 --- a/test/fixtures/lightscript/match/subscripts/expected.json +++ b/test/fixtures/lightscript/match/subscripts/expected.json @@ -29,7 +29,7 @@ "sourceType": "script", "body": [ { - "type": "ExpressionStatement", + "type": "MatchStatement", "start": 0, "end": 135, "loc": { @@ -42,102 +42,102 @@ "column": 31 } }, - "expression": { - "type": "MatchExpression", - "start": 0, - "end": 135, + "discriminant": { + "type": "Identifier", + "start": 6, + "end": 7, "loc": { "start": { "line": 1, - "column": 0 + "column": 6 }, "end": { - "line": 7, - "column": 31 - } + "line": 1, + "column": 7 + }, + "identifierName": "x" }, - "discriminant": { - "type": "Identifier", - "start": 6, - "end": 7, + "name": "x" + }, + "cases": [ + { + "type": "MatchCase", + "start": 11, + "end": 24, "loc": { "start": { - "line": 1, - "column": 6 + "line": 2, + "column": 2 }, "end": { - "line": 1, - "column": 7 - }, - "identifierName": "x" + "line": 2, + "column": 15 + } }, - "name": "x" - }, - "cases": [ - { - "type": "MatchCase", - "start": 11, - "end": 24, + "test": { + "type": "MemberExpression", + "start": 13, + "end": 15, "loc": { "start": { "line": 2, - "column": 2 + "column": 4 }, "end": { "line": 2, - "column": 15 + "column": 6 } }, - "test": { - "type": "MemberExpression", - "start": 13, - "end": 15, + "object": { + "type": "PlaceholderExpression", + "start": 12, + "end": 13, "loc": { "start": { + "line": 2, + "column": 3 + }, + "end": { "line": 2, "column": 4 + } + } + }, + "property": { + "type": "Identifier", + "start": 14, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 5 }, "end": { "line": 2, "column": 6 - } - }, - "object": { - "type": "PlaceholderExpression", - "start": 12, - "end": 13, - "loc": { - "start": { - "line": 2, - "column": 3 - }, - "end": { - "line": 2, - "column": 4 - } - } - }, - "property": { - "type": "Identifier", - "start": 14, - "end": 15, - "loc": { - "start": { - "line": 2, - "column": 5 - }, - "end": { - "line": 2, - "column": 6 - }, - "identifierName": "a" }, - "name": "a" + "identifierName": "a" + }, + "name": "a" + }, + "computed": false + }, + "consequent": { + "type": "ExpressionStatement", + "start": 17, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 8 }, - "computed": false + "end": { + "line": 2, + "column": 15 + } }, - "consequent": { - "type": "ExpressionStatement", + "expression": { + "type": "StringLiteral", "start": 17, "end": 24, "loc": { @@ -150,81 +150,81 @@ "column": 15 } }, - "expression": { + "extra": { + "rawValue": "has a", + "raw": "'has a'" + }, + "value": "has a" + } + } + }, + { + "type": "MatchCase", + "start": 27, + "end": 43, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 18 + } + }, + "test": { + "type": "ArrayExpression", + "start": 29, + "end": 34, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "elements": [ + { "type": "StringLiteral", - "start": 17, - "end": 24, + "start": 30, + "end": 33, "loc": { "start": { - "line": 2, - "column": 8 + "line": 3, + "column": 5 }, "end": { - "line": 2, - "column": 15 + "line": 3, + "column": 8 } }, "extra": { - "rawValue": "has a", - "raw": "'has a'" + "rawValue": "b", + "raw": "'b'" }, - "value": "has a" + "value": "b" } - } + ] }, - { - "type": "MatchCase", - "start": 27, + "consequent": { + "type": "ExpressionStatement", + "start": 36, "end": 43, "loc": { "start": { "line": 3, - "column": 2 + "column": 11 }, "end": { "line": 3, "column": 18 } }, - "test": { - "type": "ArrayExpression", - "start": 29, - "end": 34, - "loc": { - "start": { - "line": 3, - "column": 4 - }, - "end": { - "line": 3, - "column": 9 - } - }, - "elements": [ - { - "type": "StringLiteral", - "start": 30, - "end": 33, - "loc": { - "start": { - "line": 3, - "column": 5 - }, - "end": { - "line": 3, - "column": 8 - } - }, - "extra": { - "rawValue": "b", - "raw": "'b'" - }, - "value": "b" - } - ] - }, - "consequent": { - "type": "ExpressionStatement", + "expression": { + "type": "StringLiteral", "start": 36, "end": 43, "loc": { @@ -237,92 +237,92 @@ "column": 18 } }, - "expression": { - "type": "StringLiteral", - "start": 36, - "end": 43, - "loc": { - "start": { - "line": 3, - "column": 11 - }, - "end": { - "line": 3, - "column": 18 - } - }, - "extra": { - "rawValue": "has b", - "raw": "'has b'" - }, - "value": "has b" - } + "extra": { + "rawValue": "has b", + "raw": "'has b'" + }, + "value": "has b" + } + } + }, + { + "type": "MatchCase", + "start": 46, + "end": 60, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 16 } }, - { - "type": "MatchCase", - "start": 46, - "end": 60, + "test": { + "type": "SafeMemberExpression", + "start": 48, + "end": 51, "loc": { "start": { "line": 4, - "column": 2 + "column": 4 }, "end": { "line": 4, - "column": 16 + "column": 7 } }, - "test": { - "type": "SafeMemberExpression", - "start": 48, - "end": 51, + "object": { + "type": "PlaceholderExpression", + "start": 47, + "end": 48, "loc": { "start": { + "line": 4, + "column": 3 + }, + "end": { "line": 4, "column": 4 + } + } + }, + "property": { + "type": "Identifier", + "start": 50, + "end": 51, + "loc": { + "start": { + "line": 4, + "column": 6 }, "end": { "line": 4, "column": 7 - } - }, - "object": { - "type": "PlaceholderExpression", - "start": 47, - "end": 48, - "loc": { - "start": { - "line": 4, - "column": 3 - }, - "end": { - "line": 4, - "column": 4 - } - } - }, - "property": { - "type": "Identifier", - "start": 50, - "end": 51, - "loc": { - "start": { - "line": 4, - "column": 6 - }, - "end": { - "line": 4, - "column": 7 - }, - "identifierName": "c" }, - "name": "c" + "identifierName": "c" }, - "computed": false + "name": "c" }, - "consequent": { - "type": "ExpressionStatement", + "computed": false + }, + "consequent": { + "type": "ExpressionStatement", + "start": 53, + "end": 60, + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 4, + "column": 16 + } + }, + "expression": { + "type": "StringLiteral", "start": 53, "end": 60, "loc": { @@ -335,92 +335,92 @@ "column": 16 } }, - "expression": { - "type": "StringLiteral", - "start": 53, - "end": 60, - "loc": { - "start": { - "line": 4, - "column": 9 - }, - "end": { - "line": 4, - "column": 16 - } - }, - "extra": { - "rawValue": "has c", - "raw": "'has c'" - }, - "value": "has c" - } + "extra": { + "rawValue": "has c", + "raw": "'has c'" + }, + "value": "has c" + } + } + }, + { + "type": "MatchCase", + "start": 63, + "end": 78, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 17 } }, - { - "type": "MatchCase", - "start": 63, - "end": 78, + "test": { + "type": "SafeMemberExpression", + "start": 65, + "end": 69, "loc": { "start": { "line": 5, - "column": 2 + "column": 4 }, "end": { "line": 5, - "column": 17 + "column": 8 } }, - "test": { - "type": "SafeMemberExpression", - "start": 65, - "end": 69, + "object": { + "type": "PlaceholderExpression", + "start": 64, + "end": 65, "loc": { "start": { "line": 5, - "column": 4 + "column": 3 }, "end": { "line": 5, - "column": 8 - } - }, - "object": { - "type": "PlaceholderExpression", - "start": 64, - "end": 65, - "loc": { - "start": { - "line": 5, - "column": 3 - }, - "end": { - "line": 5, - "column": 4 - } + "column": 4 } - }, - "property": { - "type": "Identifier", - "start": 67, - "end": 68, - "loc": { - "start": { - "line": 5, - "column": 6 - }, - "end": { - "line": 5, - "column": 7 - }, - "identifierName": "d" + } + }, + "property": { + "type": "Identifier", + "start": 67, + "end": 68, + "loc": { + "start": { + "line": 5, + "column": 6 }, - "name": "d" + "end": { + "line": 5, + "column": 7 + }, + "identifierName": "d" + }, + "name": "d" + }, + "computed": true + }, + "consequent": { + "type": "ExpressionStatement", + "start": 71, + "end": 78, + "loc": { + "start": { + "line": 5, + "column": 10 }, - "computed": true + "end": { + "line": 5, + "column": 17 + } }, - "consequent": { - "type": "ExpressionStatement", + "expression": { + "type": "StringLiteral", "start": 71, "end": 78, "loc": { @@ -433,95 +433,95 @@ "column": 17 } }, - "expression": { - "type": "StringLiteral", - "start": 71, - "end": 78, - "loc": { - "start": { - "line": 5, - "column": 10 - }, - "end": { - "line": 5, - "column": 17 - } - }, - "extra": { - "rawValue": "has d", - "raw": "'has d'" - }, - "value": "has d" - } + "extra": { + "rawValue": "has d", + "raw": "'has d'" + }, + "value": "has d" + } + } + }, + { + "type": "MatchCase", + "start": 81, + "end": 103, + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 24 } }, - { - "type": "MatchCase", - "start": 81, - "end": 103, + "test": { + "type": "MemberExpression", + "start": 83, + "end": 85, "loc": { "start": { "line": 6, - "column": 2 + "column": 4 }, "end": { "line": 6, - "column": 24 + "column": 6 } }, - "test": { - "type": "MemberExpression", - "start": 83, - "end": 85, + "object": { + "type": "PlaceholderExpression", + "start": 82, + "end": 83, "loc": { "start": { + "line": 6, + "column": 3 + }, + "end": { "line": 6, "column": 4 + } + } + }, + "property": { + "type": "NumericLiteral", + "start": 84, + "end": 85, + "loc": { + "start": { + "line": 6, + "column": 5 }, "end": { "line": 6, "column": 6 } }, - "object": { - "type": "PlaceholderExpression", - "start": 82, - "end": 83, - "loc": { - "start": { - "line": 6, - "column": 3 - }, - "end": { - "line": 6, - "column": 4 - } - } + "extra": { + "rawValue": 0, + "raw": "0" }, - "property": { - "type": "NumericLiteral", - "start": 84, - "end": 85, - "loc": { - "start": { - "line": 6, - "column": 5 - }, - "end": { - "line": 6, - "column": 6 - } - }, - "extra": { - "rawValue": 0, - "raw": "0" - }, - "value": 0 + "value": 0 + }, + "computed": true + }, + "consequent": { + "type": "ExpressionStatement", + "start": 87, + "end": 103, + "loc": { + "start": { + "line": 6, + "column": 8 }, - "computed": true + "end": { + "line": 6, + "column": 24 + } }, - "consequent": { - "type": "ExpressionStatement", + "expression": { + "type": "StringLiteral", "start": 87, "end": 103, "loc": { @@ -534,92 +534,92 @@ "column": 24 } }, - "expression": { - "type": "StringLiteral", - "start": 87, - "end": 103, - "loc": { - "start": { - "line": 6, - "column": 8 - }, - "end": { - "line": 6, - "column": 24 - } - }, - "extra": { - "rawValue": "has first elem", - "raw": "'has first elem'" - }, - "value": "has first elem" - } + "extra": { + "rawValue": "has first elem", + "raw": "'has first elem'" + }, + "value": "has first elem" + } + } + }, + { + "type": "MatchCase", + "start": 106, + "end": 135, + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 31 } }, - { - "type": "MatchCase", - "start": 106, - "end": 135, + "test": { + "type": "TildeCallExpression", + "start": 108, + "end": 121, "loc": { "start": { "line": 7, - "column": 2 + "column": 4 }, "end": { "line": 7, - "column": 31 + "column": 17 } }, - "test": { - "type": "TildeCallExpression", - "start": 108, - "end": 121, + "left": { + "type": "PlaceholderExpression", + "start": 107, + "end": 108, "loc": { "start": { "line": 7, - "column": 4 + "column": 3 }, "end": { "line": 7, - "column": 17 - } - }, - "left": { - "type": "PlaceholderExpression", - "start": 107, - "end": 108, - "loc": { - "start": { - "line": 7, - "column": 3 - }, - "end": { - "line": 7, - "column": 4 - } + "column": 4 } - }, - "right": { - "type": "Identifier", - "start": 109, - "end": 119, - "loc": { - "start": { - "line": 7, - "column": 5 - }, - "end": { - "line": 7, - "column": 15 - }, - "identifierName": "isFunction" + } + }, + "right": { + "type": "Identifier", + "start": 109, + "end": 119, + "loc": { + "start": { + "line": 7, + "column": 5 + }, + "end": { + "line": 7, + "column": 15 }, - "name": "isFunction" + "identifierName": "isFunction" + }, + "name": "isFunction" + }, + "arguments": [] + }, + "consequent": { + "type": "ExpressionStatement", + "start": 123, + "end": 135, + "loc": { + "start": { + "line": 7, + "column": 19 }, - "arguments": [] + "end": { + "line": 7, + "column": 31 + } }, - "consequent": { - "type": "ExpressionStatement", + "expression": { + "type": "StringLiteral", "start": 123, "end": 135, "loc": { @@ -632,30 +632,15 @@ "column": 31 } }, - "expression": { - "type": "StringLiteral", - "start": 123, - "end": 135, - "loc": { - "start": { - "line": 7, - "column": 19 - }, - "end": { - "line": 7, - "column": 31 - } - }, - "extra": { - "rawValue": "its a func", - "raw": "'its a func'" - }, - "value": "its a func" - } + "extra": { + "rawValue": "its a func", + "raw": "'its a func'" + }, + "value": "its a func" } } - ] - } + } + ] } ], "directives": [] diff --git a/test/fixtures/lightscript/match/tag-literal/expected.json b/test/fixtures/lightscript/match/tag-literal/expected.json index 9f6adc3c15..7ecb00e7bc 100644 --- a/test/fixtures/lightscript/match/tag-literal/expected.json +++ b/test/fixtures/lightscript/match/tag-literal/expected.json @@ -29,7 +29,7 @@ "sourceType": "script", "body": [ { - "type": "ExpressionStatement", + "type": "MatchStatement", "start": 0, "end": 52, "loc": { @@ -42,92 +42,92 @@ "column": 25 } }, - "expression": { - "type": "MatchExpression", - "start": 0, - "end": 52, + "discriminant": { + "type": "Identifier", + "start": 6, + "end": 7, "loc": { "start": { "line": 1, - "column": 0 + "column": 6 }, "end": { - "line": 3, - "column": 25 - } + "line": 1, + "column": 7 + }, + "identifierName": "x" }, - "discriminant": { - "type": "Identifier", - "start": 6, - "end": 7, + "name": "x" + }, + "cases": [ + { + "type": "MatchCase", + "start": 11, + "end": 26, "loc": { "start": { - "line": 1, - "column": 6 + "line": 2, + "column": 2 }, "end": { - "line": 1, - "column": 7 - }, - "identifierName": "x" + "line": 2, + "column": 17 + } }, - "name": "x" - }, - "cases": [ - { - "type": "MatchCase", - "start": 11, - "end": 26, + "test": { + "type": "TemplateLiteral", + "start": 13, + "end": 16, "loc": { "start": { "line": 2, - "column": 2 + "column": 4 }, "end": { "line": 2, - "column": 17 + "column": 7 } }, - "test": { - "type": "TemplateLiteral", - "start": 13, - "end": 16, - "loc": { - "start": { - "line": 2, - "column": 4 + "expressions": [], + "quasis": [ + { + "type": "TemplateElement", + "start": 14, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 6 + } }, - "end": { - "line": 2, - "column": 7 - } + "value": { + "raw": "a", + "cooked": "a" + }, + "tail": true + } + ] + }, + "consequent": { + "type": "ExpressionStatement", + "start": 18, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 9 }, - "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 - } - ] + "end": { + "line": 2, + "column": 17 + } }, - "consequent": { - "type": "ExpressionStatement", + "expression": { + "type": "StringLiteral", "start": 18, "end": 26, "loc": { @@ -140,120 +140,120 @@ "column": 17 } }, - "expression": { - "type": "StringLiteral", - "start": 18, - "end": 26, + "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": 2, + "line": 3, "column": 9 }, "end": { - "line": 2, - "column": 17 + "line": 3, + "column": 9 } }, - "extra": { - "rawValue": "is \"a\"", - "raw": "'is \"a\"'" + "value": { + "raw": "", + "cooked": "" }, - "value": "is \"a\"" + "tail": true } - } + ] }, - { - "type": "MatchCase", - "start": 29, + "consequent": { + "type": "ExpressionStatement", + "start": 39, "end": 52, "loc": { "start": { "line": 3, - "column": 2 + "column": 12 }, "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", + "expression": { + "type": "StringLiteral", "start": 39, "end": 52, "loc": { @@ -266,30 +266,15 @@ "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" - } + "extra": { + "rawValue": "is str of b", + "raw": "'is str of b'" + }, + "value": "is str of b" } } - ] - } + } + ] } ], "directives": [] From e4b33f5081bf921a4b426181c12190c0eac8bc58 Mon Sep 17 00:00:00 2001 From: Alex Rattray Date: Fri, 2 Jun 2017 17:26:31 -0700 Subject: [PATCH 04/12] Destructuring in pattern matching --- src/parser/expression.js | 11 + src/plugins/lightscript.js | 35 +- src/tokenizer/state.js | 2 + .../match/basic-destructuring/actual.js | 8 +- .../match/basic-destructuring/expected.json | 561 +---- .../match/curly-consequent/actual.js | 2 +- .../match/curly-consequent/expected.json | 64 +- .../match/destructuring-arr/actual.js | 15 + .../match/destructuring-arr/expected.json | 1566 ++++++++++++ .../destructuring-obj-arr-mixed/actual.js | 15 + .../destructuring-obj-arr-mixed/expected.json | 707 ++++++ .../destructuring-obj-arr-mixed/options.json | 3 + .../match/destructuring-obj/actual.js | 14 + .../match/destructuring-obj/expected.json | 2158 +++++++++++++++++ .../match/destructuring-obj/options.json | 3 + .../match/illegal-arrow-fn/actual.js | 2 + .../match/illegal-arrow-fn/options.json | 3 + .../illegal-assignment-expression/actual.js | 3 + .../options.json | 3 + .../illegal-destructure-and-as/actual.js | 2 + .../illegal-destructure-and-as/options.json | 3 + .../match/illegal-fn-expression/actual.js | 2 + .../match/illegal-fn-expression/options.json | 3 + .../match/illegal-multi-pattern-1/actual.js | 2 + .../illegal-multi-pattern-1/options.json | 3 + .../match/illegal-multi-pattern-2/actual.js | 2 + .../illegal-multi-pattern-2/options.json | 3 + .../match/illegal-multi-pattern-3/actual.js | 2 + .../illegal-multi-pattern-3/options.json | 3 + .../match/illegal-multi-pattern-4/actual.js | 2 + .../illegal-multi-pattern-4/options.json | 3 + .../illegal-nested-match-in-test/actual.js | 2 + .../illegal-nested-match-in-test/options.json | 3 + .../illegal-sequence-expression/actual.js | 2 + .../illegal-sequence-expression/options.json | 3 + .../match/illegal-ternary/actual.js | 2 + .../match/illegal-ternary/options.json | 3 + .../lightscript/match/nested/actual.js | 2 +- .../lightscript/match/nested/expected.json | 110 +- .../actual.js | 4 +- .../options.json | 2 +- .../lightscript/match/subscripts/actual.js | 1 - .../match/subscripts/expected.json | 283 +-- 43 files changed, 4899 insertions(+), 723 deletions(-) create mode 100644 test/fixtures/lightscript/match/destructuring-arr/actual.js create mode 100644 test/fixtures/lightscript/match/destructuring-arr/expected.json create mode 100644 test/fixtures/lightscript/match/destructuring-obj-arr-mixed/actual.js create mode 100644 test/fixtures/lightscript/match/destructuring-obj-arr-mixed/expected.json create mode 100644 test/fixtures/lightscript/match/destructuring-obj-arr-mixed/options.json create mode 100644 test/fixtures/lightscript/match/destructuring-obj/actual.js create mode 100644 test/fixtures/lightscript/match/destructuring-obj/expected.json create mode 100644 test/fixtures/lightscript/match/destructuring-obj/options.json create mode 100644 test/fixtures/lightscript/match/illegal-arrow-fn/actual.js create mode 100644 test/fixtures/lightscript/match/illegal-arrow-fn/options.json create mode 100644 test/fixtures/lightscript/match/illegal-assignment-expression/actual.js create mode 100644 test/fixtures/lightscript/match/illegal-assignment-expression/options.json create mode 100644 test/fixtures/lightscript/match/illegal-destructure-and-as/actual.js create mode 100644 test/fixtures/lightscript/match/illegal-destructure-and-as/options.json create mode 100644 test/fixtures/lightscript/match/illegal-fn-expression/actual.js create mode 100644 test/fixtures/lightscript/match/illegal-fn-expression/options.json create mode 100644 test/fixtures/lightscript/match/illegal-multi-pattern-1/actual.js create mode 100644 test/fixtures/lightscript/match/illegal-multi-pattern-1/options.json create mode 100644 test/fixtures/lightscript/match/illegal-multi-pattern-2/actual.js create mode 100644 test/fixtures/lightscript/match/illegal-multi-pattern-2/options.json create mode 100644 test/fixtures/lightscript/match/illegal-multi-pattern-3/actual.js create mode 100644 test/fixtures/lightscript/match/illegal-multi-pattern-3/options.json create mode 100644 test/fixtures/lightscript/match/illegal-multi-pattern-4/actual.js create mode 100644 test/fixtures/lightscript/match/illegal-multi-pattern-4/options.json create mode 100644 test/fixtures/lightscript/match/illegal-nested-match-in-test/actual.js create mode 100644 test/fixtures/lightscript/match/illegal-nested-match-in-test/options.json create mode 100644 test/fixtures/lightscript/match/illegal-sequence-expression/actual.js create mode 100644 test/fixtures/lightscript/match/illegal-sequence-expression/options.json create mode 100644 test/fixtures/lightscript/match/illegal-ternary/actual.js create mode 100644 test/fixtures/lightscript/match/illegal-ternary/options.json diff --git a/src/parser/expression.js b/src/parser/expression.js index 654b6684ed..b299d09c89 100644 --- a/src/parser/expression.js +++ b/src/parser/expression.js @@ -678,6 +678,10 @@ pp.parseExprAtom = function (refShorthandDefaultPos) { return this.parseParenAndDistinguishExpression(null, null, canBeArrow); case tt.bracketL: + if (this.hasPlugin("lightscript") && this.state.inMatchCaseTest && !refShorthandDefaultPos) { + // re-enter this fn, but with refShorthandDefaultPos and state tracking + return this.parseMatchCaseTestPattern(); + } node = this.startNode(); this.next(); if (this.hasPlugin("lightscript") && this.match(tt._for)) { @@ -688,6 +692,10 @@ pp.parseExprAtom = function (refShorthandDefaultPos) { return this.finishNode(node, "ArrayExpression"); case tt.braceL: + if (this.hasPlugin("lightscript") && this.state.inMatchCaseTest && !refShorthandDefaultPos) { + // re-enter this fn, but with refShorthandDefaultPos and state tracking + return this.parseMatchCaseTestPattern(); + } return this.parseObj(false, refShorthandDefaultPos); case tt._function: @@ -1170,6 +1178,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/plugins/lightscript.js b/src/plugins/lightscript.js index 8ca9858f61..12c6f88eac 100644 --- a/src/plugins/lightscript.js +++ b/src/plugins/lightscript.js @@ -559,6 +559,7 @@ pp.parseMatchStatement = function (node) { }; pp.parseMatch = function (node, isExpression) { + if (this.state.inMatchCaseTest) this.unexpected(); this.expect(tt._match); node.discriminant = this.parseParenExpression(); @@ -594,8 +595,12 @@ pp.parseMatchCase = function (isExpression) { node.test = this.parseMatchCaseTest(); - if (this.eat(tt._with)) { - node.binding = this.parseBindingAtom(); + if (this.isContextual("as")) { + if (!this.state.allowMatchCaseTestPattern) { + this.unexpected(null, "Cannot rename after destructuring."); + } + this.next(); + node.binding = this.parseIdentifier(); } if (isExpression) { @@ -619,6 +624,7 @@ pp.parseMatchCase = function (isExpression) { pp.parseMatchCaseTest = function () { // can't be nested so no need to read/restore old value this.state.inMatchCaseTest = true; + this.state.allowMatchCaseTestPattern = true; this.expect(tt.bitwiseOR); if (this.isLineBreak()) this.unexpected(this.state.lastTokEnd, "Illegal newline."); @@ -633,6 +639,7 @@ pp.parseMatchCaseTest = function () { } this.state.inMatchCaseTest = false; + this.state.allowMatchCaseTestPattern = false; return test; }; @@ -649,8 +656,7 @@ pp.isSubscriptTokenForMatchCase = function (tokenType) { return ( tokenType === tt.dot || tokenType === tt.elvis || - tokenType === tt.tilde || - tokenType === tt.bracketL + tokenType === tt.tilde ); }; @@ -672,6 +678,27 @@ pp.allowMatchCasePlaceholder = function () { return false; }; +pp.parseMatchCaseTestPattern = function () { + if (!this.state.allowMatchCaseTestPattern) { + this.unexpected(null, "Only one pattern allowed per match case test."); + } + + const oldInMatchCaseTestPattern = this.state.inMatchCaseTestPattern; + this.state.inMatchCaseTestPattern = true; + + // re-enter parent function, allowing patterns. + const refShorthandDefaultPos = { start: 0 }; + const node = this.parseExprAtom(refShorthandDefaultPos); + + // once we have finished recursing through a pattern, disallow future patterns + this.state.inMatchCaseTestPattern = oldInMatchCaseTestPattern; + if (this.state.inMatchCaseTestPattern === false) { + this.state.allowMatchCaseTestPattern = false; + } + + return node; +}; + export default function (instance) { diff --git a/src/tokenizer/state.js b/src/tokenizer/state.js index 9e19e9f21c..5313aca266 100644 --- a/src/tokenizer/state.js +++ b/src/tokenizer/state.js @@ -41,6 +41,8 @@ export default class State { // for lightscript this.indentLevel = 0; this.inMatchCaseTest = false; + this.inMatchCaseTestPattern = false; + this.allowMatchCaseTestPattern = false; this.type = tt.eof; this.value = null; diff --git a/test/fixtures/lightscript/match/basic-destructuring/actual.js b/test/fixtures/lightscript/match/basic-destructuring/actual.js index 05ae81c620..c43b0dbbfb 100644 --- a/test/fixtures/lightscript/match/basic-destructuring/actual.js +++ b/test/fixtures/lightscript/match/basic-destructuring/actual.js @@ -1,8 +1,6 @@ match x: | a: 1 | b: b - | c with c: c - | d with { d }: d - | e with { e = 1 }: e - | f with [ f ]: f - | g with [ g = 1 ]: g + | c as c: c + | as as as: as + | ~isNumber() as n: n + 1 diff --git a/test/fixtures/lightscript/match/basic-destructuring/expected.json b/test/fixtures/lightscript/match/basic-destructuring/expected.json index 415a472e75..4810f40b10 100644 --- a/test/fixtures/lightscript/match/basic-destructuring/expected.json +++ b/test/fixtures/lightscript/match/basic-destructuring/expected.json @@ -1,29 +1,29 @@ { "type": "File", "start": 0, - "end": 130, + "end": 85, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 8, - "column": 23 + "line": 6, + "column": 27 } }, "program": { "type": "Program", "start": 0, - "end": 130, + "end": 85, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 8, - "column": 23 + "line": 6, + "column": 27 } }, "sourceType": "script", @@ -31,15 +31,15 @@ { "type": "MatchStatement", "start": 0, - "end": 130, + "end": 85, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 8, - "column": 23 + "line": 6, + "column": 27 } }, "discriminant": { @@ -194,7 +194,7 @@ { "type": "MatchCase", "start": 29, - "end": 42, + "end": 40, "loc": { "start": { "line": 4, @@ -202,7 +202,7 @@ }, "end": { "line": 4, - "column": 15 + "column": 13 } }, "test": { @@ -224,16 +224,16 @@ }, "binding": { "type": "Identifier", - "start": 38, - "end": 39, + "start": 36, + "end": 37, "loc": { "start": { "line": 4, - "column": 11 + "column": 9 }, "end": { "line": 4, - "column": 12 + "column": 10 }, "identifierName": "c" }, @@ -241,30 +241,30 @@ }, "consequent": { "type": "ExpressionStatement", - "start": 41, - "end": 42, + "start": 39, + "end": 40, "loc": { "start": { "line": 4, - "column": 14 + "column": 12 }, "end": { "line": 4, - "column": 15 + "column": 13 } }, "expression": { "type": "Identifier", - "start": 41, - "end": 42, + "start": 39, + "end": 40, "loc": { "start": { "line": 4, - "column": 14 + "column": 12 }, "end": { "line": 4, - "column": 15 + "column": 13 }, "identifierName": "c" }, @@ -274,8 +274,8 @@ }, { "type": "MatchCase", - "start": 45, - "end": 62, + "start": 43, + "end": 57, "loc": { "start": { "line": 5, @@ -283,13 +283,13 @@ }, "end": { "line": 5, - "column": 19 + "column": 16 } }, "test": { "type": "Identifier", - "start": 47, - "end": 48, + "start": 45, + "end": 47, "loc": { "start": { "line": 5, @@ -297,121 +297,66 @@ }, "end": { "line": 5, - "column": 5 + "column": 6 }, - "identifierName": "d" + "identifierName": "as" }, - "name": "d" + "name": "as" }, "binding": { - "type": "ObjectPattern", - "start": 54, - "end": 59, + "type": "Identifier", + "start": 51, + "end": 53, "loc": { "start": { "line": 5, - "column": 11 + "column": 10 }, "end": { "line": 5, - "column": 16 - } + "column": 12 + }, + "identifierName": "as" }, - "properties": [ - { - "type": "ObjectProperty", - "start": 56, - "end": 57, - "loc": { - "start": { - "line": 5, - "column": 13 - }, - "end": { - "line": 5, - "column": 14 - } - }, - "method": false, - "shorthand": true, - "computed": false, - "key": { - "type": "Identifier", - "start": 56, - "end": 57, - "loc": { - "start": { - "line": 5, - "column": 13 - }, - "end": { - "line": 5, - "column": 14 - }, - "identifierName": "d" - }, - "name": "d" - }, - "value": { - "type": "Identifier", - "start": 56, - "end": 57, - "loc": { - "start": { - "line": 5, - "column": 13 - }, - "end": { - "line": 5, - "column": 14 - }, - "identifierName": "d" - }, - "name": "d" - }, - "extra": { - "shorthand": true - } - } - ] + "name": "as" }, "consequent": { "type": "ExpressionStatement", - "start": 61, - "end": 62, + "start": 55, + "end": 57, "loc": { "start": { "line": 5, - "column": 18 + "column": 14 }, "end": { "line": 5, - "column": 19 + "column": 16 } }, "expression": { "type": "Identifier", - "start": 61, - "end": 62, + "start": 55, + "end": 57, "loc": { "start": { "line": 5, - "column": 18 + "column": 14 }, "end": { "line": 5, - "column": 19 + "column": 16 }, - "identifierName": "d" + "identifierName": "as" }, - "name": "d" + "name": "as" } } }, { "type": "MatchCase", - "start": 65, - "end": 86, + "start": 60, + "end": 85, "loc": { "start": { "line": 6, @@ -419,13 +364,13 @@ }, "end": { "line": 6, - "column": 23 + "column": 27 } }, "test": { - "type": "Identifier", - "start": 67, - "end": 68, + "type": "TildeCallExpression", + "start": 62, + "end": 73, "loc": { "start": { "line": 6, @@ -433,123 +378,64 @@ }, "end": { "line": 6, - "column": 5 + "column": 15 + } + }, + "left": { + "type": "PlaceholderExpression", + "start": 61, + "end": 62, + "loc": { + "start": { + "line": 6, + "column": 3 + }, + "end": { + "line": 6, + "column": 4 + } + } + }, + "right": { + "type": "Identifier", + "start": 63, + "end": 71, + "loc": { + "start": { + "line": 6, + "column": 5 + }, + "end": { + "line": 6, + "column": 13 + }, + "identifierName": "isNumber" }, - "identifierName": "e" + "name": "isNumber" }, - "name": "e" + "arguments": [] }, "binding": { - "type": "ObjectPattern", - "start": 74, - "end": 83, + "type": "Identifier", + "start": 77, + "end": 78, "loc": { "start": { "line": 6, - "column": 11 + "column": 19 }, "end": { "line": 6, "column": 20 - } + }, + "identifierName": "n" }, - "properties": [ - { - "type": "ObjectProperty", - "start": 76, - "end": 81, - "loc": { - "start": { - "line": 6, - "column": 13 - }, - "end": { - "line": 6, - "column": 18 - } - }, - "method": false, - "shorthand": true, - "computed": false, - "key": { - "type": "Identifier", - "start": 76, - "end": 77, - "loc": { - "start": { - "line": 6, - "column": 13 - }, - "end": { - "line": 6, - "column": 14 - }, - "identifierName": "e" - }, - "name": "e" - }, - "value": { - "type": "AssignmentPattern", - "start": 76, - "end": 81, - "loc": { - "start": { - "line": 6, - "column": 13 - }, - "end": { - "line": 6, - "column": 18 - } - }, - "left": { - "type": "Identifier", - "start": 76, - "end": 77, - "loc": { - "start": { - "line": 6, - "column": 13 - }, - "end": { - "line": 6, - "column": 14 - }, - "identifierName": "e" - }, - "name": "e" - }, - "right": { - "type": "NumericLiteral", - "start": 80, - "end": 81, - "loc": { - "start": { - "line": 6, - "column": 17 - }, - "end": { - "line": 6, - "column": 18 - } - }, - "extra": { - "rawValue": 1, - "raw": "1" - }, - "value": 1 - } - }, - "extra": { - "shorthand": true - } - } - ] + "name": "n" }, "consequent": { "type": "ExpressionStatement", - "start": 85, - "end": 86, + "start": 80, + "end": 85, "loc": { "start": { "line": 6, @@ -557,13 +443,13 @@ }, "end": { "line": 6, - "column": 23 + "column": 27 } }, "expression": { - "type": "Identifier", - "start": 85, - "end": 86, + "type": "BinaryExpression", + "start": 80, + "end": 85, "loc": { "start": { "line": 6, @@ -571,242 +457,47 @@ }, "end": { "line": 6, - "column": 23 - }, - "identifierName": "e" - }, - "name": "e" - } - } - }, - { - "type": "MatchCase", - "start": 89, - "end": 106, - "loc": { - "start": { - "line": 7, - "column": 2 - }, - "end": { - "line": 7, - "column": 19 - } - }, - "test": { - "type": "Identifier", - "start": 91, - "end": 92, - "loc": { - "start": { - "line": 7, - "column": 4 - }, - "end": { - "line": 7, - "column": 5 - }, - "identifierName": "f" - }, - "name": "f" - }, - "binding": { - "type": "ArrayPattern", - "start": 98, - "end": 103, - "loc": { - "start": { - "line": 7, - "column": 11 + "column": 27 + } }, - "end": { - "line": 7, - "column": 16 - } - }, - "elements": [ - { + "left": { "type": "Identifier", - "start": 100, - "end": 101, + "start": 80, + "end": 81, "loc": { "start": { - "line": 7, - "column": 13 + "line": 6, + "column": 22 }, "end": { - "line": 7, - "column": 14 + "line": 6, + "column": 23 }, - "identifierName": "f" + "identifierName": "n" }, - "name": "f" - } - ] - }, - "consequent": { - "type": "ExpressionStatement", - "start": 105, - "end": 106, - "loc": { - "start": { - "line": 7, - "column": 18 - }, - "end": { - "line": 7, - "column": 19 - } - }, - "expression": { - "type": "Identifier", - "start": 105, - "end": 106, - "loc": { - "start": { - "line": 7, - "column": 18 - }, - "end": { - "line": 7, - "column": 19 - }, - "identifierName": "f" - }, - "name": "f" - } - } - }, - { - "type": "MatchCase", - "start": 109, - "end": 130, - "loc": { - "start": { - "line": 8, - "column": 2 - }, - "end": { - "line": 8, - "column": 23 - } - }, - "test": { - "type": "Identifier", - "start": 111, - "end": 112, - "loc": { - "start": { - "line": 8, - "column": 4 - }, - "end": { - "line": 8, - "column": 5 - }, - "identifierName": "g" - }, - "name": "g" - }, - "binding": { - "type": "ArrayPattern", - "start": 118, - "end": 127, - "loc": { - "start": { - "line": 8, - "column": 11 + "name": "n" }, - "end": { - "line": 8, - "column": 20 - } - }, - "elements": [ - { - "type": "AssignmentPattern", - "start": 120, - "end": 125, + "operator": "+", + "right": { + "type": "NumericLiteral", + "start": 84, + "end": 85, "loc": { "start": { - "line": 8, - "column": 13 + "line": 6, + "column": 26 }, "end": { - "line": 8, - "column": 18 + "line": 6, + "column": 27 } }, - "left": { - "type": "Identifier", - "start": 120, - "end": 121, - "loc": { - "start": { - "line": 8, - "column": 13 - }, - "end": { - "line": 8, - "column": 14 - }, - "identifierName": "g" - }, - "name": "g" + "extra": { + "rawValue": 1, + "raw": "1" }, - "right": { - "type": "NumericLiteral", - "start": 124, - "end": 125, - "loc": { - "start": { - "line": 8, - "column": 17 - }, - "end": { - "line": 8, - "column": 18 - } - }, - "extra": { - "rawValue": 1, - "raw": "1" - }, - "value": 1 - } + "value": 1 } - ] - }, - "consequent": { - "type": "ExpressionStatement", - "start": 129, - "end": 130, - "loc": { - "start": { - "line": 8, - "column": 22 - }, - "end": { - "line": 8, - "column": 23 - } - }, - "expression": { - "type": "Identifier", - "start": 129, - "end": 130, - "loc": { - "start": { - "line": 8, - "column": 22 - }, - "end": { - "line": 8, - "column": 23 - }, - "identifierName": "g" - }, - "name": "g" } } } diff --git a/test/fixtures/lightscript/match/curly-consequent/actual.js b/test/fixtures/lightscript/match/curly-consequent/actual.js index fdd561e298..308471a449 100644 --- a/test/fixtures/lightscript/match/curly-consequent/actual.js +++ b/test/fixtures/lightscript/match/curly-consequent/actual.js @@ -3,7 +3,7 @@ a = match x: | z { "z" } - | a with b { + | a as b { b b } diff --git a/test/fixtures/lightscript/match/curly-consequent/expected.json b/test/fixtures/lightscript/match/curly-consequent/expected.json index d25a2b7d98..fbb47ccaef 100644 --- a/test/fixtures/lightscript/match/curly-consequent/expected.json +++ b/test/fixtures/lightscript/match/curly-consequent/expected.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 97, + "end": 95, "loc": { "start": { "line": 1, @@ -15,7 +15,7 @@ "program": { "type": "Program", "start": 0, - "end": 97, + "end": 95, "loc": { "start": { "line": 1, @@ -31,7 +31,7 @@ { "type": "VariableDeclaration", "start": 0, - "end": 97, + "end": 95, "loc": { "start": { "line": 1, @@ -50,7 +50,7 @@ { "type": "VariableDeclarator", "start": 0, - "end": 97, + "end": 95, "loc": { "start": { "line": 1, @@ -81,7 +81,7 @@ "init": { "type": "MatchExpression", "start": 4, - "end": 97, + "end": 95, "loc": { "start": { "line": 1, @@ -289,7 +289,7 @@ { "type": "MatchCase", "start": 49, - "end": 77, + "end": 75, "loc": { "start": { "line": 6, @@ -319,16 +319,16 @@ }, "binding": { "type": "Identifier", - "start": 58, - "end": 59, + "start": 56, + "end": 57, "loc": { "start": { "line": 6, - "column": 11 + "column": 9 }, "end": { "line": 6, - "column": 12 + "column": 10 }, "identifierName": "b" }, @@ -336,12 +336,12 @@ }, "consequent": { "type": "BlockStatement", - "start": 60, - "end": 77, + "start": 58, + "end": 75, "loc": { "start": { "line": 6, - "column": 13 + "column": 11 }, "end": { "line": 9, @@ -351,8 +351,8 @@ "body": [ { "type": "ExpressionStatement", - "start": 66, - "end": 67, + "start": 64, + "end": 65, "loc": { "start": { "line": 7, @@ -365,8 +365,8 @@ }, "expression": { "type": "Identifier", - "start": 66, - "end": 67, + "start": 64, + "end": 65, "loc": { "start": { "line": 7, @@ -383,8 +383,8 @@ }, { "type": "ExpressionStatement", - "start": 72, - "end": 73, + "start": 70, + "end": 71, "loc": { "start": { "line": 8, @@ -397,8 +397,8 @@ }, "expression": { "type": "Identifier", - "start": 72, - "end": 73, + "start": 70, + "end": 71, "loc": { "start": { "line": 8, @@ -422,8 +422,8 @@ }, { "type": "MatchCase", - "start": 80, - "end": 97, + "start": 78, + "end": 95, "loc": { "start": { "line": 10, @@ -436,8 +436,8 @@ }, "test": { "type": "Identifier", - "start": 83, - "end": 84, + "start": 81, + "end": 82, "loc": { "start": { "line": 10, @@ -452,13 +452,13 @@ "name": "c", "extra": { "parenthesized": true, - "parenStart": 82 + "parenStart": 80 } }, "consequent": { "type": "BlockStatement", - "start": 86, - "end": 97, + "start": 84, + "end": 95, "loc": { "start": { "line": 10, @@ -472,8 +472,8 @@ "body": [ { "type": "ExpressionStatement", - "start": 92, - "end": 93, + "start": 90, + "end": 91, "loc": { "start": { "line": 11, @@ -486,8 +486,8 @@ }, "expression": { "type": "Identifier", - "start": 92, - "end": 93, + "start": 90, + "end": 91, "loc": { "start": { "line": 11, 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..e37f2c9d9d --- /dev/null +++ b/test/fixtures/lightscript/match/destructuring-arr/actual.js @@ -0,0 +1,15 @@ +match x: + | [ a, b ] and a > 1: a + b + | [ a, b ]: a - b + | [ a, b = 2 ]: a + b - 2 + | [ 'a', b, c = 'c' ]: ['a', b, c].join('') + | [ + [ + b + d = 'e' + ] + [ g, 'h' ] + ...j + ]: + [b, d, g, ...j].join('') + | [ a, 'b', ...c ]: [a, 'b', ...c].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..27757a24d2 --- /dev/null +++ b/test/fixtures/lightscript/match/destructuring-arr/expected.json @@ -0,0 +1,1566 @@ +{ + "type": "File", + "start": 0, + "end": 288, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 15, + "column": 45 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 288, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 15, + "column": 45 + } + }, + "sourceType": "script", + "body": [ + { + "type": "MatchStatement", + "start": 0, + "end": 288, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 15, + "column": 45 + } + }, + "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": "LogicalExpression", + "start": 13, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "left": { + "type": "ArrayExpression", + "start": 13, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 7 + }, + "identifierName": "a" + }, + "name": "a" + }, + { + "type": "Identifier", + "start": 18, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 10 + }, + "identifierName": "b" + }, + "name": "b" + } + ] + }, + "operator": "&&", + "right": { + "type": "BinaryExpression", + "start": 26, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "left": { + "type": "Identifier", + "start": 26, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 18 + }, + "identifierName": "a" + }, + "name": "a" + }, + "operator": ">", + "right": { + "type": "NumericLiteral", + "start": 30, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + }, + "consequent": { + "type": "ExpressionStatement", + "start": 33, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 33, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "left": { + "type": "Identifier", + "start": 33, + "end": 34, + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 25 + }, + "identifierName": "a" + }, + "name": "a" + }, + "operator": "+", + "right": { + "type": "Identifier", + "start": 37, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 28 + }, + "end": { + "line": 2, + "column": 29 + }, + "identifierName": "b" + }, + "name": "b" + } + } + } + }, + { + "type": "MatchCase", + "start": 41, + "end": 58, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 19 + } + }, + "test": { + "type": "ArrayExpression", + "start": 43, + "end": 51, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 12 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 45, + "end": 46, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 7 + }, + "identifierName": "a" + }, + "name": "a" + }, + { + "type": "Identifier", + "start": 48, + "end": 49, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 10 + }, + "identifierName": "b" + }, + "name": "b" + } + ] + }, + "consequent": { + "type": "ExpressionStatement", + "start": 53, + "end": 58, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 19 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 53, + "end": 58, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 19 + } + }, + "left": { + "type": "Identifier", + "start": 53, + "end": 54, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + }, + "identifierName": "a" + }, + "name": "a" + }, + "operator": "-", + "right": { + "type": "Identifier", + "start": 57, + "end": 58, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 19 + }, + "identifierName": "b" + }, + "name": "b" + } + } + } + }, + { + "type": "MatchCase", + "start": 61, + "end": 86, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 27 + } + }, + "test": { + "type": "ArrayExpression", + "start": 63, + "end": 75, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 16 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 65, + "end": 66, + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 7 + }, + "identifierName": "a" + }, + "name": "a" + }, + { + "type": "AssignmentExpression", + "start": 68, + "end": 73, + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 4, + "column": 14 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 68, + "end": 69, + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 4, + "column": 10 + }, + "identifierName": "b" + }, + "name": "b" + }, + "right": { + "type": "NumericLiteral", + "start": 72, + "end": 73, + "loc": { + "start": { + "line": 4, + "column": 13 + }, + "end": { + "line": 4, + "column": 14 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + }, + "isNowAssign": false + } + ] + }, + "consequent": { + "type": "ExpressionStatement", + "start": 77, + "end": 86, + "loc": { + "start": { + "line": 4, + "column": 18 + }, + "end": { + "line": 4, + "column": 27 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 77, + "end": 86, + "loc": { + "start": { + "line": 4, + "column": 18 + }, + "end": { + "line": 4, + "column": 27 + } + }, + "left": { + "type": "BinaryExpression", + "start": 77, + "end": 82, + "loc": { + "start": { + "line": 4, + "column": 18 + }, + "end": { + "line": 4, + "column": 23 + } + }, + "left": { + "type": "Identifier", + "start": 77, + "end": 78, + "loc": { + "start": { + "line": 4, + "column": 18 + }, + "end": { + "line": 4, + "column": 19 + }, + "identifierName": "a" + }, + "name": "a" + }, + "operator": "+", + "right": { + "type": "Identifier", + "start": 81, + "end": 82, + "loc": { + "start": { + "line": 4, + "column": 22 + }, + "end": { + "line": 4, + "column": 23 + }, + "identifierName": "b" + }, + "name": "b" + } + }, + "operator": "-", + "right": { + "type": "NumericLiteral", + "start": 85, + "end": 86, + "loc": { + "start": { + "line": 4, + "column": 26 + }, + "end": { + "line": 4, + "column": 27 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + } + } + }, + { + "type": "MatchCase", + "start": 89, + "end": 132, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 45 + } + }, + "test": { + "type": "ArrayExpression", + "start": 91, + "end": 110, + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 23 + } + }, + "elements": [ + { + "type": "StringLiteral", + "start": 93, + "end": 96, + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 5, + "column": 9 + } + }, + "extra": { + "rawValue": "a", + "raw": "'a'" + }, + "value": "a" + }, + { + "type": "Identifier", + "start": 98, + "end": 99, + "loc": { + "start": { + "line": 5, + "column": 11 + }, + "end": { + "line": 5, + "column": 12 + }, + "identifierName": "b" + }, + "name": "b" + }, + { + "type": "AssignmentExpression", + "start": 101, + "end": 108, + "loc": { + "start": { + "line": 5, + "column": 14 + }, + "end": { + "line": 5, + "column": 21 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 101, + "end": 102, + "loc": { + "start": { + "line": 5, + "column": 14 + }, + "end": { + "line": 5, + "column": 15 + }, + "identifierName": "c" + }, + "name": "c" + }, + "right": { + "type": "StringLiteral", + "start": 105, + "end": 108, + "loc": { + "start": { + "line": 5, + "column": 18 + }, + "end": { + "line": 5, + "column": 21 + } + }, + "extra": { + "rawValue": "c", + "raw": "'c'" + }, + "value": "c" + }, + "isNowAssign": false + } + ] + }, + "consequent": { + "type": "ExpressionStatement", + "start": 112, + "end": 132, + "loc": { + "start": { + "line": 5, + "column": 25 + }, + "end": { + "line": 5, + "column": 45 + } + }, + "expression": { + "type": "CallExpression", + "start": 112, + "end": 132, + "loc": { + "start": { + "line": 5, + "column": 25 + }, + "end": { + "line": 5, + "column": 45 + } + }, + "callee": { + "type": "MemberExpression", + "start": 112, + "end": 128, + "loc": { + "start": { + "line": 5, + "column": 25 + }, + "end": { + "line": 5, + "column": 41 + } + }, + "object": { + "type": "ArrayExpression", + "start": 112, + "end": 123, + "loc": { + "start": { + "line": 5, + "column": 25 + }, + "end": { + "line": 5, + "column": 36 + } + }, + "elements": [ + { + "type": "StringLiteral", + "start": 113, + "end": 116, + "loc": { + "start": { + "line": 5, + "column": 26 + }, + "end": { + "line": 5, + "column": 29 + } + }, + "extra": { + "rawValue": "a", + "raw": "'a'" + }, + "value": "a" + }, + { + "type": "Identifier", + "start": 118, + "end": 119, + "loc": { + "start": { + "line": 5, + "column": 31 + }, + "end": { + "line": 5, + "column": 32 + }, + "identifierName": "b" + }, + "name": "b" + }, + { + "type": "Identifier", + "start": 121, + "end": 122, + "loc": { + "start": { + "line": 5, + "column": 34 + }, + "end": { + "line": 5, + "column": 35 + }, + "identifierName": "c" + }, + "name": "c" + } + ] + }, + "property": { + "type": "Identifier", + "start": 124, + "end": 128, + "loc": { + "start": { + "line": 5, + "column": 37 + }, + "end": { + "line": 5, + "column": 41 + }, + "identifierName": "join" + }, + "name": "join" + }, + "computed": false + }, + "arguments": [ + { + "type": "StringLiteral", + "start": 129, + "end": 131, + "loc": { + "start": { + "line": 5, + "column": 42 + }, + "end": { + "line": 5, + "column": 44 + } + }, + "extra": { + "rawValue": "", + "raw": "''" + }, + "value": "" + } + ] + } + } + }, + { + "type": "MatchCase", + "start": 135, + "end": 242, + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 14, + "column": 28 + } + }, + "test": { + "type": "ArrayExpression", + "start": 137, + "end": 212, + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 13, + "column": 3 + } + }, + "elements": [ + { + "type": "ArrayExpression", + "start": 145, + "end": 180, + "loc": { + "start": { + "line": 7, + "column": 6 + }, + "end": { + "line": 10, + "column": 7 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 155, + "end": 156, + "loc": { + "start": { + "line": 8, + "column": 8 + }, + "end": { + "line": 8, + "column": 9 + }, + "identifierName": "b" + }, + "name": "b" + }, + { + "type": "AssignmentExpression", + "start": 165, + "end": 172, + "loc": { + "start": { + "line": 9, + "column": 8 + }, + "end": { + "line": 9, + "column": 15 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 165, + "end": 166, + "loc": { + "start": { + "line": 9, + "column": 8 + }, + "end": { + "line": 9, + "column": 9 + }, + "identifierName": "d" + }, + "name": "d" + }, + "right": { + "type": "StringLiteral", + "start": 169, + "end": 172, + "loc": { + "start": { + "line": 9, + "column": 12 + }, + "end": { + "line": 9, + "column": 15 + } + }, + "extra": { + "rawValue": "e", + "raw": "'e'" + }, + "value": "e" + }, + "isNowAssign": false + } + ] + }, + { + "type": "ArrayExpression", + "start": 187, + "end": 197, + "loc": { + "start": { + "line": 11, + "column": 6 + }, + "end": { + "line": 11, + "column": 16 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 189, + "end": 190, + "loc": { + "start": { + "line": 11, + "column": 8 + }, + "end": { + "line": 11, + "column": 9 + }, + "identifierName": "g" + }, + "name": "g" + }, + { + "type": "StringLiteral", + "start": 192, + "end": 195, + "loc": { + "start": { + "line": 11, + "column": 11 + }, + "end": { + "line": 11, + "column": 14 + } + }, + "extra": { + "rawValue": "h", + "raw": "'h'" + }, + "value": "h" + } + ] + }, + { + "type": "SpreadElement", + "start": 204, + "end": 208, + "loc": { + "start": { + "line": 12, + "column": 6 + }, + "end": { + "line": 12, + "column": 10 + } + }, + "argument": { + "type": "Identifier", + "start": 207, + "end": 208, + "loc": { + "start": { + "line": 12, + "column": 9 + }, + "end": { + "line": 12, + "column": 10 + }, + "identifierName": "j" + }, + "name": "j" + } + } + ] + }, + "consequent": { + "type": "BlockStatement", + "start": 212, + "end": 242, + "loc": { + "start": { + "line": 13, + "column": 3 + }, + "end": { + "line": 14, + "column": 28 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 218, + "end": 242, + "loc": { + "start": { + "line": 14, + "column": 4 + }, + "end": { + "line": 14, + "column": 28 + } + }, + "expression": { + "type": "CallExpression", + "start": 218, + "end": 242, + "loc": { + "start": { + "line": 14, + "column": 4 + }, + "end": { + "line": 14, + "column": 28 + } + }, + "callee": { + "type": "MemberExpression", + "start": 218, + "end": 238, + "loc": { + "start": { + "line": 14, + "column": 4 + }, + "end": { + "line": 14, + "column": 24 + } + }, + "object": { + "type": "ArrayExpression", + "start": 218, + "end": 233, + "loc": { + "start": { + "line": 14, + "column": 4 + }, + "end": { + "line": 14, + "column": 19 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 219, + "end": 220, + "loc": { + "start": { + "line": 14, + "column": 5 + }, + "end": { + "line": 14, + "column": 6 + }, + "identifierName": "b" + }, + "name": "b" + }, + { + "type": "Identifier", + "start": 222, + "end": 223, + "loc": { + "start": { + "line": 14, + "column": 8 + }, + "end": { + "line": 14, + "column": 9 + }, + "identifierName": "d" + }, + "name": "d" + }, + { + "type": "Identifier", + "start": 225, + "end": 226, + "loc": { + "start": { + "line": 14, + "column": 11 + }, + "end": { + "line": 14, + "column": 12 + }, + "identifierName": "g" + }, + "name": "g" + }, + { + "type": "SpreadElement", + "start": 228, + "end": 232, + "loc": { + "start": { + "line": 14, + "column": 14 + }, + "end": { + "line": 14, + "column": 18 + } + }, + "argument": { + "type": "Identifier", + "start": 231, + "end": 232, + "loc": { + "start": { + "line": 14, + "column": 17 + }, + "end": { + "line": 14, + "column": 18 + }, + "identifierName": "j" + }, + "name": "j" + } + } + ] + }, + "property": { + "type": "Identifier", + "start": 234, + "end": 238, + "loc": { + "start": { + "line": 14, + "column": 20 + }, + "end": { + "line": 14, + "column": 24 + }, + "identifierName": "join" + }, + "name": "join" + }, + "computed": false + }, + "arguments": [ + { + "type": "StringLiteral", + "start": 239, + "end": 241, + "loc": { + "start": { + "line": 14, + "column": 25 + }, + "end": { + "line": 14, + "column": 27 + } + }, + "extra": { + "rawValue": "", + "raw": "''" + }, + "value": "" + } + ] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + }, + { + "type": "MatchCase", + "start": 245, + "end": 288, + "loc": { + "start": { + "line": 15, + "column": 2 + }, + "end": { + "line": 15, + "column": 45 + } + }, + "test": { + "type": "ArrayExpression", + "start": 247, + "end": 263, + "loc": { + "start": { + "line": 15, + "column": 4 + }, + "end": { + "line": 15, + "column": 20 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 249, + "end": 250, + "loc": { + "start": { + "line": 15, + "column": 6 + }, + "end": { + "line": 15, + "column": 7 + }, + "identifierName": "a" + }, + "name": "a" + }, + { + "type": "StringLiteral", + "start": 252, + "end": 255, + "loc": { + "start": { + "line": 15, + "column": 9 + }, + "end": { + "line": 15, + "column": 12 + } + }, + "extra": { + "rawValue": "b", + "raw": "'b'" + }, + "value": "b" + }, + { + "type": "SpreadElement", + "start": 257, + "end": 261, + "loc": { + "start": { + "line": 15, + "column": 14 + }, + "end": { + "line": 15, + "column": 18 + } + }, + "argument": { + "type": "Identifier", + "start": 260, + "end": 261, + "loc": { + "start": { + "line": 15, + "column": 17 + }, + "end": { + "line": 15, + "column": 18 + }, + "identifierName": "c" + }, + "name": "c" + } + } + ] + }, + "consequent": { + "type": "ExpressionStatement", + "start": 265, + "end": 288, + "loc": { + "start": { + "line": 15, + "column": 22 + }, + "end": { + "line": 15, + "column": 45 + } + }, + "expression": { + "type": "CallExpression", + "start": 265, + "end": 288, + "loc": { + "start": { + "line": 15, + "column": 22 + }, + "end": { + "line": 15, + "column": 45 + } + }, + "callee": { + "type": "MemberExpression", + "start": 265, + "end": 284, + "loc": { + "start": { + "line": 15, + "column": 22 + }, + "end": { + "line": 15, + "column": 41 + } + }, + "object": { + "type": "ArrayExpression", + "start": 265, + "end": 279, + "loc": { + "start": { + "line": 15, + "column": 22 + }, + "end": { + "line": 15, + "column": 36 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 266, + "end": 267, + "loc": { + "start": { + "line": 15, + "column": 23 + }, + "end": { + "line": 15, + "column": 24 + }, + "identifierName": "a" + }, + "name": "a" + }, + { + "type": "StringLiteral", + "start": 269, + "end": 272, + "loc": { + "start": { + "line": 15, + "column": 26 + }, + "end": { + "line": 15, + "column": 29 + } + }, + "extra": { + "rawValue": "b", + "raw": "'b'" + }, + "value": "b" + }, + { + "type": "SpreadElement", + "start": 274, + "end": 278, + "loc": { + "start": { + "line": 15, + "column": 31 + }, + "end": { + "line": 15, + "column": 35 + } + }, + "argument": { + "type": "Identifier", + "start": 277, + "end": 278, + "loc": { + "start": { + "line": 15, + "column": 34 + }, + "end": { + "line": 15, + "column": 35 + }, + "identifierName": "c" + }, + "name": "c" + } + } + ] + }, + "property": { + "type": "Identifier", + "start": 280, + "end": 284, + "loc": { + "start": { + "line": 15, + "column": 37 + }, + "end": { + "line": 15, + "column": 41 + }, + "identifierName": "join" + }, + "name": "join" + }, + "computed": false + }, + "arguments": [ + { + "type": "StringLiteral", + "start": 285, + "end": 287, + "loc": { + "start": { + "line": 15, + "column": 42 + }, + "end": { + "line": 15, + "column": 44 + } + }, + "extra": { + "rawValue": "", + "raw": "''" + }, + "value": "" + } + ] + } + } + } + ] + } + ], + "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..c55f1c63b0 --- /dev/null +++ b/test/fixtures/lightscript/match/destructuring-obj-arr-mixed/actual.js @@ -0,0 +1,15 @@ +match x: + | { + a: [ + b + { + d + e: 'e' + ...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..6d154936f2 --- /dev/null +++ b/test/fixtures/lightscript/match/destructuring-obj-arr-mixed/expected.json @@ -0,0 +1,707 @@ +{ + "type": "File", + "start": 0, + "end": 160, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 15, + "column": 34 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 160, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 15, + "column": 34 + } + }, + "sourceType": "script", + "body": [ + { + "type": "MatchStatement", + "start": 0, + "end": 160, + "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": 160, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 15, + "column": 34 + } + }, + "test": { + "type": "ObjectExpression", + "start": 13, + "end": 124, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 14, + "column": 3 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 19, + "end": 99, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 11, + "column": 5 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 19, + "end": 20, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 5 + }, + "identifierName": "a" + }, + "name": "a" + }, + "value": { + "type": "ArrayExpression", + "start": 22, + "end": 99, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 11, + "column": 5 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 30, + "end": 31, + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 7 + }, + "identifierName": "b" + }, + "name": "b" + }, + { + "type": "ObjectExpression", + "start": 38, + "end": 85, + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 9, + "column": 7 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 48, + "end": 49, + "loc": { + "start": { + "line": 6, + "column": 8 + }, + "end": { + "line": 6, + "column": 9 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 48, + "end": 49, + "loc": { + "start": { + "line": 6, + "column": 8 + }, + "end": { + "line": 6, + "column": 9 + }, + "identifierName": "d" + }, + "name": "d" + }, + "value": { + "type": "Identifier", + "start": 48, + "end": 49, + "loc": { + "start": { + "line": 6, + "column": 8 + }, + "end": { + "line": 6, + "column": 9 + }, + "identifierName": "d" + }, + "name": "d" + }, + "extra": { + "shorthand": true + } + }, + { + "type": "ObjectProperty", + "start": 58, + "end": 64, + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 14 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 58, + "end": 59, + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 9 + }, + "identifierName": "e" + }, + "name": "e" + }, + "value": { + "type": "StringLiteral", + "start": 61, + "end": 64, + "loc": { + "start": { + "line": 7, + "column": 11 + }, + "end": { + "line": 7, + "column": 14 + } + }, + "extra": { + "rawValue": "e", + "raw": "'e'" + }, + "value": "e" + } + }, + { + "type": "SpreadProperty", + "start": 73, + "end": 77, + "loc": { + "start": { + "line": 8, + "column": 8 + }, + "end": { + "line": 8, + "column": 12 + } + }, + "argument": { + "type": "Identifier", + "start": 76, + "end": 77, + "loc": { + "start": { + "line": 8, + "column": 11 + }, + "end": { + "line": 8, + "column": 12 + }, + "identifierName": "f" + }, + "name": "f" + } + } + ] + }, + { + "type": "Identifier", + "start": 92, + "end": 93, + "loc": { + "start": { + "line": 10, + "column": 6 + }, + "end": { + "line": 10, + "column": 7 + }, + "identifierName": "g" + }, + "name": "g" + } + ] + } + }, + { + "type": "ObjectProperty", + "start": 104, + "end": 111, + "loc": { + "start": { + "line": 12, + "column": 4 + }, + "end": { + "line": 12, + "column": 11 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 104, + "end": 105, + "loc": { + "start": { + "line": 12, + "column": 4 + }, + "end": { + "line": 12, + "column": 5 + }, + "identifierName": "h" + }, + "name": "h" + }, + "value": { + "type": "AssignmentPattern", + "start": 104, + "end": 111, + "loc": { + "start": { + "line": 12, + "column": 4 + }, + "end": { + "line": 12, + "column": 11 + } + }, + "left": { + "type": "Identifier", + "start": 104, + "end": 105, + "loc": { + "start": { + "line": 12, + "column": 4 + }, + "end": { + "line": 12, + "column": 5 + }, + "identifierName": "h" + }, + "name": "h" + }, + "right": { + "type": "StringLiteral", + "start": 108, + "end": 111, + "loc": { + "start": { + "line": 12, + "column": 8 + }, + "end": { + "line": 12, + "column": 11 + } + }, + "extra": { + "rawValue": "h", + "raw": "'h'" + }, + "value": "h" + } + }, + "extra": { + "shorthand": true + } + }, + { + "type": "SpreadProperty", + "start": 116, + "end": 120, + "loc": { + "start": { + "line": 13, + "column": 4 + }, + "end": { + "line": 13, + "column": 8 + } + }, + "argument": { + "type": "Identifier", + "start": 119, + "end": 120, + "loc": { + "start": { + "line": 13, + "column": 7 + }, + "end": { + "line": 13, + "column": 8 + }, + "identifierName": "i" + }, + "name": "i" + } + } + ] + }, + "consequent": { + "type": "BlockStatement", + "start": 124, + "end": 160, + "loc": { + "start": { + "line": 14, + "column": 3 + }, + "end": { + "line": 15, + "column": 34 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 130, + "end": 160, + "loc": { + "start": { + "line": 15, + "column": 4 + }, + "end": { + "line": 15, + "column": 34 + } + }, + "expression": { + "type": "CallExpression", + "start": 130, + "end": 160, + "loc": { + "start": { + "line": 15, + "column": 4 + }, + "end": { + "line": 15, + "column": 34 + } + }, + "callee": { + "type": "MemberExpression", + "start": 130, + "end": 156, + "loc": { + "start": { + "line": 15, + "column": 4 + }, + "end": { + "line": 15, + "column": 30 + } + }, + "object": { + "type": "ArrayExpression", + "start": 130, + "end": 151, + "loc": { + "start": { + "line": 15, + "column": 4 + }, + "end": { + "line": 15, + "column": 25 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 131, + "end": 132, + "loc": { + "start": { + "line": 15, + "column": 5 + }, + "end": { + "line": 15, + "column": 6 + }, + "identifierName": "b" + }, + "name": "b" + }, + { + "type": "Identifier", + "start": 134, + "end": 135, + "loc": { + "start": { + "line": 15, + "column": 8 + }, + "end": { + "line": 15, + "column": 9 + }, + "identifierName": "d" + }, + "name": "d" + }, + { + "type": "SpreadElement", + "start": 137, + "end": 141, + "loc": { + "start": { + "line": 15, + "column": 11 + }, + "end": { + "line": 15, + "column": 15 + } + }, + "argument": { + "type": "Identifier", + "start": 140, + "end": 141, + "loc": { + "start": { + "line": 15, + "column": 14 + }, + "end": { + "line": 15, + "column": 15 + }, + "identifierName": "f" + }, + "name": "f" + } + }, + { + "type": "Identifier", + "start": 143, + "end": 144, + "loc": { + "start": { + "line": 15, + "column": 17 + }, + "end": { + "line": 15, + "column": 18 + }, + "identifierName": "g" + }, + "name": "g" + }, + { + "type": "Identifier", + "start": 146, + "end": 147, + "loc": { + "start": { + "line": 15, + "column": 20 + }, + "end": { + "line": 15, + "column": 21 + }, + "identifierName": "h" + }, + "name": "h" + }, + { + "type": "Identifier", + "start": 149, + "end": 150, + "loc": { + "start": { + "line": 15, + "column": 23 + }, + "end": { + "line": 15, + "column": 24 + }, + "identifierName": "i" + }, + "name": "i" + } + ] + }, + "property": { + "type": "Identifier", + "start": 152, + "end": 156, + "loc": { + "start": { + "line": 15, + "column": 26 + }, + "end": { + "line": 15, + "column": 30 + }, + "identifierName": "join" + }, + "name": "join" + }, + "computed": false + }, + "arguments": [ + { + "type": "StringLiteral", + "start": 157, + "end": 159, + "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/actual.js b/test/fixtures/lightscript/match/destructuring-obj/actual.js new file mode 100644 index 0000000000..f8ef2530ce --- /dev/null +++ b/test/fixtures/lightscript/match/destructuring-obj/actual.js @@ -0,0 +1,14 @@ +match x: + | { a, b } and a > 1: a + b + | { a, b }: a - b + | { a, b = 2 }: a + b - 2 + | { a: 'a', b: 'c', d = 'e' }: [a, b, d].join('') + | { + a: { + b: 'c' + d = 'e' + } + f: { g: 'g', h = 'h' } + }: + [b, d, g, h].join('') + | { a, b: 'b', ...c }: [a, b, c].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..6ed70e17b0 --- /dev/null +++ b/test/fixtures/lightscript/match/destructuring-obj/expected.json @@ -0,0 +1,2158 @@ +{ + "type": "File", + "start": 0, + "end": 288, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 14, + "column": 43 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 288, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 14, + "column": 43 + } + }, + "sourceType": "script", + "body": [ + { + "type": "MatchStatement", + "start": 0, + "end": 288, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 14, + "column": 43 + } + }, + "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": "LogicalExpression", + "start": 13, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "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 + } + } + ] + }, + "operator": "&&", + "right": { + "type": "BinaryExpression", + "start": 26, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "left": { + "type": "Identifier", + "start": 26, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 18 + }, + "identifierName": "a" + }, + "name": "a" + }, + "operator": ">", + "right": { + "type": "NumericLiteral", + "start": 30, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + }, + "consequent": { + "type": "ExpressionStatement", + "start": 33, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 33, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "left": { + "type": "Identifier", + "start": 33, + "end": 34, + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 25 + }, + "identifierName": "a" + }, + "name": "a" + }, + "operator": "+", + "right": { + "type": "Identifier", + "start": 37, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 28 + }, + "end": { + "line": 2, + "column": 29 + }, + "identifierName": "b" + }, + "name": "b" + } + } + } + }, + { + "type": "MatchCase", + "start": 41, + "end": 58, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 19 + } + }, + "test": { + "type": "ObjectExpression", + "start": 43, + "end": 51, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 12 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 45, + "end": 46, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 7 + } + }, + "method": false, + "shorthand": true, + "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": "Identifier", + "start": 45, + "end": 46, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 7 + }, + "identifierName": "a" + }, + "name": "a" + }, + "extra": { + "shorthand": true + } + }, + { + "type": "ObjectProperty", + "start": 48, + "end": 49, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 48, + "end": 49, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 10 + }, + "identifierName": "b" + }, + "name": "b" + }, + "value": { + "type": "Identifier", + "start": 48, + "end": 49, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 10 + }, + "identifierName": "b" + }, + "name": "b" + }, + "extra": { + "shorthand": true + } + } + ] + }, + "consequent": { + "type": "ExpressionStatement", + "start": 53, + "end": 58, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 19 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 53, + "end": 58, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 19 + } + }, + "left": { + "type": "Identifier", + "start": 53, + "end": 54, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + }, + "identifierName": "a" + }, + "name": "a" + }, + "operator": "-", + "right": { + "type": "Identifier", + "start": 57, + "end": 58, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 19 + }, + "identifierName": "b" + }, + "name": "b" + } + } + } + }, + { + "type": "MatchCase", + "start": 61, + "end": 86, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 27 + } + }, + "test": { + "type": "ObjectExpression", + "start": 63, + "end": 75, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 16 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 65, + "end": 66, + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 7 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 65, + "end": 66, + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 7 + }, + "identifierName": "a" + }, + "name": "a" + }, + "value": { + "type": "Identifier", + "start": 65, + "end": 66, + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 7 + }, + "identifierName": "a" + }, + "name": "a" + }, + "extra": { + "shorthand": true + } + }, + { + "type": "ObjectProperty", + "start": 68, + "end": 73, + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 4, + "column": 14 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 68, + "end": 69, + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 4, + "column": 10 + }, + "identifierName": "b" + }, + "name": "b" + }, + "value": { + "type": "AssignmentPattern", + "start": 68, + "end": 73, + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 4, + "column": 14 + } + }, + "left": { + "type": "Identifier", + "start": 68, + "end": 69, + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 4, + "column": 10 + }, + "identifierName": "b" + }, + "name": "b" + }, + "right": { + "type": "NumericLiteral", + "start": 72, + "end": 73, + "loc": { + "start": { + "line": 4, + "column": 13 + }, + "end": { + "line": 4, + "column": 14 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + }, + "extra": { + "shorthand": true + } + } + ] + }, + "consequent": { + "type": "ExpressionStatement", + "start": 77, + "end": 86, + "loc": { + "start": { + "line": 4, + "column": 18 + }, + "end": { + "line": 4, + "column": 27 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 77, + "end": 86, + "loc": { + "start": { + "line": 4, + "column": 18 + }, + "end": { + "line": 4, + "column": 27 + } + }, + "left": { + "type": "BinaryExpression", + "start": 77, + "end": 82, + "loc": { + "start": { + "line": 4, + "column": 18 + }, + "end": { + "line": 4, + "column": 23 + } + }, + "left": { + "type": "Identifier", + "start": 77, + "end": 78, + "loc": { + "start": { + "line": 4, + "column": 18 + }, + "end": { + "line": 4, + "column": 19 + }, + "identifierName": "a" + }, + "name": "a" + }, + "operator": "+", + "right": { + "type": "Identifier", + "start": 81, + "end": 82, + "loc": { + "start": { + "line": 4, + "column": 22 + }, + "end": { + "line": 4, + "column": 23 + }, + "identifierName": "b" + }, + "name": "b" + } + }, + "operator": "-", + "right": { + "type": "NumericLiteral", + "start": 85, + "end": 86, + "loc": { + "start": { + "line": 4, + "column": 26 + }, + "end": { + "line": 4, + "column": 27 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + } + } + }, + { + "type": "MatchCase", + "start": 89, + "end": 138, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 51 + } + }, + "test": { + "type": "ObjectExpression", + "start": 91, + "end": 118, + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 31 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 93, + "end": 99, + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 5, + "column": 12 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 93, + "end": 94, + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 5, + "column": 7 + }, + "identifierName": "a" + }, + "name": "a" + }, + "value": { + "type": "StringLiteral", + "start": 96, + "end": 99, + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 5, + "column": 12 + } + }, + "extra": { + "rawValue": "a", + "raw": "'a'" + }, + "value": "a" + } + }, + { + "type": "ObjectProperty", + "start": 101, + "end": 107, + "loc": { + "start": { + "line": 5, + "column": 14 + }, + "end": { + "line": 5, + "column": 20 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 101, + "end": 102, + "loc": { + "start": { + "line": 5, + "column": 14 + }, + "end": { + "line": 5, + "column": 15 + }, + "identifierName": "b" + }, + "name": "b" + }, + "value": { + "type": "StringLiteral", + "start": 104, + "end": 107, + "loc": { + "start": { + "line": 5, + "column": 17 + }, + "end": { + "line": 5, + "column": 20 + } + }, + "extra": { + "rawValue": "c", + "raw": "'c'" + }, + "value": "c" + } + }, + { + "type": "ObjectProperty", + "start": 109, + "end": 116, + "loc": { + "start": { + "line": 5, + "column": 22 + }, + "end": { + "line": 5, + "column": 29 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 109, + "end": 110, + "loc": { + "start": { + "line": 5, + "column": 22 + }, + "end": { + "line": 5, + "column": 23 + }, + "identifierName": "d" + }, + "name": "d" + }, + "value": { + "type": "AssignmentPattern", + "start": 109, + "end": 116, + "loc": { + "start": { + "line": 5, + "column": 22 + }, + "end": { + "line": 5, + "column": 29 + } + }, + "left": { + "type": "Identifier", + "start": 109, + "end": 110, + "loc": { + "start": { + "line": 5, + "column": 22 + }, + "end": { + "line": 5, + "column": 23 + }, + "identifierName": "d" + }, + "name": "d" + }, + "right": { + "type": "StringLiteral", + "start": 113, + "end": 116, + "loc": { + "start": { + "line": 5, + "column": 26 + }, + "end": { + "line": 5, + "column": 29 + } + }, + "extra": { + "rawValue": "e", + "raw": "'e'" + }, + "value": "e" + } + }, + "extra": { + "shorthand": true + } + } + ] + }, + "consequent": { + "type": "ExpressionStatement", + "start": 120, + "end": 138, + "loc": { + "start": { + "line": 5, + "column": 33 + }, + "end": { + "line": 5, + "column": 51 + } + }, + "expression": { + "type": "CallExpression", + "start": 120, + "end": 138, + "loc": { + "start": { + "line": 5, + "column": 33 + }, + "end": { + "line": 5, + "column": 51 + } + }, + "callee": { + "type": "MemberExpression", + "start": 120, + "end": 134, + "loc": { + "start": { + "line": 5, + "column": 33 + }, + "end": { + "line": 5, + "column": 47 + } + }, + "object": { + "type": "ArrayExpression", + "start": 120, + "end": 129, + "loc": { + "start": { + "line": 5, + "column": 33 + }, + "end": { + "line": 5, + "column": 42 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 121, + "end": 122, + "loc": { + "start": { + "line": 5, + "column": 34 + }, + "end": { + "line": 5, + "column": 35 + }, + "identifierName": "a" + }, + "name": "a" + }, + { + "type": "Identifier", + "start": 124, + "end": 125, + "loc": { + "start": { + "line": 5, + "column": 37 + }, + "end": { + "line": 5, + "column": 38 + }, + "identifierName": "b" + }, + "name": "b" + }, + { + "type": "Identifier", + "start": 127, + "end": 128, + "loc": { + "start": { + "line": 5, + "column": 40 + }, + "end": { + "line": 5, + "column": 41 + }, + "identifierName": "d" + }, + "name": "d" + } + ] + }, + "property": { + "type": "Identifier", + "start": 130, + "end": 134, + "loc": { + "start": { + "line": 5, + "column": 43 + }, + "end": { + "line": 5, + "column": 47 + }, + "identifierName": "join" + }, + "name": "join" + }, + "computed": false + }, + "arguments": [ + { + "type": "StringLiteral", + "start": 135, + "end": 137, + "loc": { + "start": { + "line": 5, + "column": 48 + }, + "end": { + "line": 5, + "column": 50 + } + }, + "extra": { + "rawValue": "", + "raw": "''" + }, + "value": "" + } + ] + } + } + }, + { + "type": "MatchCase", + "start": 141, + "end": 244, + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 13, + "column": 25 + } + }, + "test": { + "type": "ObjectExpression", + "start": 143, + "end": 217, + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 12, + "column": 3 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 149, + "end": 186, + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 10, + "column": 5 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 149, + "end": 150, + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 5 + }, + "identifierName": "a" + }, + "name": "a" + }, + "value": { + "type": "ObjectExpression", + "start": 152, + "end": 186, + "loc": { + "start": { + "line": 7, + "column": 7 + }, + "end": { + "line": 10, + "column": 5 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 160, + "end": 166, + "loc": { + "start": { + "line": 8, + "column": 6 + }, + "end": { + "line": 8, + "column": 12 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 160, + "end": 161, + "loc": { + "start": { + "line": 8, + "column": 6 + }, + "end": { + "line": 8, + "column": 7 + }, + "identifierName": "b" + }, + "name": "b" + }, + "value": { + "type": "StringLiteral", + "start": 163, + "end": 166, + "loc": { + "start": { + "line": 8, + "column": 9 + }, + "end": { + "line": 8, + "column": 12 + } + }, + "extra": { + "rawValue": "c", + "raw": "'c'" + }, + "value": "c" + } + }, + { + "type": "ObjectProperty", + "start": 173, + "end": 180, + "loc": { + "start": { + "line": 9, + "column": 6 + }, + "end": { + "line": 9, + "column": 13 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 173, + "end": 174, + "loc": { + "start": { + "line": 9, + "column": 6 + }, + "end": { + "line": 9, + "column": 7 + }, + "identifierName": "d" + }, + "name": "d" + }, + "value": { + "type": "AssignmentPattern", + "start": 173, + "end": 180, + "loc": { + "start": { + "line": 9, + "column": 6 + }, + "end": { + "line": 9, + "column": 13 + } + }, + "left": { + "type": "Identifier", + "start": 173, + "end": 174, + "loc": { + "start": { + "line": 9, + "column": 6 + }, + "end": { + "line": 9, + "column": 7 + }, + "identifierName": "d" + }, + "name": "d" + }, + "right": { + "type": "StringLiteral", + "start": 177, + "end": 180, + "loc": { + "start": { + "line": 9, + "column": 10 + }, + "end": { + "line": 9, + "column": 13 + } + }, + "extra": { + "rawValue": "e", + "raw": "'e'" + }, + "value": "e" + } + }, + "extra": { + "shorthand": true + } + } + ] + } + }, + { + "type": "ObjectProperty", + "start": 191, + "end": 213, + "loc": { + "start": { + "line": 11, + "column": 4 + }, + "end": { + "line": 11, + "column": 26 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 191, + "end": 192, + "loc": { + "start": { + "line": 11, + "column": 4 + }, + "end": { + "line": 11, + "column": 5 + }, + "identifierName": "f" + }, + "name": "f" + }, + "value": { + "type": "ObjectExpression", + "start": 194, + "end": 213, + "loc": { + "start": { + "line": 11, + "column": 7 + }, + "end": { + "line": 11, + "column": 26 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 196, + "end": 202, + "loc": { + "start": { + "line": 11, + "column": 9 + }, + "end": { + "line": 11, + "column": 15 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 196, + "end": 197, + "loc": { + "start": { + "line": 11, + "column": 9 + }, + "end": { + "line": 11, + "column": 10 + }, + "identifierName": "g" + }, + "name": "g" + }, + "value": { + "type": "StringLiteral", + "start": 199, + "end": 202, + "loc": { + "start": { + "line": 11, + "column": 12 + }, + "end": { + "line": 11, + "column": 15 + } + }, + "extra": { + "rawValue": "g", + "raw": "'g'" + }, + "value": "g" + } + }, + { + "type": "ObjectProperty", + "start": 204, + "end": 211, + "loc": { + "start": { + "line": 11, + "column": 17 + }, + "end": { + "line": 11, + "column": 24 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 204, + "end": 205, + "loc": { + "start": { + "line": 11, + "column": 17 + }, + "end": { + "line": 11, + "column": 18 + }, + "identifierName": "h" + }, + "name": "h" + }, + "value": { + "type": "AssignmentPattern", + "start": 204, + "end": 211, + "loc": { + "start": { + "line": 11, + "column": 17 + }, + "end": { + "line": 11, + "column": 24 + } + }, + "left": { + "type": "Identifier", + "start": 204, + "end": 205, + "loc": { + "start": { + "line": 11, + "column": 17 + }, + "end": { + "line": 11, + "column": 18 + }, + "identifierName": "h" + }, + "name": "h" + }, + "right": { + "type": "StringLiteral", + "start": 208, + "end": 211, + "loc": { + "start": { + "line": 11, + "column": 21 + }, + "end": { + "line": 11, + "column": 24 + } + }, + "extra": { + "rawValue": "h", + "raw": "'h'" + }, + "value": "h" + } + }, + "extra": { + "shorthand": true + } + } + ] + } + } + ] + }, + "consequent": { + "type": "BlockStatement", + "start": 217, + "end": 244, + "loc": { + "start": { + "line": 12, + "column": 3 + }, + "end": { + "line": 13, + "column": 25 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 223, + "end": 244, + "loc": { + "start": { + "line": 13, + "column": 4 + }, + "end": { + "line": 13, + "column": 25 + } + }, + "expression": { + "type": "CallExpression", + "start": 223, + "end": 244, + "loc": { + "start": { + "line": 13, + "column": 4 + }, + "end": { + "line": 13, + "column": 25 + } + }, + "callee": { + "type": "MemberExpression", + "start": 223, + "end": 240, + "loc": { + "start": { + "line": 13, + "column": 4 + }, + "end": { + "line": 13, + "column": 21 + } + }, + "object": { + "type": "ArrayExpression", + "start": 223, + "end": 235, + "loc": { + "start": { + "line": 13, + "column": 4 + }, + "end": { + "line": 13, + "column": 16 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 224, + "end": 225, + "loc": { + "start": { + "line": 13, + "column": 5 + }, + "end": { + "line": 13, + "column": 6 + }, + "identifierName": "b" + }, + "name": "b" + }, + { + "type": "Identifier", + "start": 227, + "end": 228, + "loc": { + "start": { + "line": 13, + "column": 8 + }, + "end": { + "line": 13, + "column": 9 + }, + "identifierName": "d" + }, + "name": "d" + }, + { + "type": "Identifier", + "start": 230, + "end": 231, + "loc": { + "start": { + "line": 13, + "column": 11 + }, + "end": { + "line": 13, + "column": 12 + }, + "identifierName": "g" + }, + "name": "g" + }, + { + "type": "Identifier", + "start": 233, + "end": 234, + "loc": { + "start": { + "line": 13, + "column": 14 + }, + "end": { + "line": 13, + "column": 15 + }, + "identifierName": "h" + }, + "name": "h" + } + ] + }, + "property": { + "type": "Identifier", + "start": 236, + "end": 240, + "loc": { + "start": { + "line": 13, + "column": 17 + }, + "end": { + "line": 13, + "column": 21 + }, + "identifierName": "join" + }, + "name": "join" + }, + "computed": false + }, + "arguments": [ + { + "type": "StringLiteral", + "start": 241, + "end": 243, + "loc": { + "start": { + "line": 13, + "column": 22 + }, + "end": { + "line": 13, + "column": 24 + } + }, + "extra": { + "rawValue": "", + "raw": "''" + }, + "value": "" + } + ] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + }, + { + "type": "MatchCase", + "start": 247, + "end": 288, + "loc": { + "start": { + "line": 14, + "column": 2 + }, + "end": { + "line": 14, + "column": 43 + } + }, + "test": { + "type": "ObjectExpression", + "start": 249, + "end": 268, + "loc": { + "start": { + "line": 14, + "column": 4 + }, + "end": { + "line": 14, + "column": 23 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 251, + "end": 252, + "loc": { + "start": { + "line": 14, + "column": 6 + }, + "end": { + "line": 14, + "column": 7 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 251, + "end": 252, + "loc": { + "start": { + "line": 14, + "column": 6 + }, + "end": { + "line": 14, + "column": 7 + }, + "identifierName": "a" + }, + "name": "a" + }, + "value": { + "type": "Identifier", + "start": 251, + "end": 252, + "loc": { + "start": { + "line": 14, + "column": 6 + }, + "end": { + "line": 14, + "column": 7 + }, + "identifierName": "a" + }, + "name": "a" + }, + "extra": { + "shorthand": true + } + }, + { + "type": "ObjectProperty", + "start": 254, + "end": 260, + "loc": { + "start": { + "line": 14, + "column": 9 + }, + "end": { + "line": 14, + "column": 15 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 254, + "end": 255, + "loc": { + "start": { + "line": 14, + "column": 9 + }, + "end": { + "line": 14, + "column": 10 + }, + "identifierName": "b" + }, + "name": "b" + }, + "value": { + "type": "StringLiteral", + "start": 257, + "end": 260, + "loc": { + "start": { + "line": 14, + "column": 12 + }, + "end": { + "line": 14, + "column": 15 + } + }, + "extra": { + "rawValue": "b", + "raw": "'b'" + }, + "value": "b" + } + }, + { + "type": "SpreadProperty", + "start": 262, + "end": 266, + "loc": { + "start": { + "line": 14, + "column": 17 + }, + "end": { + "line": 14, + "column": 21 + } + }, + "argument": { + "type": "Identifier", + "start": 265, + "end": 266, + "loc": { + "start": { + "line": 14, + "column": 20 + }, + "end": { + "line": 14, + "column": 21 + }, + "identifierName": "c" + }, + "name": "c" + } + } + ] + }, + "consequent": { + "type": "ExpressionStatement", + "start": 270, + "end": 288, + "loc": { + "start": { + "line": 14, + "column": 25 + }, + "end": { + "line": 14, + "column": 43 + } + }, + "expression": { + "type": "CallExpression", + "start": 270, + "end": 288, + "loc": { + "start": { + "line": 14, + "column": 25 + }, + "end": { + "line": 14, + "column": 43 + } + }, + "callee": { + "type": "MemberExpression", + "start": 270, + "end": 284, + "loc": { + "start": { + "line": 14, + "column": 25 + }, + "end": { + "line": 14, + "column": 39 + } + }, + "object": { + "type": "ArrayExpression", + "start": 270, + "end": 279, + "loc": { + "start": { + "line": 14, + "column": 25 + }, + "end": { + "line": 14, + "column": 34 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 271, + "end": 272, + "loc": { + "start": { + "line": 14, + "column": 26 + }, + "end": { + "line": 14, + "column": 27 + }, + "identifierName": "a" + }, + "name": "a" + }, + { + "type": "Identifier", + "start": 274, + "end": 275, + "loc": { + "start": { + "line": 14, + "column": 29 + }, + "end": { + "line": 14, + "column": 30 + }, + "identifierName": "b" + }, + "name": "b" + }, + { + "type": "Identifier", + "start": 277, + "end": 278, + "loc": { + "start": { + "line": 14, + "column": 32 + }, + "end": { + "line": 14, + "column": 33 + }, + "identifierName": "c" + }, + "name": "c" + } + ] + }, + "property": { + "type": "Identifier", + "start": 280, + "end": 284, + "loc": { + "start": { + "line": 14, + "column": 35 + }, + "end": { + "line": 14, + "column": 39 + }, + "identifierName": "join" + }, + "name": "join" + }, + "computed": false + }, + "arguments": [ + { + "type": "StringLiteral", + "start": 285, + "end": 287, + "loc": { + "start": { + "line": 14, + "column": 40 + }, + "end": { + "line": 14, + "column": 42 + } + }, + "extra": { + "rawValue": "", + "raw": "''" + }, + "value": "" + } + ] + } + } + } + ] + } + ], + "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/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-as/actual.js b/test/fixtures/lightscript/match/illegal-destructure-and-as/actual.js new file mode 100644 index 0000000000..98e7a41ca7 --- /dev/null +++ b/test/fixtures/lightscript/match/illegal-destructure-and-as/actual.js @@ -0,0 +1,2 @@ +match x: + | { a } as obj: "not allowed" diff --git a/test/fixtures/lightscript/match/illegal-destructure-and-as/options.json b/test/fixtures/lightscript/match/illegal-destructure-and-as/options.json new file mode 100644 index 0000000000..c13a638b56 --- /dev/null +++ b/test/fixtures/lightscript/match/illegal-destructure-and-as/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Cannot rename after destructuring. (2:10)" +} 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-multi-pattern-1/actual.js b/test/fixtures/lightscript/match/illegal-multi-pattern-1/actual.js new file mode 100644 index 0000000000..224b73451e --- /dev/null +++ b/test/fixtures/lightscript/match/illegal-multi-pattern-1/actual.js @@ -0,0 +1,2 @@ +match x: + | true and {a} or [a]: "not allowed" diff --git a/test/fixtures/lightscript/match/illegal-multi-pattern-1/options.json b/test/fixtures/lightscript/match/illegal-multi-pattern-1/options.json new file mode 100644 index 0000000000..46a08cef29 --- /dev/null +++ b/test/fixtures/lightscript/match/illegal-multi-pattern-1/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Only one pattern allowed per match case test. (2:20)" +} diff --git a/test/fixtures/lightscript/match/illegal-multi-pattern-2/actual.js b/test/fixtures/lightscript/match/illegal-multi-pattern-2/actual.js new file mode 100644 index 0000000000..bde1ba7de3 --- /dev/null +++ b/test/fixtures/lightscript/match/illegal-multi-pattern-2/actual.js @@ -0,0 +1,2 @@ +match x: + | true and {a} or {a}: "not allowed" diff --git a/test/fixtures/lightscript/match/illegal-multi-pattern-2/options.json b/test/fixtures/lightscript/match/illegal-multi-pattern-2/options.json new file mode 100644 index 0000000000..46a08cef29 --- /dev/null +++ b/test/fixtures/lightscript/match/illegal-multi-pattern-2/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Only one pattern allowed per match case test. (2:20)" +} diff --git a/test/fixtures/lightscript/match/illegal-multi-pattern-3/actual.js b/test/fixtures/lightscript/match/illegal-multi-pattern-3/actual.js new file mode 100644 index 0000000000..290fd5e05d --- /dev/null +++ b/test/fixtures/lightscript/match/illegal-multi-pattern-3/actual.js @@ -0,0 +1,2 @@ +match x: + | true and [a] or {a}: "not allowed" diff --git a/test/fixtures/lightscript/match/illegal-multi-pattern-3/options.json b/test/fixtures/lightscript/match/illegal-multi-pattern-3/options.json new file mode 100644 index 0000000000..46a08cef29 --- /dev/null +++ b/test/fixtures/lightscript/match/illegal-multi-pattern-3/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Only one pattern allowed per match case test. (2:20)" +} diff --git a/test/fixtures/lightscript/match/illegal-multi-pattern-4/actual.js b/test/fixtures/lightscript/match/illegal-multi-pattern-4/actual.js new file mode 100644 index 0000000000..88d6ac8804 --- /dev/null +++ b/test/fixtures/lightscript/match/illegal-multi-pattern-4/actual.js @@ -0,0 +1,2 @@ +match x: + | true and [a] or [a]: "not allowed" diff --git a/test/fixtures/lightscript/match/illegal-multi-pattern-4/options.json b/test/fixtures/lightscript/match/illegal-multi-pattern-4/options.json new file mode 100644 index 0000000000..46a08cef29 --- /dev/null +++ b/test/fixtures/lightscript/match/illegal-multi-pattern-4/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Only one pattern allowed per match case test. (2:20)" +} 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-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/nested/actual.js b/test/fixtures/lightscript/match/nested/actual.js index 2b273e8b75..7c75d0c9bd 100644 --- a/test/fixtures/lightscript/match/nested/actual.js +++ b/test/fixtures/lightscript/match/nested/actual.js @@ -1,5 +1,5 @@ match x: - | > 2 with y: match y: + | > 2 as y: match y: | > 10: "soo big" | > 5: "still pretty big" | else: "kinda big" diff --git a/test/fixtures/lightscript/match/nested/expected.json b/test/fixtures/lightscript/match/nested/expected.json index 75d517152a..0385cfcc7e 100644 --- a/test/fixtures/lightscript/match/nested/expected.json +++ b/test/fixtures/lightscript/match/nested/expected.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 138, + "end": 136, "loc": { "start": { "line": 1, @@ -15,7 +15,7 @@ "program": { "type": "Program", "start": 0, - "end": 138, + "end": 136, "loc": { "start": { "line": 1, @@ -31,7 +31,7 @@ { "type": "MatchStatement", "start": 0, - "end": 138, + "end": 136, "loc": { "start": { "line": 1, @@ -63,7 +63,7 @@ { "type": "MatchCase", "start": 11, - "end": 109, + "end": 107, "loc": { "start": { "line": 2, @@ -127,16 +127,16 @@ }, "binding": { "type": "Identifier", - "start": 22, - "end": 23, + "start": 20, + "end": 21, "loc": { "start": { "line": 2, - "column": 13 + "column": 11 }, "end": { "line": 2, - "column": 14 + "column": 12 }, "identifierName": "y" }, @@ -144,12 +144,12 @@ }, "consequent": { "type": "MatchStatement", - "start": 25, - "end": 109, + "start": 23, + "end": 107, "loc": { "start": { "line": 2, - "column": 16 + "column": 14 }, "end": { "line": 5, @@ -158,16 +158,16 @@ }, "discriminant": { "type": "Identifier", - "start": 31, - "end": 32, + "start": 29, + "end": 30, "loc": { "start": { "line": 2, - "column": 22 + "column": 20 }, "end": { "line": 2, - "column": 23 + "column": 21 }, "identifierName": "y" }, @@ -176,8 +176,8 @@ "cases": [ { "type": "MatchCase", - "start": 38, - "end": 55, + "start": 36, + "end": 53, "loc": { "start": { "line": 3, @@ -190,8 +190,8 @@ }, "test": { "type": "BinaryExpression", - "start": 40, - "end": 44, + "start": 38, + "end": 42, "loc": { "start": { "line": 3, @@ -204,8 +204,8 @@ }, "left": { "type": "PlaceholderExpression", - "start": 39, - "end": 40, + "start": 37, + "end": 38, "loc": { "start": { "line": 3, @@ -220,8 +220,8 @@ "operator": ">", "right": { "type": "NumericLiteral", - "start": 42, - "end": 44, + "start": 40, + "end": 42, "loc": { "start": { "line": 3, @@ -241,8 +241,8 @@ }, "consequent": { "type": "ExpressionStatement", - "start": 46, - "end": 55, + "start": 44, + "end": 53, "loc": { "start": { "line": 3, @@ -255,8 +255,8 @@ }, "expression": { "type": "StringLiteral", - "start": 46, - "end": 55, + "start": 44, + "end": 53, "loc": { "start": { "line": 3, @@ -277,8 +277,8 @@ }, { "type": "MatchCase", - "start": 60, - "end": 85, + "start": 58, + "end": 83, "loc": { "start": { "line": 4, @@ -291,8 +291,8 @@ }, "test": { "type": "BinaryExpression", - "start": 62, - "end": 65, + "start": 60, + "end": 63, "loc": { "start": { "line": 4, @@ -305,8 +305,8 @@ }, "left": { "type": "PlaceholderExpression", - "start": 61, - "end": 62, + "start": 59, + "end": 60, "loc": { "start": { "line": 4, @@ -321,8 +321,8 @@ "operator": ">", "right": { "type": "NumericLiteral", - "start": 64, - "end": 65, + "start": 62, + "end": 63, "loc": { "start": { "line": 4, @@ -342,8 +342,8 @@ }, "consequent": { "type": "ExpressionStatement", - "start": 67, - "end": 85, + "start": 65, + "end": 83, "loc": { "start": { "line": 4, @@ -356,8 +356,8 @@ }, "expression": { "type": "StringLiteral", - "start": 67, - "end": 85, + "start": 65, + "end": 83, "loc": { "start": { "line": 4, @@ -378,8 +378,8 @@ }, { "type": "MatchCase", - "start": 90, - "end": 109, + "start": 88, + "end": 107, "loc": { "start": { "line": 5, @@ -392,8 +392,8 @@ }, "test": { "type": "MatchElse", - "start": 92, - "end": 96, + "start": 90, + "end": 94, "loc": { "start": { "line": 5, @@ -407,8 +407,8 @@ }, "consequent": { "type": "ExpressionStatement", - "start": 98, - "end": 109, + "start": 96, + "end": 107, "loc": { "start": { "line": 5, @@ -421,8 +421,8 @@ }, "expression": { "type": "StringLiteral", - "start": 98, - "end": 109, + "start": 96, + "end": 107, "loc": { "start": { "line": 5, @@ -446,8 +446,8 @@ }, { "type": "MatchCase", - "start": 112, - "end": 138, + "start": 110, + "end": 136, "loc": { "start": { "line": 6, @@ -460,8 +460,8 @@ }, "test": { "type": "MatchElse", - "start": 114, - "end": 118, + "start": 112, + "end": 116, "loc": { "start": { "line": 6, @@ -475,8 +475,8 @@ }, "consequent": { "type": "ExpressionStatement", - "start": 120, - "end": 138, + "start": 118, + "end": 136, "loc": { "start": { "line": 6, @@ -489,8 +489,8 @@ }, "expression": { "type": "StringLiteral", - "start": 120, - "end": 138, + "start": 118, + "end": 136, "loc": { "start": { "line": 6, diff --git a/test/fixtures/lightscript/match/parenthesized-destructuring-illegal/actual.js b/test/fixtures/lightscript/match/parenthesized-destructuring-illegal/actual.js index c9be8589a1..d5037008b6 100644 --- a/test/fixtures/lightscript/match/parenthesized-destructuring-illegal/actual.js +++ b/test/fixtures/lightscript/match/parenthesized-destructuring-illegal/actual.js @@ -1,4 +1,2 @@ a = match x: - | 3 with (three): three - | 4 with ({ four = 4 }): four - | 5 with ({ five = 5 }): five + | 3 as (three): three diff --git a/test/fixtures/lightscript/match/parenthesized-destructuring-illegal/options.json b/test/fixtures/lightscript/match/parenthesized-destructuring-illegal/options.json index 8551537138..3c68e9be75 100644 --- a/test/fixtures/lightscript/match/parenthesized-destructuring-illegal/options.json +++ b/test/fixtures/lightscript/match/parenthesized-destructuring-illegal/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token (2:11)" + "throws": "Unexpected token (2:9)" } diff --git a/test/fixtures/lightscript/match/subscripts/actual.js b/test/fixtures/lightscript/match/subscripts/actual.js index e0a896a349..62d4889664 100644 --- a/test/fixtures/lightscript/match/subscripts/actual.js +++ b/test/fixtures/lightscript/match/subscripts/actual.js @@ -1,6 +1,5 @@ match x: | .a: 'has a' - | ['b']: 'has b' | ?.c: 'has c' | ?[d]: 'has d' | .0: 'has first elem' diff --git a/test/fixtures/lightscript/match/subscripts/expected.json b/test/fixtures/lightscript/match/subscripts/expected.json index 50cdba6448..432b459e6c 100644 --- a/test/fixtures/lightscript/match/subscripts/expected.json +++ b/test/fixtures/lightscript/match/subscripts/expected.json @@ -1,28 +1,28 @@ { "type": "File", "start": 0, - "end": 135, + "end": 116, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 7, + "line": 6, "column": 31 } }, "program": { "type": "Program", "start": 0, - "end": 135, + "end": 116, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 7, + "line": 6, "column": 31 } }, @@ -31,14 +31,14 @@ { "type": "MatchStatement", "start": 0, - "end": 135, + "end": 116, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 7, + "line": 6, "column": 31 } }, @@ -161,7 +161,7 @@ { "type": "MatchCase", "start": 27, - "end": 43, + "end": 41, "loc": { "start": { "line": 3, @@ -169,13 +169,13 @@ }, "end": { "line": 3, - "column": 18 + "column": 16 } }, "test": { - "type": "ArrayExpression", + "type": "SafeMemberExpression", "start": 29, - "end": 34, + "end": 32, "loc": { "start": { "line": 3, @@ -183,122 +183,35 @@ }, "end": { "line": 3, - "column": 9 - } - }, - "elements": [ - { - "type": "StringLiteral", - "start": 30, - "end": 33, - "loc": { - "start": { - "line": 3, - "column": 5 - }, - "end": { - "line": 3, - "column": 8 - } - }, - "extra": { - "rawValue": "b", - "raw": "'b'" - }, - "value": "b" - } - ] - }, - "consequent": { - "type": "ExpressionStatement", - "start": 36, - "end": 43, - "loc": { - "start": { - "line": 3, - "column": 11 - }, - "end": { - "line": 3, - "column": 18 - } - }, - "expression": { - "type": "StringLiteral", - "start": 36, - "end": 43, - "loc": { - "start": { - "line": 3, - "column": 11 - }, - "end": { - "line": 3, - "column": 18 - } - }, - "extra": { - "rawValue": "has b", - "raw": "'has b'" - }, - "value": "has b" - } - } - }, - { - "type": "MatchCase", - "start": 46, - "end": 60, - "loc": { - "start": { - "line": 4, - "column": 2 - }, - "end": { - "line": 4, - "column": 16 - } - }, - "test": { - "type": "SafeMemberExpression", - "start": 48, - "end": 51, - "loc": { - "start": { - "line": 4, - "column": 4 - }, - "end": { - "line": 4, "column": 7 } }, "object": { "type": "PlaceholderExpression", - "start": 47, - "end": 48, + "start": 28, + "end": 29, "loc": { "start": { - "line": 4, + "line": 3, "column": 3 }, "end": { - "line": 4, + "line": 3, "column": 4 } } }, "property": { "type": "Identifier", - "start": 50, - "end": 51, + "start": 31, + "end": 32, "loc": { "start": { - "line": 4, + "line": 3, "column": 6 }, "end": { - "line": 4, + "line": 3, "column": 7 }, "identifierName": "c" @@ -309,29 +222,29 @@ }, "consequent": { "type": "ExpressionStatement", - "start": 53, - "end": 60, + "start": 34, + "end": 41, "loc": { "start": { - "line": 4, + "line": 3, "column": 9 }, "end": { - "line": 4, + "line": 3, "column": 16 } }, "expression": { "type": "StringLiteral", - "start": 53, - "end": 60, + "start": 34, + "end": 41, "loc": { "start": { - "line": 4, + "line": 3, "column": 9 }, "end": { - "line": 4, + "line": 3, "column": 16 } }, @@ -345,58 +258,58 @@ }, { "type": "MatchCase", - "start": 63, - "end": 78, + "start": 44, + "end": 59, "loc": { "start": { - "line": 5, + "line": 4, "column": 2 }, "end": { - "line": 5, + "line": 4, "column": 17 } }, "test": { "type": "SafeMemberExpression", - "start": 65, - "end": 69, + "start": 46, + "end": 50, "loc": { "start": { - "line": 5, + "line": 4, "column": 4 }, "end": { - "line": 5, + "line": 4, "column": 8 } }, "object": { "type": "PlaceholderExpression", - "start": 64, - "end": 65, + "start": 45, + "end": 46, "loc": { "start": { - "line": 5, + "line": 4, "column": 3 }, "end": { - "line": 5, + "line": 4, "column": 4 } } }, "property": { "type": "Identifier", - "start": 67, - "end": 68, + "start": 48, + "end": 49, "loc": { "start": { - "line": 5, + "line": 4, "column": 6 }, "end": { - "line": 5, + "line": 4, "column": 7 }, "identifierName": "d" @@ -407,29 +320,29 @@ }, "consequent": { "type": "ExpressionStatement", - "start": 71, - "end": 78, + "start": 52, + "end": 59, "loc": { "start": { - "line": 5, + "line": 4, "column": 10 }, "end": { - "line": 5, + "line": 4, "column": 17 } }, "expression": { "type": "StringLiteral", - "start": 71, - "end": 78, + "start": 52, + "end": 59, "loc": { "start": { - "line": 5, + "line": 4, "column": 10 }, "end": { - "line": 5, + "line": 4, "column": 17 } }, @@ -443,58 +356,58 @@ }, { "type": "MatchCase", - "start": 81, - "end": 103, + "start": 62, + "end": 84, "loc": { "start": { - "line": 6, + "line": 5, "column": 2 }, "end": { - "line": 6, + "line": 5, "column": 24 } }, "test": { "type": "MemberExpression", - "start": 83, - "end": 85, + "start": 64, + "end": 66, "loc": { "start": { - "line": 6, + "line": 5, "column": 4 }, "end": { - "line": 6, + "line": 5, "column": 6 } }, "object": { "type": "PlaceholderExpression", - "start": 82, - "end": 83, + "start": 63, + "end": 64, "loc": { "start": { - "line": 6, + "line": 5, "column": 3 }, "end": { - "line": 6, + "line": 5, "column": 4 } } }, "property": { "type": "NumericLiteral", - "start": 84, - "end": 85, + "start": 65, + "end": 66, "loc": { "start": { - "line": 6, + "line": 5, "column": 5 }, "end": { - "line": 6, + "line": 5, "column": 6 } }, @@ -508,29 +421,29 @@ }, "consequent": { "type": "ExpressionStatement", - "start": 87, - "end": 103, + "start": 68, + "end": 84, "loc": { "start": { - "line": 6, + "line": 5, "column": 8 }, "end": { - "line": 6, + "line": 5, "column": 24 } }, "expression": { "type": "StringLiteral", - "start": 87, - "end": 103, + "start": 68, + "end": 84, "loc": { "start": { - "line": 6, + "line": 5, "column": 8 }, "end": { - "line": 6, + "line": 5, "column": 24 } }, @@ -544,58 +457,58 @@ }, { "type": "MatchCase", - "start": 106, - "end": 135, + "start": 87, + "end": 116, "loc": { "start": { - "line": 7, + "line": 6, "column": 2 }, "end": { - "line": 7, + "line": 6, "column": 31 } }, "test": { "type": "TildeCallExpression", - "start": 108, - "end": 121, + "start": 89, + "end": 102, "loc": { "start": { - "line": 7, + "line": 6, "column": 4 }, "end": { - "line": 7, + "line": 6, "column": 17 } }, "left": { "type": "PlaceholderExpression", - "start": 107, - "end": 108, + "start": 88, + "end": 89, "loc": { "start": { - "line": 7, + "line": 6, "column": 3 }, "end": { - "line": 7, + "line": 6, "column": 4 } } }, "right": { "type": "Identifier", - "start": 109, - "end": 119, + "start": 90, + "end": 100, "loc": { "start": { - "line": 7, + "line": 6, "column": 5 }, "end": { - "line": 7, + "line": 6, "column": 15 }, "identifierName": "isFunction" @@ -606,29 +519,29 @@ }, "consequent": { "type": "ExpressionStatement", - "start": 123, - "end": 135, + "start": 104, + "end": 116, "loc": { "start": { - "line": 7, + "line": 6, "column": 19 }, "end": { - "line": 7, + "line": 6, "column": 31 } }, "expression": { "type": "StringLiteral", - "start": 123, - "end": 135, + "start": 104, + "end": 116, "loc": { "start": { - "line": 7, + "line": 6, "column": 19 }, "end": { - "line": 7, + "line": 6, "column": 31 } }, From 837a35815151da8eb6f3e60aab59199b7c37b27b Mon Sep 17 00:00:00 2001 From: Alex Rattray Date: Sat, 3 Jun 2017 09:14:36 -0700 Subject: [PATCH 05/12] Destructure as patterns, allow destructured 'as' --- src/parser/expression.js | 6 +- src/plugins/lightscript.js | 11 +- .../actual.js | 0 .../expected.json | 0 .../match/destructured-renaming/actual.js | 3 + .../match/destructured-renaming/expected.json | 607 +++++++ .../match/destructuring-arr/actual.js | 5 +- .../match/destructuring-arr/expected.json | 639 ++----- .../destructuring-obj-arr-mixed/actual.js | 2 +- .../destructuring-obj-arr-mixed/expected.json | 181 +- .../match/destructuring-obj/actual.js | 11 +- .../match/destructuring-obj/expected.json | 1520 ++++++----------- 12 files changed, 1403 insertions(+), 1582 deletions(-) rename test/fixtures/lightscript/match/{basic-destructuring => basic-renaming}/actual.js (100%) rename test/fixtures/lightscript/match/{basic-destructuring => basic-renaming}/expected.json (100%) create mode 100644 test/fixtures/lightscript/match/destructured-renaming/actual.js create mode 100644 test/fixtures/lightscript/match/destructured-renaming/expected.json diff --git a/src/parser/expression.js b/src/parser/expression.js index b299d09c89..563d2ae522 100644 --- a/src/parser/expression.js +++ b/src/parser/expression.js @@ -678,8 +678,7 @@ pp.parseExprAtom = function (refShorthandDefaultPos) { return this.parseParenAndDistinguishExpression(null, null, canBeArrow); case tt.bracketL: - if (this.hasPlugin("lightscript") && this.state.inMatchCaseTest && !refShorthandDefaultPos) { - // re-enter this fn, but with refShorthandDefaultPos and state tracking + if (this.hasPlugin("lightscript") && this.state.inMatchCaseTest) { return this.parseMatchCaseTestPattern(); } node = this.startNode(); @@ -692,8 +691,7 @@ pp.parseExprAtom = function (refShorthandDefaultPos) { return this.finishNode(node, "ArrayExpression"); case tt.braceL: - if (this.hasPlugin("lightscript") && this.state.inMatchCaseTest && !refShorthandDefaultPos) { - // re-enter this fn, but with refShorthandDefaultPos and state tracking + if (this.hasPlugin("lightscript") && this.state.inMatchCaseTest) { return this.parseMatchCaseTestPattern(); } return this.parseObj(false, refShorthandDefaultPos); diff --git a/src/plugins/lightscript.js b/src/plugins/lightscript.js index 12c6f88eac..ee60c0b723 100644 --- a/src/plugins/lightscript.js +++ b/src/plugins/lightscript.js @@ -593,15 +593,16 @@ pp.parseMatch = function (node, isExpression) { pp.parseMatchCase = function (isExpression) { const node = this.startNode(); + this.state.allowMatchCaseTestPattern = true; node.test = this.parseMatchCaseTest(); - if (this.isContextual("as")) { if (!this.state.allowMatchCaseTestPattern) { this.unexpected(null, "Cannot rename after destructuring."); } this.next(); - node.binding = this.parseIdentifier(); + node.binding = this.parseBindingAtom(); } + this.state.allowMatchCaseTestPattern = false; if (isExpression) { // disallow return/continue/break, etc. c/p doExpression @@ -624,7 +625,6 @@ pp.parseMatchCase = function (isExpression) { pp.parseMatchCaseTest = function () { // can't be nested so no need to read/restore old value this.state.inMatchCaseTest = true; - this.state.allowMatchCaseTestPattern = true; this.expect(tt.bitwiseOR); if (this.isLineBreak()) this.unexpected(this.state.lastTokEnd, "Illegal newline."); @@ -639,7 +639,6 @@ pp.parseMatchCaseTest = function () { } this.state.inMatchCaseTest = false; - this.state.allowMatchCaseTestPattern = false; return test; }; @@ -686,9 +685,7 @@ pp.parseMatchCaseTestPattern = function () { const oldInMatchCaseTestPattern = this.state.inMatchCaseTestPattern; this.state.inMatchCaseTestPattern = true; - // re-enter parent function, allowing patterns. - const refShorthandDefaultPos = { start: 0 }; - const node = this.parseExprAtom(refShorthandDefaultPos); + const node = this.parseBindingAtom(); // once we have finished recursing through a pattern, disallow future patterns this.state.inMatchCaseTestPattern = oldInMatchCaseTestPattern; diff --git a/test/fixtures/lightscript/match/basic-destructuring/actual.js b/test/fixtures/lightscript/match/basic-renaming/actual.js similarity index 100% rename from test/fixtures/lightscript/match/basic-destructuring/actual.js rename to test/fixtures/lightscript/match/basic-renaming/actual.js diff --git a/test/fixtures/lightscript/match/basic-destructuring/expected.json b/test/fixtures/lightscript/match/basic-renaming/expected.json similarity index 100% rename from test/fixtures/lightscript/match/basic-destructuring/expected.json rename to test/fixtures/lightscript/match/basic-renaming/expected.json 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..1428670473 --- /dev/null +++ b/test/fixtures/lightscript/match/destructured-renaming/actual.js @@ -0,0 +1,3 @@ +match x: + | .a as { a, b = 1 }: a + b + | .0 and .1 as [ 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..1759e1ddfc --- /dev/null +++ b/test/fixtures/lightscript/match/destructured-renaming/expected.json @@ -0,0 +1,607 @@ +{ + "type": "File", + "start": 0, + "end": 71, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 32 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 71, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 32 + } + }, + "sourceType": "script", + "body": [ + { + "type": "MatchStatement", + "start": 0, + "end": 71, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 32 + } + }, + "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": "MemberExpression", + "start": 13, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "object": { + "type": "PlaceholderExpression", + "start": 12, + "end": 13, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + } + } + }, + "property": { + "type": "Identifier", + "start": 14, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 6 + }, + "identifierName": "a" + }, + "name": "a" + }, + "computed": false + }, + "binding": { + "type": "ObjectPattern", + "start": 19, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 21, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 21, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 13 + }, + "identifierName": "a" + }, + "name": "a" + }, + "value": { + "type": "Identifier", + "start": 21, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 13 + }, + "identifierName": "a" + }, + "name": "a" + }, + "extra": { + "shorthand": true + } + }, + { + "type": "ObjectProperty", + "start": 24, + "end": 29, + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "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": "b" + }, + "name": "b" + }, + "value": { + "type": "AssignmentPattern", + "start": 24, + "end": 29, + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "left": { + "type": "Identifier", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 16 + }, + "identifierName": "b" + }, + "name": "b" + }, + "right": { + "type": "NumericLiteral", + "start": 28, + "end": 29, + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + }, + "extra": { + "shorthand": true + } + } + ] + }, + "consequent": { + "type": "ExpressionStatement", + "start": 33, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 33, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "left": { + "type": "Identifier", + "start": 33, + "end": 34, + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 25 + }, + "identifierName": "a" + }, + "name": "a" + }, + "operator": "+", + "right": { + "type": "Identifier", + "start": 37, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 28 + }, + "end": { + "line": 2, + "column": 29 + }, + "identifierName": "b" + }, + "name": "b" + } + } + } + }, + { + "type": "MatchCase", + "start": 41, + "end": 71, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 32 + } + }, + "test": { + "type": "LogicalExpression", + "start": 43, + "end": 52, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "left": { + "type": "MemberExpression", + "start": 43, + "end": 45, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 6 + } + }, + "object": { + "type": "PlaceholderExpression", + "start": 42, + "end": 43, + "loc": { + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 4 + } + } + }, + "property": { + "type": "NumericLiteral", + "start": 44, + "end": 45, + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 6 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + }, + "computed": true + }, + "operator": "&&", + "right": { + "type": "MemberExpression", + "start": 50, + "end": 52, + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "object": { + "type": "PlaceholderExpression", + "start": 49, + "end": 50, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + } + } + }, + "property": { + "type": "NumericLiteral", + "start": 51, + "end": 52, + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + }, + "computed": true + } + }, + "binding": { + "type": "ArrayPattern", + "start": 56, + "end": 64, + "loc": { + "start": { + "line": 3, + "column": 17 + }, + "end": { + "line": 3, + "column": 25 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 58, + "end": 59, + "loc": { + "start": { + "line": 3, + "column": 19 + }, + "end": { + "line": 3, + "column": 20 + }, + "identifierName": "a" + }, + "name": "a" + }, + { + "type": "Identifier", + "start": 61, + "end": 62, + "loc": { + "start": { + "line": 3, + "column": 22 + }, + "end": { + "line": 3, + "column": 23 + }, + "identifierName": "b" + }, + "name": "b" + } + ] + }, + "consequent": { + "type": "ExpressionStatement", + "start": 66, + "end": 71, + "loc": { + "start": { + "line": 3, + "column": 27 + }, + "end": { + "line": 3, + "column": 32 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 66, + "end": 71, + "loc": { + "start": { + "line": 3, + "column": 27 + }, + "end": { + "line": 3, + "column": 32 + } + }, + "left": { + "type": "Identifier", + "start": 66, + "end": 67, + "loc": { + "start": { + "line": 3, + "column": 27 + }, + "end": { + "line": 3, + "column": 28 + }, + "identifierName": "a" + }, + "name": "a" + }, + "operator": "+", + "right": { + "type": "Identifier", + "start": 70, + "end": 71, + "loc": { + "start": { + "line": 3, + "column": 31 + }, + "end": { + "line": 3, + "column": 32 + }, + "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 index e37f2c9d9d..5372aefa73 100644 --- a/test/fixtures/lightscript/match/destructuring-arr/actual.js +++ b/test/fixtures/lightscript/match/destructuring-arr/actual.js @@ -2,14 +2,13 @@ match x: | [ a, b ] and a > 1: a + b | [ a, b ]: a - b | [ a, b = 2 ]: a + b - 2 - | [ 'a', b, c = 'c' ]: ['a', b, c].join('') + | [ a, ...b ]: b.concat(a) | [ [ b d = 'e' ] - [ g, 'h' ] + [ g, , h ] ...j ]: [b, d, g, ...j].join('') - | [ a, 'b', ...c ]: [a, 'b', ...c].join('') diff --git a/test/fixtures/lightscript/match/destructuring-arr/expected.json b/test/fixtures/lightscript/match/destructuring-arr/expected.json index 27757a24d2..8c23d91f3f 100644 --- a/test/fixtures/lightscript/match/destructuring-arr/expected.json +++ b/test/fixtures/lightscript/match/destructuring-arr/expected.json @@ -1,29 +1,29 @@ { "type": "File", "start": 0, - "end": 288, + "end": 225, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 15, - "column": 45 + "line": 14, + "column": 28 } }, "program": { "type": "Program", "start": 0, - "end": 288, + "end": 225, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 15, - "column": 45 + "line": 14, + "column": 28 } }, "sourceType": "script", @@ -31,15 +31,15 @@ { "type": "MatchStatement", "start": 0, - "end": 288, + "end": 225, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 15, - "column": 45 + "line": 14, + "column": 28 } }, "discriminant": { @@ -89,7 +89,7 @@ } }, "left": { - "type": "ArrayExpression", + "type": "ArrayPattern", "start": 13, "end": 21, "loc": { @@ -275,7 +275,7 @@ } }, "test": { - "type": "ArrayExpression", + "type": "ArrayPattern", "start": 43, "end": 51, "loc": { @@ -406,7 +406,7 @@ } }, "test": { - "type": "ArrayExpression", + "type": "ArrayPattern", "start": 63, "end": 75, "loc": { @@ -438,7 +438,7 @@ "name": "a" }, { - "type": "AssignmentExpression", + "type": "AssignmentPattern", "start": 68, "end": 73, "loc": { @@ -451,7 +451,6 @@ "column": 14 } }, - "operator": "=", "left": { "type": "Identifier", "start": 68, @@ -488,8 +487,7 @@ "raw": "2" }, "value": 2 - }, - "isNowAssign": false + } } ] }, @@ -598,7 +596,7 @@ { "type": "MatchCase", "start": 89, - "end": 132, + "end": 115, "loc": { "start": { "line": 5, @@ -606,13 +604,13 @@ }, "end": { "line": 5, - "column": 45 + "column": 28 } }, "test": { - "type": "ArrayExpression", + "type": "ArrayPattern", "start": 91, - "end": 110, + "end": 102, "loc": { "start": { "line": 5, @@ -620,14 +618,14 @@ }, "end": { "line": 5, - "column": 23 + "column": 15 } }, "elements": [ { - "type": "StringLiteral", + "type": "Identifier", "start": 93, - "end": 96, + "end": 94, "loc": { "start": { "line": 5, @@ -635,240 +633,141 @@ }, "end": { "line": 5, - "column": 9 - } - }, - "extra": { - "rawValue": "a", - "raw": "'a'" - }, - "value": "a" - }, - { - "type": "Identifier", - "start": 98, - "end": 99, - "loc": { - "start": { - "line": 5, - "column": 11 - }, - "end": { - "line": 5, - "column": 12 + "column": 7 }, - "identifierName": "b" + "identifierName": "a" }, - "name": "b" + "name": "a" }, { - "type": "AssignmentExpression", - "start": 101, - "end": 108, + "type": "RestElement", + "start": 96, + "end": 100, "loc": { "start": { "line": 5, - "column": 14 + "column": 9 }, "end": { "line": 5, - "column": 21 + "column": 13 } }, - "operator": "=", - "left": { + "argument": { "type": "Identifier", - "start": 101, - "end": 102, + "start": 99, + "end": 100, "loc": { "start": { "line": 5, - "column": 14 + "column": 12 }, "end": { "line": 5, - "column": 15 - }, - "identifierName": "c" - }, - "name": "c" - }, - "right": { - "type": "StringLiteral", - "start": 105, - "end": 108, - "loc": { - "start": { - "line": 5, - "column": 18 + "column": 13 }, - "end": { - "line": 5, - "column": 21 - } - }, - "extra": { - "rawValue": "c", - "raw": "'c'" + "identifierName": "b" }, - "value": "c" - }, - "isNowAssign": false + "name": "b" + } } ] }, "consequent": { "type": "ExpressionStatement", - "start": 112, - "end": 132, + "start": 104, + "end": 115, "loc": { "start": { "line": 5, - "column": 25 + "column": 17 }, "end": { "line": 5, - "column": 45 + "column": 28 } }, "expression": { "type": "CallExpression", - "start": 112, - "end": 132, + "start": 104, + "end": 115, "loc": { "start": { "line": 5, - "column": 25 + "column": 17 }, "end": { "line": 5, - "column": 45 + "column": 28 } }, "callee": { "type": "MemberExpression", - "start": 112, - "end": 128, + "start": 104, + "end": 112, "loc": { "start": { "line": 5, - "column": 25 + "column": 17 }, "end": { "line": 5, - "column": 41 + "column": 25 } }, "object": { - "type": "ArrayExpression", - "start": 112, - "end": 123, + "type": "Identifier", + "start": 104, + "end": 105, "loc": { "start": { "line": 5, - "column": 25 + "column": 17 }, "end": { "line": 5, - "column": 36 - } - }, - "elements": [ - { - "type": "StringLiteral", - "start": 113, - "end": 116, - "loc": { - "start": { - "line": 5, - "column": 26 - }, - "end": { - "line": 5, - "column": 29 - } - }, - "extra": { - "rawValue": "a", - "raw": "'a'" - }, - "value": "a" - }, - { - "type": "Identifier", - "start": 118, - "end": 119, - "loc": { - "start": { - "line": 5, - "column": 31 - }, - "end": { - "line": 5, - "column": 32 - }, - "identifierName": "b" - }, - "name": "b" + "column": 18 }, - { - "type": "Identifier", - "start": 121, - "end": 122, - "loc": { - "start": { - "line": 5, - "column": 34 - }, - "end": { - "line": 5, - "column": 35 - }, - "identifierName": "c" - }, - "name": "c" - } - ] + "identifierName": "b" + }, + "name": "b" }, "property": { "type": "Identifier", - "start": 124, - "end": 128, + "start": 106, + "end": 112, "loc": { "start": { "line": 5, - "column": 37 + "column": 19 }, "end": { "line": 5, - "column": 41 + "column": 25 }, - "identifierName": "join" + "identifierName": "concat" }, - "name": "join" + "name": "concat" }, "computed": false }, "arguments": [ { - "type": "StringLiteral", - "start": 129, - "end": 131, + "type": "Identifier", + "start": 113, + "end": 114, "loc": { "start": { "line": 5, - "column": 42 + "column": 26 }, "end": { "line": 5, - "column": 44 - } - }, - "extra": { - "rawValue": "", - "raw": "''" + "column": 27 + }, + "identifierName": "a" }, - "value": "" + "name": "a" } ] } @@ -876,8 +775,8 @@ }, { "type": "MatchCase", - "start": 135, - "end": 242, + "start": 118, + "end": 225, "loc": { "start": { "line": 6, @@ -889,9 +788,9 @@ } }, "test": { - "type": "ArrayExpression", - "start": 137, - "end": 212, + "type": "ArrayPattern", + "start": 120, + "end": 195, "loc": { "start": { "line": 6, @@ -904,9 +803,9 @@ }, "elements": [ { - "type": "ArrayExpression", - "start": 145, - "end": 180, + "type": "ArrayPattern", + "start": 128, + "end": 163, "loc": { "start": { "line": 7, @@ -920,8 +819,8 @@ "elements": [ { "type": "Identifier", - "start": 155, - "end": 156, + "start": 138, + "end": 139, "loc": { "start": { "line": 8, @@ -936,9 +835,9 @@ "name": "b" }, { - "type": "AssignmentExpression", - "start": 165, - "end": 172, + "type": "AssignmentPattern", + "start": 148, + "end": 155, "loc": { "start": { "line": 9, @@ -949,11 +848,10 @@ "column": 15 } }, - "operator": "=", "left": { "type": "Identifier", - "start": 165, - "end": 166, + "start": 148, + "end": 149, "loc": { "start": { "line": 9, @@ -969,8 +867,8 @@ }, "right": { "type": "StringLiteral", - "start": 169, - "end": 172, + "start": 152, + "end": 155, "loc": { "start": { "line": 9, @@ -986,15 +884,14 @@ "raw": "'e'" }, "value": "e" - }, - "isNowAssign": false + } } ] }, { - "type": "ArrayExpression", - "start": 187, - "end": 197, + "type": "ArrayPattern", + "start": 170, + "end": 180, "loc": { "start": { "line": 11, @@ -1008,8 +905,8 @@ "elements": [ { "type": "Identifier", - "start": 189, - "end": 190, + "start": 172, + "end": 173, "loc": { "start": { "line": 11, @@ -1023,32 +920,30 @@ }, "name": "g" }, + null, { - "type": "StringLiteral", - "start": 192, - "end": 195, + "type": "Identifier", + "start": 177, + "end": 178, "loc": { "start": { "line": 11, - "column": 11 + "column": 13 }, "end": { "line": 11, "column": 14 - } - }, - "extra": { - "rawValue": "h", - "raw": "'h'" + }, + "identifierName": "h" }, - "value": "h" + "name": "h" } ] }, { - "type": "SpreadElement", - "start": 204, - "end": 208, + "type": "RestElement", + "start": 187, + "end": 191, "loc": { "start": { "line": 12, @@ -1061,8 +956,8 @@ }, "argument": { "type": "Identifier", - "start": 207, - "end": 208, + "start": 190, + "end": 191, "loc": { "start": { "line": 12, @@ -1081,8 +976,8 @@ }, "consequent": { "type": "BlockStatement", - "start": 212, - "end": 242, + "start": 195, + "end": 225, "loc": { "start": { "line": 13, @@ -1096,8 +991,8 @@ "body": [ { "type": "ExpressionStatement", - "start": 218, - "end": 242, + "start": 201, + "end": 225, "loc": { "start": { "line": 14, @@ -1110,8 +1005,8 @@ }, "expression": { "type": "CallExpression", - "start": 218, - "end": 242, + "start": 201, + "end": 225, "loc": { "start": { "line": 14, @@ -1124,8 +1019,8 @@ }, "callee": { "type": "MemberExpression", - "start": 218, - "end": 238, + "start": 201, + "end": 221, "loc": { "start": { "line": 14, @@ -1138,8 +1033,8 @@ }, "object": { "type": "ArrayExpression", - "start": 218, - "end": 233, + "start": 201, + "end": 216, "loc": { "start": { "line": 14, @@ -1153,8 +1048,8 @@ "elements": [ { "type": "Identifier", - "start": 219, - "end": 220, + "start": 202, + "end": 203, "loc": { "start": { "line": 14, @@ -1170,8 +1065,8 @@ }, { "type": "Identifier", - "start": 222, - "end": 223, + "start": 205, + "end": 206, "loc": { "start": { "line": 14, @@ -1187,8 +1082,8 @@ }, { "type": "Identifier", - "start": 225, - "end": 226, + "start": 208, + "end": 209, "loc": { "start": { "line": 14, @@ -1204,8 +1099,8 @@ }, { "type": "SpreadElement", - "start": 228, - "end": 232, + "start": 211, + "end": 215, "loc": { "start": { "line": 14, @@ -1218,8 +1113,8 @@ }, "argument": { "type": "Identifier", - "start": 231, - "end": 232, + "start": 214, + "end": 215, "loc": { "start": { "line": 14, @@ -1238,8 +1133,8 @@ }, "property": { "type": "Identifier", - "start": 234, - "end": 238, + "start": 217, + "end": 221, "loc": { "start": { "line": 14, @@ -1258,8 +1153,8 @@ "arguments": [ { "type": "StringLiteral", - "start": 239, - "end": 241, + "start": 222, + "end": 224, "loc": { "start": { "line": 14, @@ -1285,278 +1180,6 @@ "curly": false } } - }, - { - "type": "MatchCase", - "start": 245, - "end": 288, - "loc": { - "start": { - "line": 15, - "column": 2 - }, - "end": { - "line": 15, - "column": 45 - } - }, - "test": { - "type": "ArrayExpression", - "start": 247, - "end": 263, - "loc": { - "start": { - "line": 15, - "column": 4 - }, - "end": { - "line": 15, - "column": 20 - } - }, - "elements": [ - { - "type": "Identifier", - "start": 249, - "end": 250, - "loc": { - "start": { - "line": 15, - "column": 6 - }, - "end": { - "line": 15, - "column": 7 - }, - "identifierName": "a" - }, - "name": "a" - }, - { - "type": "StringLiteral", - "start": 252, - "end": 255, - "loc": { - "start": { - "line": 15, - "column": 9 - }, - "end": { - "line": 15, - "column": 12 - } - }, - "extra": { - "rawValue": "b", - "raw": "'b'" - }, - "value": "b" - }, - { - "type": "SpreadElement", - "start": 257, - "end": 261, - "loc": { - "start": { - "line": 15, - "column": 14 - }, - "end": { - "line": 15, - "column": 18 - } - }, - "argument": { - "type": "Identifier", - "start": 260, - "end": 261, - "loc": { - "start": { - "line": 15, - "column": 17 - }, - "end": { - "line": 15, - "column": 18 - }, - "identifierName": "c" - }, - "name": "c" - } - } - ] - }, - "consequent": { - "type": "ExpressionStatement", - "start": 265, - "end": 288, - "loc": { - "start": { - "line": 15, - "column": 22 - }, - "end": { - "line": 15, - "column": 45 - } - }, - "expression": { - "type": "CallExpression", - "start": 265, - "end": 288, - "loc": { - "start": { - "line": 15, - "column": 22 - }, - "end": { - "line": 15, - "column": 45 - } - }, - "callee": { - "type": "MemberExpression", - "start": 265, - "end": 284, - "loc": { - "start": { - "line": 15, - "column": 22 - }, - "end": { - "line": 15, - "column": 41 - } - }, - "object": { - "type": "ArrayExpression", - "start": 265, - "end": 279, - "loc": { - "start": { - "line": 15, - "column": 22 - }, - "end": { - "line": 15, - "column": 36 - } - }, - "elements": [ - { - "type": "Identifier", - "start": 266, - "end": 267, - "loc": { - "start": { - "line": 15, - "column": 23 - }, - "end": { - "line": 15, - "column": 24 - }, - "identifierName": "a" - }, - "name": "a" - }, - { - "type": "StringLiteral", - "start": 269, - "end": 272, - "loc": { - "start": { - "line": 15, - "column": 26 - }, - "end": { - "line": 15, - "column": 29 - } - }, - "extra": { - "rawValue": "b", - "raw": "'b'" - }, - "value": "b" - }, - { - "type": "SpreadElement", - "start": 274, - "end": 278, - "loc": { - "start": { - "line": 15, - "column": 31 - }, - "end": { - "line": 15, - "column": 35 - } - }, - "argument": { - "type": "Identifier", - "start": 277, - "end": 278, - "loc": { - "start": { - "line": 15, - "column": 34 - }, - "end": { - "line": 15, - "column": 35 - }, - "identifierName": "c" - }, - "name": "c" - } - } - ] - }, - "property": { - "type": "Identifier", - "start": 280, - "end": 284, - "loc": { - "start": { - "line": 15, - "column": 37 - }, - "end": { - "line": 15, - "column": 41 - }, - "identifierName": "join" - }, - "name": "join" - }, - "computed": false - }, - "arguments": [ - { - "type": "StringLiteral", - "start": 285, - "end": 287, - "loc": { - "start": { - "line": 15, - "column": 42 - }, - "end": { - "line": 15, - "column": 44 - } - }, - "extra": { - "rawValue": "", - "raw": "''" - }, - "value": "" - } - ] - } - } } ] } diff --git a/test/fixtures/lightscript/match/destructuring-obj-arr-mixed/actual.js b/test/fixtures/lightscript/match/destructuring-obj-arr-mixed/actual.js index c55f1c63b0..6ad3c916fc 100644 --- a/test/fixtures/lightscript/match/destructuring-obj-arr-mixed/actual.js +++ b/test/fixtures/lightscript/match/destructuring-obj-arr-mixed/actual.js @@ -4,7 +4,7 @@ match x: b { d - e: 'e' + e = 1 ...f } g diff --git a/test/fixtures/lightscript/match/destructuring-obj-arr-mixed/expected.json b/test/fixtures/lightscript/match/destructuring-obj-arr-mixed/expected.json index 6d154936f2..160cd21e8b 100644 --- a/test/fixtures/lightscript/match/destructuring-obj-arr-mixed/expected.json +++ b/test/fixtures/lightscript/match/destructuring-obj-arr-mixed/expected.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 160, + "end": 159, "loc": { "start": { "line": 1, @@ -15,7 +15,7 @@ "program": { "type": "Program", "start": 0, - "end": 160, + "end": 159, "loc": { "start": { "line": 1, @@ -31,7 +31,7 @@ { "type": "MatchStatement", "start": 0, - "end": 160, + "end": 159, "loc": { "start": { "line": 1, @@ -63,7 +63,7 @@ { "type": "MatchCase", "start": 11, - "end": 160, + "end": 159, "loc": { "start": { "line": 2, @@ -75,9 +75,9 @@ } }, "test": { - "type": "ObjectExpression", + "type": "ObjectPattern", "start": 13, - "end": 124, + "end": 123, "loc": { "start": { "line": 2, @@ -92,7 +92,7 @@ { "type": "ObjectProperty", "start": 19, - "end": 99, + "end": 98, "loc": { "start": { "line": 3, @@ -124,9 +124,9 @@ "name": "a" }, "value": { - "type": "ArrayExpression", + "type": "ArrayPattern", "start": 22, - "end": 99, + "end": 98, "loc": { "start": { "line": 3, @@ -156,9 +156,9 @@ "name": "b" }, { - "type": "ObjectExpression", + "type": "ObjectPattern", "start": 38, - "end": 85, + "end": 84, "loc": { "start": { "line": 5, @@ -228,7 +228,7 @@ { "type": "ObjectProperty", "start": 58, - "end": 64, + "end": 63, "loc": { "start": { "line": 7, @@ -236,11 +236,11 @@ }, "end": { "line": 7, - "column": 14 + "column": 13 } }, "method": false, - "shorthand": false, + "shorthand": true, "computed": false, "key": { "type": "Identifier", @@ -260,30 +260,65 @@ "name": "e" }, "value": { - "type": "StringLiteral", - "start": 61, - "end": 64, + "type": "AssignmentPattern", + "start": 58, + "end": 63, "loc": { "start": { "line": 7, - "column": 11 + "column": 8 }, "end": { "line": 7, - "column": 14 + "column": 13 } }, - "extra": { - "rawValue": "e", - "raw": "'e'" + "left": { + "type": "Identifier", + "start": 58, + "end": 59, + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 9 + }, + "identifierName": "e" + }, + "name": "e" }, - "value": "e" + "right": { + "type": "NumericLiteral", + "start": 62, + "end": 63, + "loc": { + "start": { + "line": 7, + "column": 12 + }, + "end": { + "line": 7, + "column": 13 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + }, + "extra": { + "shorthand": true } }, { - "type": "SpreadProperty", - "start": 73, - "end": 77, + "type": "RestProperty", + "start": 72, + "end": 76, "loc": { "start": { "line": 8, @@ -296,8 +331,8 @@ }, "argument": { "type": "Identifier", - "start": 76, - "end": 77, + "start": 75, + "end": 76, "loc": { "start": { "line": 8, @@ -316,8 +351,8 @@ }, { "type": "Identifier", - "start": 92, - "end": 93, + "start": 91, + "end": 92, "loc": { "start": { "line": 10, @@ -336,8 +371,8 @@ }, { "type": "ObjectProperty", - "start": 104, - "end": 111, + "start": 103, + "end": 110, "loc": { "start": { "line": 12, @@ -353,8 +388,8 @@ "computed": false, "key": { "type": "Identifier", - "start": 104, - "end": 105, + "start": 103, + "end": 104, "loc": { "start": { "line": 12, @@ -370,8 +405,8 @@ }, "value": { "type": "AssignmentPattern", - "start": 104, - "end": 111, + "start": 103, + "end": 110, "loc": { "start": { "line": 12, @@ -384,8 +419,8 @@ }, "left": { "type": "Identifier", - "start": 104, - "end": 105, + "start": 103, + "end": 104, "loc": { "start": { "line": 12, @@ -401,8 +436,8 @@ }, "right": { "type": "StringLiteral", - "start": 108, - "end": 111, + "start": 107, + "end": 110, "loc": { "start": { "line": 12, @@ -425,9 +460,9 @@ } }, { - "type": "SpreadProperty", - "start": 116, - "end": 120, + "type": "RestProperty", + "start": 115, + "end": 119, "loc": { "start": { "line": 13, @@ -440,8 +475,8 @@ }, "argument": { "type": "Identifier", - "start": 119, - "end": 120, + "start": 118, + "end": 119, "loc": { "start": { "line": 13, @@ -460,8 +495,8 @@ }, "consequent": { "type": "BlockStatement", - "start": 124, - "end": 160, + "start": 123, + "end": 159, "loc": { "start": { "line": 14, @@ -475,8 +510,8 @@ "body": [ { "type": "ExpressionStatement", - "start": 130, - "end": 160, + "start": 129, + "end": 159, "loc": { "start": { "line": 15, @@ -489,8 +524,8 @@ }, "expression": { "type": "CallExpression", - "start": 130, - "end": 160, + "start": 129, + "end": 159, "loc": { "start": { "line": 15, @@ -503,8 +538,8 @@ }, "callee": { "type": "MemberExpression", - "start": 130, - "end": 156, + "start": 129, + "end": 155, "loc": { "start": { "line": 15, @@ -517,8 +552,8 @@ }, "object": { "type": "ArrayExpression", - "start": 130, - "end": 151, + "start": 129, + "end": 150, "loc": { "start": { "line": 15, @@ -532,8 +567,8 @@ "elements": [ { "type": "Identifier", - "start": 131, - "end": 132, + "start": 130, + "end": 131, "loc": { "start": { "line": 15, @@ -549,8 +584,8 @@ }, { "type": "Identifier", - "start": 134, - "end": 135, + "start": 133, + "end": 134, "loc": { "start": { "line": 15, @@ -566,8 +601,8 @@ }, { "type": "SpreadElement", - "start": 137, - "end": 141, + "start": 136, + "end": 140, "loc": { "start": { "line": 15, @@ -580,8 +615,8 @@ }, "argument": { "type": "Identifier", - "start": 140, - "end": 141, + "start": 139, + "end": 140, "loc": { "start": { "line": 15, @@ -598,8 +633,8 @@ }, { "type": "Identifier", - "start": 143, - "end": 144, + "start": 142, + "end": 143, "loc": { "start": { "line": 15, @@ -615,8 +650,8 @@ }, { "type": "Identifier", - "start": 146, - "end": 147, + "start": 145, + "end": 146, "loc": { "start": { "line": 15, @@ -632,8 +667,8 @@ }, { "type": "Identifier", - "start": 149, - "end": 150, + "start": 148, + "end": 149, "loc": { "start": { "line": 15, @@ -651,8 +686,8 @@ }, "property": { "type": "Identifier", - "start": 152, - "end": 156, + "start": 151, + "end": 155, "loc": { "start": { "line": 15, @@ -671,8 +706,8 @@ "arguments": [ { "type": "StringLiteral", - "start": 157, - "end": 159, + "start": 156, + "end": 158, "loc": { "start": { "line": 15, diff --git a/test/fixtures/lightscript/match/destructuring-obj/actual.js b/test/fixtures/lightscript/match/destructuring-obj/actual.js index f8ef2530ce..6eca5e504c 100644 --- a/test/fixtures/lightscript/match/destructuring-obj/actual.js +++ b/test/fixtures/lightscript/match/destructuring-obj/actual.js @@ -1,14 +1,13 @@ match x: - | { a, b } and a > 1: a + b + | ~isObject() and { a, b } and a~isNumber() and a > 1: a + b | { a, b }: a - b | { a, b = 2 }: a + b - 2 - | { a: 'a', b: 'c', d = 'e' }: [a, b, d].join('') | { a: { - b: 'c' + b d = 'e' } - f: { g: 'g', h = 'h' } + f: { ...g } }: - [b, d, g, h].join('') - | { a, b: 'b', ...c }: [a, b, c].join('') + [b, d, g].join('') + | { a, ...c }: [a, b, c].join('') diff --git a/test/fixtures/lightscript/match/destructuring-obj/expected.json b/test/fixtures/lightscript/match/destructuring-obj/expected.json index 6ed70e17b0..aff864a79e 100644 --- a/test/fixtures/lightscript/match/destructuring-obj/expected.json +++ b/test/fixtures/lightscript/match/destructuring-obj/expected.json @@ -1,29 +1,29 @@ { "type": "File", "start": 0, - "end": 288, + "end": 242, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 14, - "column": 43 + "line": 13, + "column": 35 } }, "program": { "type": "Program", "start": 0, - "end": 288, + "end": 242, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 14, - "column": 43 + "line": 13, + "column": 35 } }, "sourceType": "script", @@ -31,15 +31,15 @@ { "type": "MatchStatement", "start": 0, - "end": 288, + "end": 242, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 14, - "column": 43 + "line": 13, + "column": 35 } }, "discriminant": { @@ -63,7 +63,7 @@ { "type": "MatchCase", "start": 11, - "end": 38, + "end": 71, "loc": { "start": { "line": 2, @@ -71,13 +71,13 @@ }, "end": { "line": 2, - "column": 29 + "column": 62 } }, "test": { "type": "LogicalExpression", "start": 13, - "end": 31, + "end": 64, "loc": { "start": { "line": 2, @@ -85,13 +85,13 @@ }, "end": { "line": 2, - "column": 22 + "column": 55 } }, "left": { - "type": "ObjectExpression", + "type": "LogicalExpression", "start": 13, - "end": 21, + "end": 54, "loc": { "start": { "line": 2, @@ -99,149 +99,279 @@ }, "end": { "line": 2, - "column": 12 + "column": 45 } }, - "properties": [ - { - "type": "ObjectProperty", - "start": 15, - "end": 16, + "left": { + "type": "LogicalExpression", + "start": 13, + "end": 37, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 28 + } + }, + "left": { + "type": "TildeCallExpression", + "start": 13, + "end": 24, "loc": { "start": { "line": 2, - "column": 6 + "column": 4 }, "end": { "line": 2, - "column": 7 + "column": 15 } }, - "method": false, - "shorthand": true, - "computed": false, - "key": { - "type": "Identifier", - "start": 15, - "end": 16, + "left": { + "type": "PlaceholderExpression", + "start": 12, + "end": 13, "loc": { "start": { "line": 2, - "column": 6 + "column": 3 }, "end": { "line": 2, - "column": 7 - }, - "identifierName": "a" - }, - "name": "a" + "column": 4 + } + } }, - "value": { + "right": { "type": "Identifier", - "start": 15, - "end": 16, + "start": 14, + "end": 22, "loc": { "start": { "line": 2, - "column": 6 + "column": 5 }, "end": { "line": 2, - "column": 7 + "column": 13 }, - "identifierName": "a" + "identifierName": "isObject" }, - "name": "a" + "name": "isObject" }, - "extra": { - "shorthand": true - } + "arguments": [] }, - { - "type": "ObjectProperty", - "start": 18, - "end": 19, + "operator": "&&", + "right": { + "type": "ObjectPattern", + "start": 29, + "end": 37, "loc": { "start": { "line": 2, - "column": 9 + "column": 20 }, "end": { "line": 2, - "column": 10 + "column": 28 } }, - "method": false, - "shorthand": true, - "computed": false, - "key": { - "type": "Identifier", - "start": 18, - "end": 19, - "loc": { - "start": { - "line": 2, - "column": 9 + "properties": [ + { + "type": "ObjectProperty", + "start": 31, + "end": 32, + "loc": { + "start": { + "line": 2, + "column": 22 + }, + "end": { + "line": 2, + "column": 23 + } }, - "end": { - "line": 2, - "column": 10 + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 31, + "end": 32, + "loc": { + "start": { + "line": 2, + "column": 22 + }, + "end": { + "line": 2, + "column": 23 + }, + "identifierName": "a" + }, + "name": "a" }, - "identifierName": "b" + "value": { + "type": "Identifier", + "start": 31, + "end": 32, + "loc": { + "start": { + "line": 2, + "column": 22 + }, + "end": { + "line": 2, + "column": 23 + }, + "identifierName": "a" + }, + "name": "a" + }, + "extra": { + "shorthand": true + } }, - "name": "b" - }, - "value": { - "type": "Identifier", - "start": 18, - "end": 19, - "loc": { - "start": { - "line": 2, - "column": 9 + { + "type": "ObjectProperty", + "start": 34, + "end": 35, + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 2, + "column": 26 + } }, - "end": { - "line": 2, - "column": 10 + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 34, + "end": 35, + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 2, + "column": 26 + }, + "identifierName": "b" + }, + "name": "b" }, - "identifierName": "b" - }, - "name": "b" + "value": { + "type": "Identifier", + "start": 34, + "end": 35, + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 2, + "column": 26 + }, + "identifierName": "b" + }, + "name": "b" + }, + "extra": { + "shorthand": true + } + } + ] + } + }, + "operator": "&&", + "right": { + "type": "TildeCallExpression", + "start": 42, + "end": 54, + "loc": { + "start": { + "line": 2, + "column": 33 }, - "extra": { - "shorthand": true + "end": { + "line": 2, + "column": 45 } - } - ] + }, + "left": { + "type": "Identifier", + "start": 42, + "end": 43, + "loc": { + "start": { + "line": 2, + "column": 33 + }, + "end": { + "line": 2, + "column": 34 + }, + "identifierName": "a" + }, + "name": "a" + }, + "right": { + "type": "Identifier", + "start": 44, + "end": 52, + "loc": { + "start": { + "line": 2, + "column": 35 + }, + "end": { + "line": 2, + "column": 43 + }, + "identifierName": "isNumber" + }, + "name": "isNumber" + }, + "arguments": [] + } }, "operator": "&&", "right": { "type": "BinaryExpression", - "start": 26, - "end": 31, + "start": 59, + "end": 64, "loc": { "start": { "line": 2, - "column": 17 + "column": 50 }, "end": { "line": 2, - "column": 22 + "column": 55 } }, "left": { "type": "Identifier", - "start": 26, - "end": 27, + "start": 59, + "end": 60, "loc": { "start": { "line": 2, - "column": 17 + "column": 50 }, "end": { "line": 2, - "column": 18 + "column": 51 }, "identifierName": "a" }, @@ -250,16 +380,16 @@ "operator": ">", "right": { "type": "NumericLiteral", - "start": 30, - "end": 31, + "start": 63, + "end": 64, "loc": { "start": { "line": 2, - "column": 21 + "column": 54 }, "end": { "line": 2, - "column": 22 + "column": 55 } }, "extra": { @@ -272,44 +402,44 @@ }, "consequent": { "type": "ExpressionStatement", - "start": 33, - "end": 38, + "start": 66, + "end": 71, "loc": { "start": { "line": 2, - "column": 24 + "column": 57 }, "end": { "line": 2, - "column": 29 + "column": 62 } }, "expression": { "type": "BinaryExpression", - "start": 33, - "end": 38, + "start": 66, + "end": 71, "loc": { "start": { "line": 2, - "column": 24 + "column": 57 }, "end": { "line": 2, - "column": 29 + "column": 62 } }, "left": { "type": "Identifier", - "start": 33, - "end": 34, + "start": 66, + "end": 67, "loc": { "start": { "line": 2, - "column": 24 + "column": 57 }, "end": { "line": 2, - "column": 25 + "column": 58 }, "identifierName": "a" }, @@ -318,16 +448,16 @@ "operator": "+", "right": { "type": "Identifier", - "start": 37, - "end": 38, + "start": 70, + "end": 71, "loc": { "start": { "line": 2, - "column": 28 + "column": 61 }, "end": { "line": 2, - "column": 29 + "column": 62 }, "identifierName": "b" }, @@ -338,8 +468,8 @@ }, { "type": "MatchCase", - "start": 41, - "end": 58, + "start": 74, + "end": 91, "loc": { "start": { "line": 3, @@ -351,9 +481,9 @@ } }, "test": { - "type": "ObjectExpression", - "start": 43, - "end": 51, + "type": "ObjectPattern", + "start": 76, + "end": 84, "loc": { "start": { "line": 3, @@ -367,8 +497,8 @@ "properties": [ { "type": "ObjectProperty", - "start": 45, - "end": 46, + "start": 78, + "end": 79, "loc": { "start": { "line": 3, @@ -384,8 +514,8 @@ "computed": false, "key": { "type": "Identifier", - "start": 45, - "end": 46, + "start": 78, + "end": 79, "loc": { "start": { "line": 3, @@ -401,8 +531,8 @@ }, "value": { "type": "Identifier", - "start": 45, - "end": 46, + "start": 78, + "end": 79, "loc": { "start": { "line": 3, @@ -422,8 +552,8 @@ }, { "type": "ObjectProperty", - "start": 48, - "end": 49, + "start": 81, + "end": 82, "loc": { "start": { "line": 3, @@ -439,8 +569,8 @@ "computed": false, "key": { "type": "Identifier", - "start": 48, - "end": 49, + "start": 81, + "end": 82, "loc": { "start": { "line": 3, @@ -456,8 +586,8 @@ }, "value": { "type": "Identifier", - "start": 48, - "end": 49, + "start": 81, + "end": 82, "loc": { "start": { "line": 3, @@ -479,8 +609,8 @@ }, "consequent": { "type": "ExpressionStatement", - "start": 53, - "end": 58, + "start": 86, + "end": 91, "loc": { "start": { "line": 3, @@ -493,8 +623,8 @@ }, "expression": { "type": "BinaryExpression", - "start": 53, - "end": 58, + "start": 86, + "end": 91, "loc": { "start": { "line": 3, @@ -507,8 +637,8 @@ }, "left": { "type": "Identifier", - "start": 53, - "end": 54, + "start": 86, + "end": 87, "loc": { "start": { "line": 3, @@ -525,8 +655,8 @@ "operator": "-", "right": { "type": "Identifier", - "start": 57, - "end": 58, + "start": 90, + "end": 91, "loc": { "start": { "line": 3, @@ -545,8 +675,8 @@ }, { "type": "MatchCase", - "start": 61, - "end": 86, + "start": 94, + "end": 119, "loc": { "start": { "line": 4, @@ -558,9 +688,9 @@ } }, "test": { - "type": "ObjectExpression", - "start": 63, - "end": 75, + "type": "ObjectPattern", + "start": 96, + "end": 108, "loc": { "start": { "line": 4, @@ -574,8 +704,8 @@ "properties": [ { "type": "ObjectProperty", - "start": 65, - "end": 66, + "start": 98, + "end": 99, "loc": { "start": { "line": 4, @@ -591,8 +721,8 @@ "computed": false, "key": { "type": "Identifier", - "start": 65, - "end": 66, + "start": 98, + "end": 99, "loc": { "start": { "line": 4, @@ -608,8 +738,8 @@ }, "value": { "type": "Identifier", - "start": 65, - "end": 66, + "start": 98, + "end": 99, "loc": { "start": { "line": 4, @@ -629,8 +759,8 @@ }, { "type": "ObjectProperty", - "start": 68, - "end": 73, + "start": 101, + "end": 106, "loc": { "start": { "line": 4, @@ -646,8 +776,8 @@ "computed": false, "key": { "type": "Identifier", - "start": 68, - "end": 69, + "start": 101, + "end": 102, "loc": { "start": { "line": 4, @@ -663,8 +793,8 @@ }, "value": { "type": "AssignmentPattern", - "start": 68, - "end": 73, + "start": 101, + "end": 106, "loc": { "start": { "line": 4, @@ -677,8 +807,8 @@ }, "left": { "type": "Identifier", - "start": 68, - "end": 69, + "start": 101, + "end": 102, "loc": { "start": { "line": 4, @@ -694,8 +824,8 @@ }, "right": { "type": "NumericLiteral", - "start": 72, - "end": 73, + "start": 105, + "end": 106, "loc": { "start": { "line": 4, @@ -721,8 +851,8 @@ }, "consequent": { "type": "ExpressionStatement", - "start": 77, - "end": 86, + "start": 110, + "end": 119, "loc": { "start": { "line": 4, @@ -735,8 +865,8 @@ }, "expression": { "type": "BinaryExpression", - "start": 77, - "end": 86, + "start": 110, + "end": 119, "loc": { "start": { "line": 4, @@ -749,8 +879,8 @@ }, "left": { "type": "BinaryExpression", - "start": 77, - "end": 82, + "start": 110, + "end": 115, "loc": { "start": { "line": 4, @@ -763,8 +893,8 @@ }, "left": { "type": "Identifier", - "start": 77, - "end": 78, + "start": 110, + "end": 111, "loc": { "start": { "line": 4, @@ -781,8 +911,8 @@ "operator": "+", "right": { "type": "Identifier", - "start": 81, - "end": 82, + "start": 114, + "end": 115, "loc": { "start": { "line": 4, @@ -800,8 +930,8 @@ "operator": "-", "right": { "type": "NumericLiteral", - "start": 85, - "end": 86, + "start": 118, + "end": 119, "loc": { "start": { "line": 4, @@ -823,45 +953,45 @@ }, { "type": "MatchCase", - "start": 89, - "end": 138, + "start": 122, + "end": 206, "loc": { "start": { "line": 5, "column": 2 }, "end": { - "line": 5, - "column": 51 + "line": 12, + "column": 22 } }, "test": { - "type": "ObjectExpression", - "start": 91, - "end": 118, + "type": "ObjectPattern", + "start": 124, + "end": 182, "loc": { "start": { "line": 5, "column": 4 }, "end": { - "line": 5, - "column": 31 + "line": 11, + "column": 3 } }, "properties": [ { "type": "ObjectProperty", - "start": 93, - "end": 99, + "start": 130, + "end": 162, "loc": { "start": { - "line": 5, - "column": 6 + "line": 6, + "column": 4 }, "end": { - "line": 5, - "column": 12 + "line": 9, + "column": 5 } }, "method": false, @@ -869,449 +999,64 @@ "computed": false, "key": { "type": "Identifier", - "start": 93, - "end": 94, + "start": 130, + "end": 131, "loc": { "start": { - "line": 5, - "column": 6 + "line": 6, + "column": 4 }, "end": { - "line": 5, - "column": 7 + "line": 6, + "column": 5 }, "identifierName": "a" }, "name": "a" }, "value": { - "type": "StringLiteral", - "start": 96, - "end": 99, - "loc": { - "start": { - "line": 5, - "column": 9 - }, - "end": { - "line": 5, - "column": 12 - } - }, - "extra": { - "rawValue": "a", - "raw": "'a'" - }, - "value": "a" - } - }, - { - "type": "ObjectProperty", - "start": 101, - "end": 107, - "loc": { - "start": { - "line": 5, - "column": 14 - }, - "end": { - "line": 5, - "column": 20 - } - }, - "method": false, - "shorthand": false, - "computed": false, - "key": { - "type": "Identifier", - "start": 101, - "end": 102, - "loc": { - "start": { - "line": 5, - "column": 14 - }, - "end": { - "line": 5, - "column": 15 - }, - "identifierName": "b" - }, - "name": "b" - }, - "value": { - "type": "StringLiteral", - "start": 104, - "end": 107, + "type": "ObjectPattern", + "start": 133, + "end": 162, "loc": { "start": { - "line": 5, - "column": 17 + "line": 6, + "column": 7 }, "end": { - "line": 5, - "column": 20 - } - }, - "extra": { - "rawValue": "c", - "raw": "'c'" - }, - "value": "c" - } - }, - { - "type": "ObjectProperty", - "start": 109, - "end": 116, - "loc": { - "start": { - "line": 5, - "column": 22 - }, - "end": { - "line": 5, - "column": 29 - } - }, - "method": false, - "shorthand": true, - "computed": false, - "key": { - "type": "Identifier", - "start": 109, - "end": 110, - "loc": { - "start": { - "line": 5, - "column": 22 - }, - "end": { - "line": 5, - "column": 23 - }, - "identifierName": "d" - }, - "name": "d" - }, - "value": { - "type": "AssignmentPattern", - "start": 109, - "end": 116, - "loc": { - "start": { - "line": 5, - "column": 22 - }, - "end": { - "line": 5, - "column": 29 - } - }, - "left": { - "type": "Identifier", - "start": 109, - "end": 110, - "loc": { - "start": { - "line": 5, - "column": 22 - }, - "end": { - "line": 5, - "column": 23 - }, - "identifierName": "d" - }, - "name": "d" - }, - "right": { - "type": "StringLiteral", - "start": 113, - "end": 116, - "loc": { - "start": { - "line": 5, - "column": 26 - }, - "end": { - "line": 5, - "column": 29 - } - }, - "extra": { - "rawValue": "e", - "raw": "'e'" - }, - "value": "e" - } - }, - "extra": { - "shorthand": true - } - } - ] - }, - "consequent": { - "type": "ExpressionStatement", - "start": 120, - "end": 138, - "loc": { - "start": { - "line": 5, - "column": 33 - }, - "end": { - "line": 5, - "column": 51 - } - }, - "expression": { - "type": "CallExpression", - "start": 120, - "end": 138, - "loc": { - "start": { - "line": 5, - "column": 33 - }, - "end": { - "line": 5, - "column": 51 - } - }, - "callee": { - "type": "MemberExpression", - "start": 120, - "end": 134, - "loc": { - "start": { - "line": 5, - "column": 33 - }, - "end": { - "line": 5, - "column": 47 - } - }, - "object": { - "type": "ArrayExpression", - "start": 120, - "end": 129, - "loc": { - "start": { - "line": 5, - "column": 33 - }, - "end": { - "line": 5, - "column": 42 - } - }, - "elements": [ - { - "type": "Identifier", - "start": 121, - "end": 122, - "loc": { - "start": { - "line": 5, - "column": 34 - }, - "end": { - "line": 5, - "column": 35 - }, - "identifierName": "a" - }, - "name": "a" - }, - { - "type": "Identifier", - "start": 124, - "end": 125, - "loc": { - "start": { - "line": 5, - "column": 37 - }, - "end": { - "line": 5, - "column": 38 - }, - "identifierName": "b" - }, - "name": "b" - }, - { - "type": "Identifier", - "start": 127, - "end": 128, - "loc": { - "start": { - "line": 5, - "column": 40 - }, - "end": { - "line": 5, - "column": 41 - }, - "identifierName": "d" - }, - "name": "d" - } - ] - }, - "property": { - "type": "Identifier", - "start": 130, - "end": 134, - "loc": { - "start": { - "line": 5, - "column": 43 - }, - "end": { - "line": 5, - "column": 47 - }, - "identifierName": "join" - }, - "name": "join" - }, - "computed": false - }, - "arguments": [ - { - "type": "StringLiteral", - "start": 135, - "end": 137, - "loc": { - "start": { - "line": 5, - "column": 48 - }, - "end": { - "line": 5, - "column": 50 - } - }, - "extra": { - "rawValue": "", - "raw": "''" - }, - "value": "" - } - ] - } - } - }, - { - "type": "MatchCase", - "start": 141, - "end": 244, - "loc": { - "start": { - "line": 6, - "column": 2 - }, - "end": { - "line": 13, - "column": 25 - } - }, - "test": { - "type": "ObjectExpression", - "start": 143, - "end": 217, - "loc": { - "start": { - "line": 6, - "column": 4 - }, - "end": { - "line": 12, - "column": 3 - } - }, - "properties": [ - { - "type": "ObjectProperty", - "start": 149, - "end": 186, - "loc": { - "start": { - "line": 7, - "column": 4 - }, - "end": { - "line": 10, - "column": 5 - } - }, - "method": false, - "shorthand": false, - "computed": false, - "key": { - "type": "Identifier", - "start": 149, - "end": 150, - "loc": { - "start": { - "line": 7, - "column": 4 - }, - "end": { - "line": 7, - "column": 5 - }, - "identifierName": "a" - }, - "name": "a" - }, - "value": { - "type": "ObjectExpression", - "start": 152, - "end": 186, - "loc": { - "start": { - "line": 7, - "column": 7 - }, - "end": { - "line": 10, - "column": 5 + "line": 9, + "column": 5 } }, "properties": [ { "type": "ObjectProperty", - "start": 160, - "end": 166, + "start": 141, + "end": 142, "loc": { "start": { - "line": 8, + "line": 7, "column": 6 }, "end": { - "line": 8, - "column": 12 + "line": 7, + "column": 7 } }, "method": false, - "shorthand": false, + "shorthand": true, "computed": false, "key": { "type": "Identifier", - "start": 160, - "end": 161, + "start": 141, + "end": 142, "loc": { "start": { - "line": 8, + "line": 7, "column": 6 }, "end": { - "line": 8, + "line": 7, "column": 7 }, "identifierName": "b" @@ -1319,37 +1064,37 @@ "name": "b" }, "value": { - "type": "StringLiteral", - "start": 163, - "end": 166, + "type": "Identifier", + "start": 141, + "end": 142, "loc": { "start": { - "line": 8, - "column": 9 + "line": 7, + "column": 6 }, "end": { - "line": 8, - "column": 12 - } - }, - "extra": { - "rawValue": "c", - "raw": "'c'" + "line": 7, + "column": 7 + }, + "identifierName": "b" }, - "value": "c" + "name": "b" + }, + "extra": { + "shorthand": true } }, { "type": "ObjectProperty", - "start": 173, - "end": 180, + "start": 149, + "end": 156, "loc": { "start": { - "line": 9, + "line": 8, "column": 6 }, "end": { - "line": 9, + "line": 8, "column": 13 } }, @@ -1358,15 +1103,15 @@ "computed": false, "key": { "type": "Identifier", - "start": 173, - "end": 174, + "start": 149, + "end": 150, "loc": { "start": { - "line": 9, + "line": 8, "column": 6 }, "end": { - "line": 9, + "line": 8, "column": 7 }, "identifierName": "d" @@ -1375,29 +1120,29 @@ }, "value": { "type": "AssignmentPattern", - "start": 173, - "end": 180, + "start": 149, + "end": 156, "loc": { "start": { - "line": 9, + "line": 8, "column": 6 }, "end": { - "line": 9, + "line": 8, "column": 13 } }, "left": { "type": "Identifier", - "start": 173, - "end": 174, + "start": 149, + "end": 150, "loc": { "start": { - "line": 9, + "line": 8, "column": 6 }, "end": { - "line": 9, + "line": 8, "column": 7 }, "identifierName": "d" @@ -1406,15 +1151,15 @@ }, "right": { "type": "StringLiteral", - "start": 177, - "end": 180, + "start": 153, + "end": 156, "loc": { "start": { - "line": 9, + "line": 8, "column": 10 }, "end": { - "line": 9, + "line": 8, "column": 13 } }, @@ -1434,16 +1179,16 @@ }, { "type": "ObjectProperty", - "start": 191, - "end": 213, + "start": 167, + "end": 178, "loc": { "start": { - "line": 11, + "line": 10, "column": 4 }, "end": { - "line": 11, - "column": 26 + "line": 10, + "column": 15 } }, "method": false, @@ -1451,15 +1196,15 @@ "computed": false, "key": { "type": "Identifier", - "start": 191, - "end": 192, + "start": 167, + "end": 168, "loc": { "start": { - "line": 11, + "line": 10, "column": 4 }, "end": { - "line": 11, + "line": 10, "column": 5 }, "identifierName": "f" @@ -1467,163 +1212,50 @@ "name": "f" }, "value": { - "type": "ObjectExpression", - "start": 194, - "end": 213, + "type": "ObjectPattern", + "start": 170, + "end": 178, "loc": { "start": { - "line": 11, + "line": 10, "column": 7 }, "end": { - "line": 11, - "column": 26 + "line": 10, + "column": 15 } }, "properties": [ { - "type": "ObjectProperty", - "start": 196, - "end": 202, + "type": "RestProperty", + "start": 172, + "end": 176, "loc": { "start": { - "line": 11, + "line": 10, "column": 9 }, "end": { - "line": 11, - "column": 15 + "line": 10, + "column": 13 } }, - "method": false, - "shorthand": false, - "computed": false, - "key": { + "argument": { "type": "Identifier", - "start": 196, - "end": 197, + "start": 175, + "end": 176, "loc": { "start": { - "line": 11, - "column": 9 + "line": 10, + "column": 12 }, "end": { - "line": 11, - "column": 10 + "line": 10, + "column": 13 }, "identifierName": "g" }, "name": "g" - }, - "value": { - "type": "StringLiteral", - "start": 199, - "end": 202, - "loc": { - "start": { - "line": 11, - "column": 12 - }, - "end": { - "line": 11, - "column": 15 - } - }, - "extra": { - "rawValue": "g", - "raw": "'g'" - }, - "value": "g" - } - }, - { - "type": "ObjectProperty", - "start": 204, - "end": 211, - "loc": { - "start": { - "line": 11, - "column": 17 - }, - "end": { - "line": 11, - "column": 24 - } - }, - "method": false, - "shorthand": true, - "computed": false, - "key": { - "type": "Identifier", - "start": 204, - "end": 205, - "loc": { - "start": { - "line": 11, - "column": 17 - }, - "end": { - "line": 11, - "column": 18 - }, - "identifierName": "h" - }, - "name": "h" - }, - "value": { - "type": "AssignmentPattern", - "start": 204, - "end": 211, - "loc": { - "start": { - "line": 11, - "column": 17 - }, - "end": { - "line": 11, - "column": 24 - } - }, - "left": { - "type": "Identifier", - "start": 204, - "end": 205, - "loc": { - "start": { - "line": 11, - "column": 17 - }, - "end": { - "line": 11, - "column": 18 - }, - "identifierName": "h" - }, - "name": "h" - }, - "right": { - "type": "StringLiteral", - "start": 208, - "end": 211, - "loc": { - "start": { - "line": 11, - "column": 21 - }, - "end": { - "line": 11, - "column": 24 - } - }, - "extra": { - "rawValue": "h", - "raw": "'h'" - }, - "value": "h" - } - }, - "extra": { - "shorthand": true } } ] @@ -1633,87 +1265,87 @@ }, "consequent": { "type": "BlockStatement", - "start": 217, - "end": 244, + "start": 182, + "end": 206, "loc": { "start": { - "line": 12, + "line": 11, "column": 3 }, "end": { - "line": 13, - "column": 25 + "line": 12, + "column": 22 } }, "body": [ { "type": "ExpressionStatement", - "start": 223, - "end": 244, + "start": 188, + "end": 206, "loc": { "start": { - "line": 13, + "line": 12, "column": 4 }, "end": { - "line": 13, - "column": 25 + "line": 12, + "column": 22 } }, "expression": { "type": "CallExpression", - "start": 223, - "end": 244, + "start": 188, + "end": 206, "loc": { "start": { - "line": 13, + "line": 12, "column": 4 }, "end": { - "line": 13, - "column": 25 + "line": 12, + "column": 22 } }, "callee": { "type": "MemberExpression", - "start": 223, - "end": 240, + "start": 188, + "end": 202, "loc": { "start": { - "line": 13, + "line": 12, "column": 4 }, "end": { - "line": 13, - "column": 21 + "line": 12, + "column": 18 } }, "object": { "type": "ArrayExpression", - "start": 223, - "end": 235, + "start": 188, + "end": 197, "loc": { "start": { - "line": 13, + "line": 12, "column": 4 }, "end": { - "line": 13, - "column": 16 + "line": 12, + "column": 13 } }, "elements": [ { "type": "Identifier", - "start": 224, - "end": 225, + "start": 189, + "end": 190, "loc": { "start": { - "line": 13, + "line": 12, "column": 5 }, "end": { - "line": 13, + "line": 12, "column": 6 }, "identifierName": "b" @@ -1722,15 +1354,15 @@ }, { "type": "Identifier", - "start": 227, - "end": 228, + "start": 192, + "end": 193, "loc": { "start": { - "line": 13, + "line": 12, "column": 8 }, "end": { - "line": 13, + "line": 12, "column": 9 }, "identifierName": "d" @@ -1739,52 +1371,35 @@ }, { "type": "Identifier", - "start": 230, - "end": 231, + "start": 195, + "end": 196, "loc": { "start": { - "line": 13, + "line": 12, "column": 11 }, "end": { - "line": 13, + "line": 12, "column": 12 }, "identifierName": "g" }, "name": "g" - }, - { - "type": "Identifier", - "start": 233, - "end": 234, - "loc": { - "start": { - "line": 13, - "column": 14 - }, - "end": { - "line": 13, - "column": 15 - }, - "identifierName": "h" - }, - "name": "h" } ] }, "property": { "type": "Identifier", - "start": 236, - "end": 240, + "start": 198, + "end": 202, "loc": { "start": { - "line": 13, - "column": 17 + "line": 12, + "column": 14 }, "end": { - "line": 13, - "column": 21 + "line": 12, + "column": 18 }, "identifierName": "join" }, @@ -1795,16 +1410,16 @@ "arguments": [ { "type": "StringLiteral", - "start": 241, - "end": 243, + "start": 203, + "end": 205, "loc": { "start": { - "line": 13, - "column": 22 + "line": 12, + "column": 19 }, "end": { - "line": 13, - "column": 24 + "line": 12, + "column": 21 } }, "extra": { @@ -1825,44 +1440,44 @@ }, { "type": "MatchCase", - "start": 247, - "end": 288, + "start": 209, + "end": 242, "loc": { "start": { - "line": 14, + "line": 13, "column": 2 }, "end": { - "line": 14, - "column": 43 + "line": 13, + "column": 35 } }, "test": { - "type": "ObjectExpression", - "start": 249, - "end": 268, + "type": "ObjectPattern", + "start": 211, + "end": 222, "loc": { "start": { - "line": 14, + "line": 13, "column": 4 }, "end": { - "line": 14, - "column": 23 + "line": 13, + "column": 15 } }, "properties": [ { "type": "ObjectProperty", - "start": 251, - "end": 252, + "start": 213, + "end": 214, "loc": { "start": { - "line": 14, + "line": 13, "column": 6 }, "end": { - "line": 14, + "line": 13, "column": 7 } }, @@ -1871,15 +1486,15 @@ "computed": false, "key": { "type": "Identifier", - "start": 251, - "end": 252, + "start": 213, + "end": 214, "loc": { "start": { - "line": 14, + "line": 13, "column": 6 }, "end": { - "line": 14, + "line": 13, "column": 7 }, "identifierName": "a" @@ -1888,15 +1503,15 @@ }, "value": { "type": "Identifier", - "start": 251, - "end": 252, + "start": 213, + "end": 214, "loc": { "start": { - "line": 14, + "line": 13, "column": 6 }, "end": { - "line": 14, + "line": 13, "column": 7 }, "identifierName": "a" @@ -1908,86 +1523,31 @@ } }, { - "type": "ObjectProperty", - "start": 254, - "end": 260, + "type": "RestProperty", + "start": 216, + "end": 220, "loc": { "start": { - "line": 14, + "line": 13, "column": 9 }, "end": { - "line": 14, - "column": 15 - } - }, - "method": false, - "shorthand": false, - "computed": false, - "key": { - "type": "Identifier", - "start": 254, - "end": 255, - "loc": { - "start": { - "line": 14, - "column": 9 - }, - "end": { - "line": 14, - "column": 10 - }, - "identifierName": "b" - }, - "name": "b" - }, - "value": { - "type": "StringLiteral", - "start": 257, - "end": 260, - "loc": { - "start": { - "line": 14, - "column": 12 - }, - "end": { - "line": 14, - "column": 15 - } - }, - "extra": { - "rawValue": "b", - "raw": "'b'" - }, - "value": "b" - } - }, - { - "type": "SpreadProperty", - "start": 262, - "end": 266, - "loc": { - "start": { - "line": 14, - "column": 17 - }, - "end": { - "line": 14, - "column": 21 + "line": 13, + "column": 13 } }, "argument": { "type": "Identifier", - "start": 265, - "end": 266, + "start": 219, + "end": 220, "loc": { "start": { - "line": 14, - "column": 20 + "line": 13, + "column": 12 }, "end": { - "line": 14, - "column": 21 + "line": 13, + "column": 13 }, "identifierName": "c" }, @@ -1998,73 +1558,73 @@ }, "consequent": { "type": "ExpressionStatement", - "start": 270, - "end": 288, + "start": 224, + "end": 242, "loc": { "start": { - "line": 14, - "column": 25 + "line": 13, + "column": 17 }, "end": { - "line": 14, - "column": 43 + "line": 13, + "column": 35 } }, "expression": { "type": "CallExpression", - "start": 270, - "end": 288, + "start": 224, + "end": 242, "loc": { "start": { - "line": 14, - "column": 25 + "line": 13, + "column": 17 }, "end": { - "line": 14, - "column": 43 + "line": 13, + "column": 35 } }, "callee": { "type": "MemberExpression", - "start": 270, - "end": 284, + "start": 224, + "end": 238, "loc": { "start": { - "line": 14, - "column": 25 + "line": 13, + "column": 17 }, "end": { - "line": 14, - "column": 39 + "line": 13, + "column": 31 } }, "object": { "type": "ArrayExpression", - "start": 270, - "end": 279, + "start": 224, + "end": 233, "loc": { "start": { - "line": 14, - "column": 25 + "line": 13, + "column": 17 }, "end": { - "line": 14, - "column": 34 + "line": 13, + "column": 26 } }, "elements": [ { "type": "Identifier", - "start": 271, - "end": 272, + "start": 225, + "end": 226, "loc": { "start": { - "line": 14, - "column": 26 + "line": 13, + "column": 18 }, "end": { - "line": 14, - "column": 27 + "line": 13, + "column": 19 }, "identifierName": "a" }, @@ -2072,16 +1632,16 @@ }, { "type": "Identifier", - "start": 274, - "end": 275, + "start": 228, + "end": 229, "loc": { "start": { - "line": 14, - "column": 29 + "line": 13, + "column": 21 }, "end": { - "line": 14, - "column": 30 + "line": 13, + "column": 22 }, "identifierName": "b" }, @@ -2089,16 +1649,16 @@ }, { "type": "Identifier", - "start": 277, - "end": 278, + "start": 231, + "end": 232, "loc": { "start": { - "line": 14, - "column": 32 + "line": 13, + "column": 24 }, "end": { - "line": 14, - "column": 33 + "line": 13, + "column": 25 }, "identifierName": "c" }, @@ -2108,16 +1668,16 @@ }, "property": { "type": "Identifier", - "start": 280, - "end": 284, + "start": 234, + "end": 238, "loc": { "start": { - "line": 14, - "column": 35 + "line": 13, + "column": 27 }, "end": { - "line": 14, - "column": 39 + "line": 13, + "column": 31 }, "identifierName": "join" }, @@ -2128,16 +1688,16 @@ "arguments": [ { "type": "StringLiteral", - "start": 285, - "end": 287, + "start": 239, + "end": 241, "loc": { "start": { - "line": 14, - "column": 40 + "line": 13, + "column": 32 }, "end": { - "line": 14, - "column": 42 + "line": 13, + "column": 34 } }, "extra": { From 4ab4179f1fff2912bca835c34258c29f8eb97791 Mon Sep 17 00:00:00 2001 From: Alex Rattray Date: Sat, 3 Jun 2017 21:07:13 -0700 Subject: [PATCH 06/12] Enforce at least one case --- src/plugins/lightscript.js | 4 ++++ test/fixtures/lightscript/match/illegal-no-cases/actual.js | 1 + test/fixtures/lightscript/match/illegal-no-cases/options.json | 3 +++ 3 files changed, 8 insertions(+) create mode 100644 test/fixtures/lightscript/match/illegal-no-cases/actual.js create mode 100644 test/fixtures/lightscript/match/illegal-no-cases/options.json diff --git a/src/plugins/lightscript.js b/src/plugins/lightscript.js index ee60c0b723..30c588b37e 100644 --- a/src/plugins/lightscript.js +++ b/src/plugins/lightscript.js @@ -587,6 +587,10 @@ pp.parseMatch = function (node, isExpression) { node.cases.push(matchCase); } + if (!node.cases.length) { + this.unexpected(null, tt.bitwiseOR); + } + return this.finishNode(node, isExpression ? "MatchExpression" : "MatchStatement"); }; 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)" +} From df8b03ad93f9daeddfcbcb1b305a77d4c47c5f09 Mon Sep 17 00:00:00 2001 From: Alex Rattray Date: Wed, 7 Jun 2017 09:59:29 -0700 Subject: [PATCH 07/12] Special parsing of within --- src/parser/expression.js | 19 +- src/plugins/lightscript.js | 6 + .../match/illegal-not-call/actual.js | 2 + .../match/illegal-not-call/options.json | 3 + test/fixtures/lightscript/match/not/actual.js | 9 + .../lightscript/match/not/expected.json | 1118 +++++++++++++++++ 6 files changed, 1153 insertions(+), 4 deletions(-) create mode 100644 test/fixtures/lightscript/match/illegal-not-call/actual.js create mode 100644 test/fixtures/lightscript/match/illegal-not-call/options.json create mode 100644 test/fixtures/lightscript/match/not/actual.js create mode 100644 test/fixtures/lightscript/match/not/expected.json diff --git a/src/parser/expression.js b/src/parser/expression.js index 563d2ae522..01fda4f45c 100644 --- a/src/parser/expression.js +++ b/src/parser/expression.js @@ -294,6 +294,7 @@ pp.parseMaybeUnary = function (refShorthandDefaultPos) { const matchCaseBinaryPlusMin = this.hasPlugin("lightscript") && this.state.inMatchCaseTest && this.match(tt.plusMin) && + this.state.tokens[this.state.tokens.length - 1].value !== "!" && this.isNextCharWhitespace(); if (this.state.type.prefix && !matchCaseBinaryPlusMin) { @@ -312,7 +313,19 @@ pp.parseMaybeUnary = function (refShorthandDefaultPos) { this.next(); const argType = this.state.type; - node.argument = this.parseMaybeUnary(); + + // change precedence / allow autofill of `not` within `match` test + if (this.hasPlugin("lightscript") && node.operator === "!" && this.state.inMatchCaseTest && !argType.startsExpr) { + if (this.match(tt.colon) || this.match(tt.logicalOR) || this.match(tt.logicalAND)) { + // allow `| not:`, `| !!:`, `| not or x:` + node.argument = this.parseMatchCasePlaceholder(); + } else { + // change precedence of `| not < 3:` to `!(x < 3)` from `(!x) < 3` + node.argument = this.parseExprOps(); + } + } else { + node.argument = this.parseMaybeUnary(); + } this.addExtra(node, "parenthesizedArgument", argType === tt.parenL && (!node.argument.extra || !node.argument.extra.parenthesized)); @@ -762,9 +775,7 @@ pp.parseExprAtom = function (refShorthandDefaultPos) { default: if (this.hasPlugin("lightscript") && this.allowMatchCasePlaceholder()) { - // use the blank space as an empty value (perhaps 0-length would be better) - node = this.startNodeAt(this.state.lastTokEnd, this.state.lastTokEndLoc); - return this.finishNodeAt(node, "PlaceholderExpression", this.state.start, this.state.startLoc); + return this.parseMatchCasePlaceholder(); } this.unexpected(); } diff --git a/src/plugins/lightscript.js b/src/plugins/lightscript.js index 30c588b37e..7268fe2d59 100644 --- a/src/plugins/lightscript.js +++ b/src/plugins/lightscript.js @@ -700,6 +700,12 @@ pp.parseMatchCaseTestPattern = function () { return node; }; +pp.parseMatchCasePlaceholder = function () { + // use the blank space as an empty value (perhaps 0-length would be better) + const node = this.startNodeAt(this.state.lastTokEnd, this.state.lastTokEndLoc); + return this.finishNodeAt(node, "PlaceholderExpression", this.state.start, this.state.startLoc); +}; + export default function (instance) { 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/not/actual.js b/test/fixtures/lightscript/match/not/actual.js new file mode 100644 index 0000000000..7a92dad138 --- /dev/null +++ b/test/fixtures/lightscript/match/not/actual.js @@ -0,0 +1,9 @@ +match x: + | not: true + | !!: true + | not < 3: true + | not + 1: true + | ! ~f(): true + | not .prop: true + | not or not not and not: true + | ! or !! and !: true diff --git a/test/fixtures/lightscript/match/not/expected.json b/test/fixtures/lightscript/match/not/expected.json new file mode 100644 index 0000000000..b6d3310196 --- /dev/null +++ b/test/fixtures/lightscript/match/not/expected.json @@ -0,0 +1,1118 @@ +{ + "type": "File", + "start": 0, + "end": 165, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 9, + "column": 23 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 165, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 9, + "column": 23 + } + }, + "sourceType": "script", + "body": [ + { + "type": "MatchStatement", + "start": 0, + "end": 165, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 9, + "column": 23 + } + }, + "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": 22, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "test": { + "type": "UnaryExpression", + "start": 13, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "operator": "!", + "prefix": true, + "argument": { + "type": "PlaceholderExpression", + "start": 16, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 7 + } + } + }, + "extra": { + "parenthesizedArgument": false + } + }, + "consequent": { + "type": "ExpressionStatement", + "start": 18, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "expression": { + "type": "BooleanLiteral", + "start": 18, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "value": true + } + } + }, + { + "type": "MatchCase", + "start": 25, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 12 + } + }, + "test": { + "type": "UnaryExpression", + "start": 27, + "end": 29, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 6 + } + }, + "operator": "!", + "prefix": true, + "argument": { + "type": "UnaryExpression", + "start": 28, + "end": 29, + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 6 + } + }, + "operator": "!", + "prefix": true, + "argument": { + "type": "PlaceholderExpression", + "start": 29, + "end": 29, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 6 + } + } + }, + "extra": { + "parenthesizedArgument": false + } + }, + "extra": { + "parenthesizedArgument": false + } + }, + "consequent": { + "type": "ExpressionStatement", + "start": 31, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 12 + } + }, + "expression": { + "type": "BooleanLiteral", + "start": 31, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 12 + } + }, + "value": true + } + } + }, + { + "type": "MatchCase", + "start": 38, + "end": 53, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 17 + } + }, + "test": { + "type": "UnaryExpression", + "start": 40, + "end": 47, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 11 + } + }, + "operator": "!", + "prefix": true, + "argument": { + "type": "BinaryExpression", + "start": 44, + "end": 47, + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 11 + } + }, + "left": { + "type": "PlaceholderExpression", + "start": 43, + "end": 44, + "loc": { + "start": { + "line": 4, + "column": 7 + }, + "end": { + "line": 4, + "column": 8 + } + } + }, + "operator": "<", + "right": { + "type": "NumericLiteral", + "start": 46, + "end": 47, + "loc": { + "start": { + "line": 4, + "column": 10 + }, + "end": { + "line": 4, + "column": 11 + } + }, + "extra": { + "rawValue": 3, + "raw": "3" + }, + "value": 3 + } + }, + "extra": { + "parenthesizedArgument": false + } + }, + "consequent": { + "type": "ExpressionStatement", + "start": 49, + "end": 53, + "loc": { + "start": { + "line": 4, + "column": 13 + }, + "end": { + "line": 4, + "column": 17 + } + }, + "expression": { + "type": "BooleanLiteral", + "start": 49, + "end": 53, + "loc": { + "start": { + "line": 4, + "column": 13 + }, + "end": { + "line": 4, + "column": 17 + } + }, + "value": true + } + } + }, + { + "type": "MatchCase", + "start": 56, + "end": 71, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 17 + } + }, + "test": { + "type": "BinaryExpression", + "start": 58, + "end": 65, + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 11 + } + }, + "left": { + "type": "UnaryExpression", + "start": 58, + "end": 61, + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 7 + } + }, + "operator": "!", + "prefix": true, + "argument": { + "type": "PlaceholderExpression", + "start": 61, + "end": 62, + "loc": { + "start": { + "line": 5, + "column": 7 + }, + "end": { + "line": 5, + "column": 8 + } + } + }, + "extra": { + "parenthesizedArgument": false + } + }, + "operator": "+", + "right": { + "type": "NumericLiteral", + "start": 64, + "end": 65, + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 11 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + }, + "consequent": { + "type": "ExpressionStatement", + "start": 67, + "end": 71, + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 17 + } + }, + "expression": { + "type": "BooleanLiteral", + "start": 67, + "end": 71, + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 17 + } + }, + "value": true + } + } + }, + { + "type": "MatchCase", + "start": 74, + "end": 88, + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 16 + } + }, + "test": { + "type": "UnaryExpression", + "start": 76, + "end": 82, + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 10 + } + }, + "operator": "!", + "prefix": true, + "argument": { + "type": "TildeCallExpression", + "start": 78, + "end": 82, + "loc": { + "start": { + "line": 6, + "column": 6 + }, + "end": { + "line": 6, + "column": 10 + } + }, + "left": { + "type": "PlaceholderExpression", + "start": 77, + "end": 78, + "loc": { + "start": { + "line": 6, + "column": 5 + }, + "end": { + "line": 6, + "column": 6 + } + } + }, + "right": { + "type": "Identifier", + "start": 79, + "end": 80, + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 8 + }, + "identifierName": "f" + }, + "name": "f" + }, + "arguments": [] + }, + "extra": { + "parenthesizedArgument": false + } + }, + "consequent": { + "type": "ExpressionStatement", + "start": 84, + "end": 88, + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 6, + "column": 16 + } + }, + "expression": { + "type": "BooleanLiteral", + "start": 84, + "end": 88, + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 6, + "column": 16 + } + }, + "value": true + } + } + }, + { + "type": "MatchCase", + "start": 91, + "end": 108, + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 19 + } + }, + "test": { + "type": "UnaryExpression", + "start": 93, + "end": 102, + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 13 + } + }, + "operator": "!", + "prefix": true, + "argument": { + "type": "MemberExpression", + "start": 97, + "end": 102, + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 13 + } + }, + "object": { + "type": "PlaceholderExpression", + "start": 96, + "end": 97, + "loc": { + "start": { + "line": 7, + "column": 7 + }, + "end": { + "line": 7, + "column": 8 + } + } + }, + "property": { + "type": "Identifier", + "start": 98, + "end": 102, + "loc": { + "start": { + "line": 7, + "column": 9 + }, + "end": { + "line": 7, + "column": 13 + }, + "identifierName": "prop" + }, + "name": "prop" + }, + "computed": false + }, + "extra": { + "parenthesizedArgument": false + } + }, + "consequent": { + "type": "ExpressionStatement", + "start": 104, + "end": 108, + "loc": { + "start": { + "line": 7, + "column": 15 + }, + "end": { + "line": 7, + "column": 19 + } + }, + "expression": { + "type": "BooleanLiteral", + "start": 104, + "end": 108, + "loc": { + "start": { + "line": 7, + "column": 15 + }, + "end": { + "line": 7, + "column": 19 + } + }, + "value": true + } + } + }, + { + "type": "MatchCase", + "start": 111, + "end": 141, + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 32 + } + }, + "test": { + "type": "LogicalExpression", + "start": 113, + "end": 135, + "loc": { + "start": { + "line": 8, + "column": 4 + }, + "end": { + "line": 8, + "column": 26 + } + }, + "left": { + "type": "UnaryExpression", + "start": 113, + "end": 116, + "loc": { + "start": { + "line": 8, + "column": 4 + }, + "end": { + "line": 8, + "column": 7 + } + }, + "operator": "!", + "prefix": true, + "argument": { + "type": "PlaceholderExpression", + "start": 116, + "end": 117, + "loc": { + "start": { + "line": 8, + "column": 7 + }, + "end": { + "line": 8, + "column": 8 + } + } + }, + "extra": { + "parenthesizedArgument": false + } + }, + "operator": "||", + "right": { + "type": "LogicalExpression", + "start": 120, + "end": 135, + "loc": { + "start": { + "line": 8, + "column": 11 + }, + "end": { + "line": 8, + "column": 26 + } + }, + "left": { + "type": "UnaryExpression", + "start": 120, + "end": 127, + "loc": { + "start": { + "line": 8, + "column": 11 + }, + "end": { + "line": 8, + "column": 18 + } + }, + "operator": "!", + "prefix": true, + "argument": { + "type": "UnaryExpression", + "start": 124, + "end": 127, + "loc": { + "start": { + "line": 8, + "column": 15 + }, + "end": { + "line": 8, + "column": 18 + } + }, + "operator": "!", + "prefix": true, + "argument": { + "type": "PlaceholderExpression", + "start": 127, + "end": 128, + "loc": { + "start": { + "line": 8, + "column": 18 + }, + "end": { + "line": 8, + "column": 19 + } + } + }, + "extra": { + "parenthesizedArgument": false + } + }, + "extra": { + "parenthesizedArgument": false + } + }, + "operator": "&&", + "right": { + "type": "UnaryExpression", + "start": 132, + "end": 135, + "loc": { + "start": { + "line": 8, + "column": 23 + }, + "end": { + "line": 8, + "column": 26 + } + }, + "operator": "!", + "prefix": true, + "argument": { + "type": "PlaceholderExpression", + "start": 135, + "end": 135, + "loc": { + "start": { + "line": 8, + "column": 26 + }, + "end": { + "line": 8, + "column": 26 + } + } + }, + "extra": { + "parenthesizedArgument": false + } + } + } + }, + "consequent": { + "type": "ExpressionStatement", + "start": 137, + "end": 141, + "loc": { + "start": { + "line": 8, + "column": 28 + }, + "end": { + "line": 8, + "column": 32 + } + }, + "expression": { + "type": "BooleanLiteral", + "start": 137, + "end": 141, + "loc": { + "start": { + "line": 8, + "column": 28 + }, + "end": { + "line": 8, + "column": 32 + } + }, + "value": true + } + } + }, + { + "type": "MatchCase", + "start": 144, + "end": 165, + "loc": { + "start": { + "line": 9, + "column": 2 + }, + "end": { + "line": 9, + "column": 23 + } + }, + "test": { + "type": "LogicalExpression", + "start": 146, + "end": 159, + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 17 + } + }, + "left": { + "type": "UnaryExpression", + "start": 146, + "end": 147, + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 5 + } + }, + "operator": "!", + "prefix": true, + "argument": { + "type": "PlaceholderExpression", + "start": 147, + "end": 148, + "loc": { + "start": { + "line": 9, + "column": 5 + }, + "end": { + "line": 9, + "column": 6 + } + } + }, + "extra": { + "parenthesizedArgument": false + } + }, + "operator": "||", + "right": { + "type": "LogicalExpression", + "start": 151, + "end": 159, + "loc": { + "start": { + "line": 9, + "column": 9 + }, + "end": { + "line": 9, + "column": 17 + } + }, + "left": { + "type": "UnaryExpression", + "start": 151, + "end": 153, + "loc": { + "start": { + "line": 9, + "column": 9 + }, + "end": { + "line": 9, + "column": 11 + } + }, + "operator": "!", + "prefix": true, + "argument": { + "type": "UnaryExpression", + "start": 152, + "end": 153, + "loc": { + "start": { + "line": 9, + "column": 10 + }, + "end": { + "line": 9, + "column": 11 + } + }, + "operator": "!", + "prefix": true, + "argument": { + "type": "PlaceholderExpression", + "start": 153, + "end": 154, + "loc": { + "start": { + "line": 9, + "column": 11 + }, + "end": { + "line": 9, + "column": 12 + } + } + }, + "extra": { + "parenthesizedArgument": false + } + }, + "extra": { + "parenthesizedArgument": false + } + }, + "operator": "&&", + "right": { + "type": "UnaryExpression", + "start": 158, + "end": 159, + "loc": { + "start": { + "line": 9, + "column": 16 + }, + "end": { + "line": 9, + "column": 17 + } + }, + "operator": "!", + "prefix": true, + "argument": { + "type": "PlaceholderExpression", + "start": 159, + "end": 159, + "loc": { + "start": { + "line": 9, + "column": 17 + }, + "end": { + "line": 9, + "column": 17 + } + } + }, + "extra": { + "parenthesizedArgument": false + } + } + } + }, + "consequent": { + "type": "ExpressionStatement", + "start": 161, + "end": 165, + "loc": { + "start": { + "line": 9, + "column": 19 + }, + "end": { + "line": 9, + "column": 23 + } + }, + "expression": { + "type": "BooleanLiteral", + "start": 161, + "end": 165, + "loc": { + "start": { + "line": 9, + "column": 19 + }, + "end": { + "line": 9, + "column": 23 + } + }, + "value": true + } + } + } + ] + } + ], + "directives": [] + } +} \ No newline at end of file From 5b3a4112bc1a0b5fff1bf648905dfb658f5314de Mon Sep 17 00:00:00 2001 From: Alex Rattray Date: Wed, 7 Jun 2017 14:13:42 -0700 Subject: [PATCH 08/12] Change destructuring, remove 'as' --- src/parser/expression.js | 6 - src/plugins/lightscript.js | 36 +- .../commaless/obj-pattern/actual.js | 8 +- .../commaless/obj-pattern/expected.json | 206 ++++- .../commaless/obj-pattern/options.json | 3 + .../match/basic-renaming/actual.js | 6 - .../match/basic-renaming/expected.json | 509 ------------ .../match/curly-consequent/actual.js | 2 +- .../match/curly-consequent/expected.json | 127 ++- .../match/destructured-renaming/actual.js | 4 +- .../match/destructured-renaming/expected.json | 210 ++--- .../match/destructuring-arr/actual.js | 2 +- .../match/destructuring-arr/expected.json | 487 ++++-------- .../destructuring-obj-arr-mixed/expected.json | 3 +- .../match/destructuring-obj-basic/actual.js | 2 + .../destructuring-obj-basic/expected.json | 276 +++++++ .../match/destructuring-obj-default/actual.js | 2 + .../destructuring-obj-default/expected.json | 311 ++++++++ .../match/destructuring-obj/actual.js | 2 +- .../match/destructuring-obj/expected.json | 746 ++++++++++-------- .../illegal-destructure-and-as/actual.js | 2 - .../illegal-destructure-and-as/options.json | 3 - .../illegal-destructure-and-with/actual.js | 2 + .../illegal-destructure-and-with/options.json | 3 + .../match/illegal-multi-pattern-1/actual.js | 2 - .../illegal-multi-pattern-1/options.json | 3 - .../match/illegal-multi-pattern-2/actual.js | 2 - .../illegal-multi-pattern-2/options.json | 3 - .../match/illegal-multi-pattern-3/actual.js | 2 - .../illegal-multi-pattern-3/options.json | 3 - .../match/illegal-multi-pattern-4/actual.js | 2 - .../illegal-multi-pattern-4/options.json | 3 - .../lightscript/match/nested/actual.js | 2 +- .../lightscript/match/nested/expected.json | 123 ++- .../actual.js | 2 +- .../options.json | 2 +- .../lightscript/match/plain-obj-arr/actual.js | 5 + .../match/plain-obj-arr/expected.json | 664 ++++++++++++++++ 38 files changed, 2311 insertions(+), 1465 deletions(-) create mode 100644 test/fixtures/lightscript/commaless/obj-pattern/options.json delete mode 100644 test/fixtures/lightscript/match/basic-renaming/actual.js delete mode 100644 test/fixtures/lightscript/match/basic-renaming/expected.json create mode 100644 test/fixtures/lightscript/match/destructuring-obj-basic/actual.js create mode 100644 test/fixtures/lightscript/match/destructuring-obj-basic/expected.json create mode 100644 test/fixtures/lightscript/match/destructuring-obj-default/actual.js create mode 100644 test/fixtures/lightscript/match/destructuring-obj-default/expected.json delete mode 100644 test/fixtures/lightscript/match/illegal-destructure-and-as/actual.js delete mode 100644 test/fixtures/lightscript/match/illegal-destructure-and-as/options.json create mode 100644 test/fixtures/lightscript/match/illegal-destructure-and-with/actual.js create mode 100644 test/fixtures/lightscript/match/illegal-destructure-and-with/options.json delete mode 100644 test/fixtures/lightscript/match/illegal-multi-pattern-1/actual.js delete mode 100644 test/fixtures/lightscript/match/illegal-multi-pattern-1/options.json delete mode 100644 test/fixtures/lightscript/match/illegal-multi-pattern-2/actual.js delete mode 100644 test/fixtures/lightscript/match/illegal-multi-pattern-2/options.json delete mode 100644 test/fixtures/lightscript/match/illegal-multi-pattern-3/actual.js delete mode 100644 test/fixtures/lightscript/match/illegal-multi-pattern-3/options.json delete mode 100644 test/fixtures/lightscript/match/illegal-multi-pattern-4/actual.js delete mode 100644 test/fixtures/lightscript/match/illegal-multi-pattern-4/options.json create mode 100644 test/fixtures/lightscript/match/plain-obj-arr/actual.js create mode 100644 test/fixtures/lightscript/match/plain-obj-arr/expected.json diff --git a/src/parser/expression.js b/src/parser/expression.js index 01fda4f45c..01c551c710 100644 --- a/src/parser/expression.js +++ b/src/parser/expression.js @@ -691,9 +691,6 @@ pp.parseExprAtom = function (refShorthandDefaultPos) { return this.parseParenAndDistinguishExpression(null, null, canBeArrow); case tt.bracketL: - if (this.hasPlugin("lightscript") && this.state.inMatchCaseTest) { - return this.parseMatchCaseTestPattern(); - } node = this.startNode(); this.next(); if (this.hasPlugin("lightscript") && this.match(tt._for)) { @@ -704,9 +701,6 @@ pp.parseExprAtom = function (refShorthandDefaultPos) { return this.finishNode(node, "ArrayExpression"); case tt.braceL: - if (this.hasPlugin("lightscript") && this.state.inMatchCaseTest) { - return this.parseMatchCaseTestPattern(); - } return this.parseObj(false, refShorthandDefaultPos); case tt._function: diff --git a/src/plugins/lightscript.js b/src/plugins/lightscript.js index 7268fe2d59..a3428db0ce 100644 --- a/src/plugins/lightscript.js +++ b/src/plugins/lightscript.js @@ -581,7 +581,7 @@ pp.parseMatch = function (node, isExpression) { } const matchCase = this.parseMatchCase(isExpression); - if (matchCase.test.type === "MatchElse") { + if (matchCase.test && matchCase.test.type === "MatchElse") { hasUsedElse = true; } node.cases.push(matchCase); @@ -597,16 +597,7 @@ pp.parseMatch = function (node, isExpression) { pp.parseMatchCase = function (isExpression) { const node = this.startNode(); - this.state.allowMatchCaseTestPattern = true; - node.test = this.parseMatchCaseTest(); - if (this.isContextual("as")) { - if (!this.state.allowMatchCaseTestPattern) { - this.unexpected(null, "Cannot rename after destructuring."); - } - this.next(); - node.binding = this.parseBindingAtom(); - } - this.state.allowMatchCaseTestPattern = false; + this.parseMatchCaseTest(node); if (isExpression) { // disallow return/continue/break, etc. c/p doExpression @@ -626,24 +617,37 @@ pp.parseMatchCase = function (isExpression) { return this.finishNode(node, "MatchCase"); }; -pp.parseMatchCaseTest = function () { +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."); - let test; if (this.match(tt._else)) { const elseNode = this.startNode(); this.next(); - test = this.finishNode(elseNode, "MatchElse"); + node.test = this.finishNode(elseNode, "MatchElse"); + } else if (this.match(tt.braceL) || this.match(tt.bracketL)) { + // disambiguate `| { a, b }:` from `| { a, b }~someFn():` + const bindingOrTest = this.parseExprOps(false, { start: 0 }); + try { + node.binding = this.toAssignable(bindingOrTest.__clone(), true, 'match test'); + node.test = null; + } catch (_err) { + node.test = bindingOrTest; + } } else { - test = this.parseExprOps(); + node.test = this.parseExprOps(); + } + + if (this.eat(tt._with)) { + 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(); } this.state.inMatchCaseTest = false; - return test; }; pp.isBinaryTokenForMatchCase = function (tokenType) { 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/basic-renaming/actual.js b/test/fixtures/lightscript/match/basic-renaming/actual.js deleted file mode 100644 index c43b0dbbfb..0000000000 --- a/test/fixtures/lightscript/match/basic-renaming/actual.js +++ /dev/null @@ -1,6 +0,0 @@ -match x: - | a: 1 - | b: b - | c as c: c - | as as as: as - | ~isNumber() as n: n + 1 diff --git a/test/fixtures/lightscript/match/basic-renaming/expected.json b/test/fixtures/lightscript/match/basic-renaming/expected.json deleted file mode 100644 index 4810f40b10..0000000000 --- a/test/fixtures/lightscript/match/basic-renaming/expected.json +++ /dev/null @@ -1,509 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 85, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 6, - "column": 27 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 85, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 6, - "column": 27 - } - }, - "sourceType": "script", - "body": [ - { - "type": "MatchStatement", - "start": 0, - "end": 85, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 6, - "column": 27 - } - }, - "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": "NumericLiteral", - "start": 16, - "end": 17, - "loc": { - "start": { - "line": 2, - "column": 7 - }, - "end": { - "line": 2, - "column": 8 - } - }, - "extra": { - "rawValue": 1, - "raw": "1" - }, - "value": 1 - } - } - }, - { - "type": "MatchCase", - "start": 20, - "end": 26, - "loc": { - "start": { - "line": 3, - "column": 2 - }, - "end": { - "line": 3, - "column": 8 - } - }, - "test": { - "type": "Identifier", - "start": 22, - "end": 23, - "loc": { - "start": { - "line": 3, - "column": 4 - }, - "end": { - "line": 3, - "column": 5 - }, - "identifierName": "b" - }, - "name": "b" - }, - "consequent": { - "type": "ExpressionStatement", - "start": 25, - "end": 26, - "loc": { - "start": { - "line": 3, - "column": 7 - }, - "end": { - "line": 3, - "column": 8 - } - }, - "expression": { - "type": "Identifier", - "start": 25, - "end": 26, - "loc": { - "start": { - "line": 3, - "column": 7 - }, - "end": { - "line": 3, - "column": 8 - }, - "identifierName": "b" - }, - "name": "b" - } - } - }, - { - "type": "MatchCase", - "start": 29, - "end": 40, - "loc": { - "start": { - "line": 4, - "column": 2 - }, - "end": { - "line": 4, - "column": 13 - } - }, - "test": { - "type": "Identifier", - "start": 31, - "end": 32, - "loc": { - "start": { - "line": 4, - "column": 4 - }, - "end": { - "line": 4, - "column": 5 - }, - "identifierName": "c" - }, - "name": "c" - }, - "binding": { - "type": "Identifier", - "start": 36, - "end": 37, - "loc": { - "start": { - "line": 4, - "column": 9 - }, - "end": { - "line": 4, - "column": 10 - }, - "identifierName": "c" - }, - "name": "c" - }, - "consequent": { - "type": "ExpressionStatement", - "start": 39, - "end": 40, - "loc": { - "start": { - "line": 4, - "column": 12 - }, - "end": { - "line": 4, - "column": 13 - } - }, - "expression": { - "type": "Identifier", - "start": 39, - "end": 40, - "loc": { - "start": { - "line": 4, - "column": 12 - }, - "end": { - "line": 4, - "column": 13 - }, - "identifierName": "c" - }, - "name": "c" - } - } - }, - { - "type": "MatchCase", - "start": 43, - "end": 57, - "loc": { - "start": { - "line": 5, - "column": 2 - }, - "end": { - "line": 5, - "column": 16 - } - }, - "test": { - "type": "Identifier", - "start": 45, - "end": 47, - "loc": { - "start": { - "line": 5, - "column": 4 - }, - "end": { - "line": 5, - "column": 6 - }, - "identifierName": "as" - }, - "name": "as" - }, - "binding": { - "type": "Identifier", - "start": 51, - "end": 53, - "loc": { - "start": { - "line": 5, - "column": 10 - }, - "end": { - "line": 5, - "column": 12 - }, - "identifierName": "as" - }, - "name": "as" - }, - "consequent": { - "type": "ExpressionStatement", - "start": 55, - "end": 57, - "loc": { - "start": { - "line": 5, - "column": 14 - }, - "end": { - "line": 5, - "column": 16 - } - }, - "expression": { - "type": "Identifier", - "start": 55, - "end": 57, - "loc": { - "start": { - "line": 5, - "column": 14 - }, - "end": { - "line": 5, - "column": 16 - }, - "identifierName": "as" - }, - "name": "as" - } - } - }, - { - "type": "MatchCase", - "start": 60, - "end": 85, - "loc": { - "start": { - "line": 6, - "column": 2 - }, - "end": { - "line": 6, - "column": 27 - } - }, - "test": { - "type": "TildeCallExpression", - "start": 62, - "end": 73, - "loc": { - "start": { - "line": 6, - "column": 4 - }, - "end": { - "line": 6, - "column": 15 - } - }, - "left": { - "type": "PlaceholderExpression", - "start": 61, - "end": 62, - "loc": { - "start": { - "line": 6, - "column": 3 - }, - "end": { - "line": 6, - "column": 4 - } - } - }, - "right": { - "type": "Identifier", - "start": 63, - "end": 71, - "loc": { - "start": { - "line": 6, - "column": 5 - }, - "end": { - "line": 6, - "column": 13 - }, - "identifierName": "isNumber" - }, - "name": "isNumber" - }, - "arguments": [] - }, - "binding": { - "type": "Identifier", - "start": 77, - "end": 78, - "loc": { - "start": { - "line": 6, - "column": 19 - }, - "end": { - "line": 6, - "column": 20 - }, - "identifierName": "n" - }, - "name": "n" - }, - "consequent": { - "type": "ExpressionStatement", - "start": 80, - "end": 85, - "loc": { - "start": { - "line": 6, - "column": 22 - }, - "end": { - "line": 6, - "column": 27 - } - }, - "expression": { - "type": "BinaryExpression", - "start": 80, - "end": 85, - "loc": { - "start": { - "line": 6, - "column": 22 - }, - "end": { - "line": 6, - "column": 27 - } - }, - "left": { - "type": "Identifier", - "start": 80, - "end": 81, - "loc": { - "start": { - "line": 6, - "column": 22 - }, - "end": { - "line": 6, - "column": 23 - }, - "identifierName": "n" - }, - "name": "n" - }, - "operator": "+", - "right": { - "type": "NumericLiteral", - "start": 84, - "end": 85, - "loc": { - "start": { - "line": 6, - "column": 26 - }, - "end": { - "line": 6, - "column": 27 - } - }, - "extra": { - "rawValue": 1, - "raw": "1" - }, - "value": 1 - } - } - } - } - ] - } - ], - "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 index 308471a449..70c9b33348 100644 --- a/test/fixtures/lightscript/match/curly-consequent/actual.js +++ b/test/fixtures/lightscript/match/curly-consequent/actual.js @@ -3,7 +3,7 @@ a = match x: | z { "z" } - | a as b { + | a with { b } { b b } diff --git a/test/fixtures/lightscript/match/curly-consequent/expected.json b/test/fixtures/lightscript/match/curly-consequent/expected.json index fbb47ccaef..359b3f2051 100644 --- a/test/fixtures/lightscript/match/curly-consequent/expected.json +++ b/test/fixtures/lightscript/match/curly-consequent/expected.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 95, + "end": 101, "loc": { "start": { "line": 1, @@ -15,7 +15,7 @@ "program": { "type": "Program", "start": 0, - "end": 95, + "end": 101, "loc": { "start": { "line": 1, @@ -31,7 +31,7 @@ { "type": "VariableDeclaration", "start": 0, - "end": 95, + "end": 101, "loc": { "start": { "line": 1, @@ -50,7 +50,7 @@ { "type": "VariableDeclarator", "start": 0, - "end": 95, + "end": 101, "loc": { "start": { "line": 1, @@ -81,7 +81,7 @@ "init": { "type": "MatchExpression", "start": 4, - "end": 95, + "end": 101, "loc": { "start": { "line": 1, @@ -289,7 +289,7 @@ { "type": "MatchCase", "start": 49, - "end": 75, + "end": 81, "loc": { "start": { "line": 6, @@ -318,30 +318,85 @@ "name": "a" }, "binding": { - "type": "Identifier", - "start": 56, - "end": 57, + "type": "ObjectPattern", + "start": 58, + "end": 63, "loc": { "start": { "line": 6, - "column": 9 + "column": 11 }, "end": { "line": 6, - "column": 10 - }, - "identifierName": "b" + "column": 16 + } }, - "name": "b" + "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": 58, - "end": 75, + "start": 64, + "end": 81, "loc": { "start": { "line": 6, - "column": 11 + "column": 17 }, "end": { "line": 9, @@ -351,8 +406,8 @@ "body": [ { "type": "ExpressionStatement", - "start": 64, - "end": 65, + "start": 70, + "end": 71, "loc": { "start": { "line": 7, @@ -365,8 +420,8 @@ }, "expression": { "type": "Identifier", - "start": 64, - "end": 65, + "start": 70, + "end": 71, "loc": { "start": { "line": 7, @@ -383,8 +438,8 @@ }, { "type": "ExpressionStatement", - "start": 70, - "end": 71, + "start": 76, + "end": 77, "loc": { "start": { "line": 8, @@ -397,8 +452,8 @@ }, "expression": { "type": "Identifier", - "start": 70, - "end": 71, + "start": 76, + "end": 77, "loc": { "start": { "line": 8, @@ -422,8 +477,8 @@ }, { "type": "MatchCase", - "start": 78, - "end": 95, + "start": 84, + "end": 101, "loc": { "start": { "line": 10, @@ -436,8 +491,8 @@ }, "test": { "type": "Identifier", - "start": 81, - "end": 82, + "start": 87, + "end": 88, "loc": { "start": { "line": 10, @@ -452,13 +507,13 @@ "name": "c", "extra": { "parenthesized": true, - "parenStart": 80 + "parenStart": 86 } }, "consequent": { "type": "BlockStatement", - "start": 84, - "end": 95, + "start": 90, + "end": 101, "loc": { "start": { "line": 10, @@ -472,8 +527,8 @@ "body": [ { "type": "ExpressionStatement", - "start": 90, - "end": 91, + "start": 96, + "end": 97, "loc": { "start": { "line": 11, @@ -486,8 +541,8 @@ }, "expression": { "type": "Identifier", - "start": 90, - "end": 91, + "start": 96, + "end": 97, "loc": { "start": { "line": 11, diff --git a/test/fixtures/lightscript/match/destructured-renaming/actual.js b/test/fixtures/lightscript/match/destructured-renaming/actual.js index 1428670473..be745c223f 100644 --- a/test/fixtures/lightscript/match/destructured-renaming/actual.js +++ b/test/fixtures/lightscript/match/destructured-renaming/actual.js @@ -1,3 +1,3 @@ match x: - | .a as { a, b = 1 }: a + b - | .0 and .1 as [ a, b ]: a + b + | .a with { a, b = 1 }: a + b + | .0 and .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 index 1759e1ddfc..c669c43850 100644 --- a/test/fixtures/lightscript/match/destructured-renaming/expected.json +++ b/test/fixtures/lightscript/match/destructured-renaming/expected.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 71, + "end": 75, "loc": { "start": { "line": 1, @@ -9,13 +9,13 @@ }, "end": { "line": 3, - "column": 32 + "column": 34 } }, "program": { "type": "Program", "start": 0, - "end": 71, + "end": 75, "loc": { "start": { "line": 1, @@ -23,7 +23,7 @@ }, "end": { "line": 3, - "column": 32 + "column": 34 } }, "sourceType": "script", @@ -31,7 +31,7 @@ { "type": "MatchStatement", "start": 0, - "end": 71, + "end": 75, "loc": { "start": { "line": 1, @@ -39,7 +39,7 @@ }, "end": { "line": 3, - "column": 32 + "column": 34 } }, "discriminant": { @@ -63,7 +63,7 @@ { "type": "MatchCase", "start": 11, - "end": 38, + "end": 40, "loc": { "start": { "line": 2, @@ -71,7 +71,7 @@ }, "end": { "line": 2, - "column": 29 + "column": 31 } }, "test": { @@ -124,31 +124,31 @@ }, "binding": { "type": "ObjectPattern", - "start": 19, - "end": 31, + "start": 21, + "end": 33, "loc": { "start": { "line": 2, - "column": 10 + "column": 12 }, "end": { "line": 2, - "column": 22 + "column": 24 } }, "properties": [ { "type": "ObjectProperty", - "start": 21, - "end": 22, + "start": 23, + "end": 24, "loc": { "start": { "line": 2, - "column": 12 + "column": 14 }, "end": { "line": 2, - "column": 13 + "column": 15 } }, "method": false, @@ -156,16 +156,16 @@ "computed": false, "key": { "type": "Identifier", - "start": 21, - "end": 22, + "start": 23, + "end": 24, "loc": { "start": { "line": 2, - "column": 12 + "column": 14 }, "end": { "line": 2, - "column": 13 + "column": 15 }, "identifierName": "a" }, @@ -173,16 +173,16 @@ }, "value": { "type": "Identifier", - "start": 21, - "end": 22, + "start": 23, + "end": 24, "loc": { "start": { "line": 2, - "column": 12 + "column": 14 }, "end": { "line": 2, - "column": 13 + "column": 15 }, "identifierName": "a" }, @@ -194,16 +194,16 @@ }, { "type": "ObjectProperty", - "start": 24, - "end": 29, + "start": 26, + "end": 31, "loc": { "start": { "line": 2, - "column": 15 + "column": 17 }, "end": { "line": 2, - "column": 20 + "column": 22 } }, "method": false, @@ -211,16 +211,16 @@ "computed": false, "key": { "type": "Identifier", - "start": 24, - "end": 25, + "start": 26, + "end": 27, "loc": { "start": { "line": 2, - "column": 15 + "column": 17 }, "end": { "line": 2, - "column": 16 + "column": 18 }, "identifierName": "b" }, @@ -228,30 +228,30 @@ }, "value": { "type": "AssignmentPattern", - "start": 24, - "end": 29, + "start": 26, + "end": 31, "loc": { "start": { "line": 2, - "column": 15 + "column": 17 }, "end": { "line": 2, - "column": 20 + "column": 22 } }, "left": { "type": "Identifier", - "start": 24, - "end": 25, + "start": 26, + "end": 27, "loc": { "start": { "line": 2, - "column": 15 + "column": 17 }, "end": { "line": 2, - "column": 16 + "column": 18 }, "identifierName": "b" }, @@ -259,16 +259,16 @@ }, "right": { "type": "NumericLiteral", - "start": 28, - "end": 29, + "start": 30, + "end": 31, "loc": { "start": { "line": 2, - "column": 19 + "column": 21 }, "end": { "line": 2, - "column": 20 + "column": 22 } }, "extra": { @@ -286,44 +286,44 @@ }, "consequent": { "type": "ExpressionStatement", - "start": 33, - "end": 38, + "start": 35, + "end": 40, "loc": { "start": { "line": 2, - "column": 24 + "column": 26 }, "end": { "line": 2, - "column": 29 + "column": 31 } }, "expression": { "type": "BinaryExpression", - "start": 33, - "end": 38, + "start": 35, + "end": 40, "loc": { "start": { "line": 2, - "column": 24 + "column": 26 }, "end": { "line": 2, - "column": 29 + "column": 31 } }, "left": { "type": "Identifier", - "start": 33, - "end": 34, + "start": 35, + "end": 36, "loc": { "start": { "line": 2, - "column": 24 + "column": 26 }, "end": { "line": 2, - "column": 25 + "column": 27 }, "identifierName": "a" }, @@ -332,16 +332,16 @@ "operator": "+", "right": { "type": "Identifier", - "start": 37, - "end": 38, + "start": 39, + "end": 40, "loc": { "start": { "line": 2, - "column": 28 + "column": 30 }, "end": { "line": 2, - "column": 29 + "column": 31 }, "identifierName": "b" }, @@ -352,8 +352,8 @@ }, { "type": "MatchCase", - "start": 41, - "end": 71, + "start": 43, + "end": 75, "loc": { "start": { "line": 3, @@ -361,13 +361,13 @@ }, "end": { "line": 3, - "column": 32 + "column": 34 } }, "test": { "type": "LogicalExpression", - "start": 43, - "end": 52, + "start": 45, + "end": 54, "loc": { "start": { "line": 3, @@ -380,8 +380,8 @@ }, "left": { "type": "MemberExpression", - "start": 43, - "end": 45, + "start": 45, + "end": 47, "loc": { "start": { "line": 3, @@ -394,8 +394,8 @@ }, "object": { "type": "PlaceholderExpression", - "start": 42, - "end": 43, + "start": 44, + "end": 45, "loc": { "start": { "line": 3, @@ -409,8 +409,8 @@ }, "property": { "type": "NumericLiteral", - "start": 44, - "end": 45, + "start": 46, + "end": 47, "loc": { "start": { "line": 3, @@ -432,8 +432,8 @@ "operator": "&&", "right": { "type": "MemberExpression", - "start": 50, - "end": 52, + "start": 52, + "end": 54, "loc": { "start": { "line": 3, @@ -446,8 +446,8 @@ }, "object": { "type": "PlaceholderExpression", - "start": 49, - "end": 50, + "start": 51, + "end": 52, "loc": { "start": { "line": 3, @@ -461,8 +461,8 @@ }, "property": { "type": "NumericLiteral", - "start": 51, - "end": 52, + "start": 53, + "end": 54, "loc": { "start": { "line": 3, @@ -484,31 +484,31 @@ }, "binding": { "type": "ArrayPattern", - "start": 56, - "end": 64, + "start": 60, + "end": 68, "loc": { "start": { "line": 3, - "column": 17 + "column": 19 }, "end": { "line": 3, - "column": 25 + "column": 27 } }, "elements": [ { "type": "Identifier", - "start": 58, - "end": 59, + "start": 62, + "end": 63, "loc": { "start": { "line": 3, - "column": 19 + "column": 21 }, "end": { "line": 3, - "column": 20 + "column": 22 }, "identifierName": "a" }, @@ -516,16 +516,16 @@ }, { "type": "Identifier", - "start": 61, - "end": 62, + "start": 65, + "end": 66, "loc": { "start": { "line": 3, - "column": 22 + "column": 24 }, "end": { "line": 3, - "column": 23 + "column": 25 }, "identifierName": "b" }, @@ -535,44 +535,44 @@ }, "consequent": { "type": "ExpressionStatement", - "start": 66, - "end": 71, + "start": 70, + "end": 75, "loc": { "start": { "line": 3, - "column": 27 + "column": 29 }, "end": { "line": 3, - "column": 32 + "column": 34 } }, "expression": { "type": "BinaryExpression", - "start": 66, - "end": 71, + "start": 70, + "end": 75, "loc": { "start": { "line": 3, - "column": 27 + "column": 29 }, "end": { "line": 3, - "column": 32 + "column": 34 } }, "left": { "type": "Identifier", - "start": 66, - "end": 67, + "start": 70, + "end": 71, "loc": { "start": { "line": 3, - "column": 27 + "column": 29 }, "end": { "line": 3, - "column": 28 + "column": 30 }, "identifierName": "a" }, @@ -581,16 +581,16 @@ "operator": "+", "right": { "type": "Identifier", - "start": 70, - "end": 71, + "start": 74, + "end": 75, "loc": { "start": { "line": 3, - "column": 31 + "column": 33 }, "end": { "line": 3, - "column": 32 + "column": 34 }, "identifierName": "b" }, diff --git a/test/fixtures/lightscript/match/destructuring-arr/actual.js b/test/fixtures/lightscript/match/destructuring-arr/actual.js index 5372aefa73..0a68eb814f 100644 --- a/test/fixtures/lightscript/match/destructuring-arr/actual.js +++ b/test/fixtures/lightscript/match/destructuring-arr/actual.js @@ -1,5 +1,5 @@ match x: - | [ a, b ] and a > 1: a + b + // | [ a, b ] and a > 1: a + b | [ a, b ]: a - b | [ a, b = 2 ]: a + b - 2 | [ a, ...b ]: b.concat(a) diff --git a/test/fixtures/lightscript/match/destructuring-arr/expected.json b/test/fixtures/lightscript/match/destructuring-arr/expected.json index 8c23d91f3f..f9cd7789f0 100644 --- a/test/fixtures/lightscript/match/destructuring-arr/expected.json +++ b/test/fixtures/lightscript/match/destructuring-arr/expected.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 225, + "end": 228, "loc": { "start": { "line": 1, @@ -15,7 +15,7 @@ "program": { "type": "Program", "start": 0, - "end": 225, + "end": 228, "loc": { "start": { "line": 1, @@ -31,7 +31,7 @@ { "type": "MatchStatement", "start": 0, - "end": 225, + "end": 228, "loc": { "start": { "line": 1, @@ -62,208 +62,8 @@ "cases": [ { "type": "MatchCase", - "start": 11, - "end": 38, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 29 - } - }, - "test": { - "type": "LogicalExpression", - "start": 13, - "end": 31, - "loc": { - "start": { - "line": 2, - "column": 4 - }, - "end": { - "line": 2, - "column": 22 - } - }, - "left": { - "type": "ArrayPattern", - "start": 13, - "end": 21, - "loc": { - "start": { - "line": 2, - "column": 4 - }, - "end": { - "line": 2, - "column": 12 - } - }, - "elements": [ - { - "type": "Identifier", - "start": 15, - "end": 16, - "loc": { - "start": { - "line": 2, - "column": 6 - }, - "end": { - "line": 2, - "column": 7 - }, - "identifierName": "a" - }, - "name": "a" - }, - { - "type": "Identifier", - "start": 18, - "end": 19, - "loc": { - "start": { - "line": 2, - "column": 9 - }, - "end": { - "line": 2, - "column": 10 - }, - "identifierName": "b" - }, - "name": "b" - } - ] - }, - "operator": "&&", - "right": { - "type": "BinaryExpression", - "start": 26, - "end": 31, - "loc": { - "start": { - "line": 2, - "column": 17 - }, - "end": { - "line": 2, - "column": 22 - } - }, - "left": { - "type": "Identifier", - "start": 26, - "end": 27, - "loc": { - "start": { - "line": 2, - "column": 17 - }, - "end": { - "line": 2, - "column": 18 - }, - "identifierName": "a" - }, - "name": "a" - }, - "operator": ">", - "right": { - "type": "NumericLiteral", - "start": 30, - "end": 31, - "loc": { - "start": { - "line": 2, - "column": 21 - }, - "end": { - "line": 2, - "column": 22 - } - }, - "extra": { - "rawValue": 1, - "raw": "1" - }, - "value": 1 - } - } - }, - "consequent": { - "type": "ExpressionStatement", - "start": 33, - "end": 38, - "loc": { - "start": { - "line": 2, - "column": 24 - }, - "end": { - "line": 2, - "column": 29 - } - }, - "expression": { - "type": "BinaryExpression", - "start": 33, - "end": 38, - "loc": { - "start": { - "line": 2, - "column": 24 - }, - "end": { - "line": 2, - "column": 29 - } - }, - "left": { - "type": "Identifier", - "start": 33, - "end": 34, - "loc": { - "start": { - "line": 2, - "column": 24 - }, - "end": { - "line": 2, - "column": 25 - }, - "identifierName": "a" - }, - "name": "a" - }, - "operator": "+", - "right": { - "type": "Identifier", - "start": 37, - "end": 38, - "loc": { - "start": { - "line": 2, - "column": 28 - }, - "end": { - "line": 2, - "column": 29 - }, - "identifierName": "b" - }, - "name": "b" - } - } - } - }, - { - "type": "MatchCase", - "start": 41, - "end": 58, + "start": 44, + "end": 61, "loc": { "start": { "line": 3, @@ -274,10 +74,10 @@ "column": 19 } }, - "test": { + "binding": { "type": "ArrayPattern", - "start": 43, - "end": 51, + "start": 46, + "end": 54, "loc": { "start": { "line": 3, @@ -291,8 +91,8 @@ "elements": [ { "type": "Identifier", - "start": 45, - "end": 46, + "start": 48, + "end": 49, "loc": { "start": { "line": 3, @@ -304,12 +104,13 @@ }, "identifierName": "a" }, - "name": "a" + "name": "a", + "leadingComments": null }, { "type": "Identifier", - "start": 48, - "end": 49, + "start": 51, + "end": 52, "loc": { "start": { "line": 3, @@ -325,10 +126,11 @@ } ] }, + "test": null, "consequent": { "type": "ExpressionStatement", - "start": 53, - "end": 58, + "start": 56, + "end": 61, "loc": { "start": { "line": 3, @@ -341,8 +143,8 @@ }, "expression": { "type": "BinaryExpression", - "start": 53, - "end": 58, + "start": 56, + "end": 61, "loc": { "start": { "line": 3, @@ -355,8 +157,8 @@ }, "left": { "type": "Identifier", - "start": 53, - "end": 54, + "start": 56, + "end": 57, "loc": { "start": { "line": 3, @@ -373,8 +175,8 @@ "operator": "-", "right": { "type": "Identifier", - "start": 57, - "end": 58, + "start": 60, + "end": 61, "loc": { "start": { "line": 3, @@ -389,12 +191,30 @@ "name": "b" } } - } + }, + "leadingComments": [ + { + "type": "CommentLine", + "value": " | [ a, b ] and a > 1: a + b", + "start": 11, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 32 + } + } + } + ] }, { "type": "MatchCase", - "start": 61, - "end": 86, + "start": 64, + "end": 89, "loc": { "start": { "line": 4, @@ -405,10 +225,10 @@ "column": 27 } }, - "test": { + "binding": { "type": "ArrayPattern", - "start": 63, - "end": 75, + "start": 66, + "end": 78, "loc": { "start": { "line": 4, @@ -422,8 +242,8 @@ "elements": [ { "type": "Identifier", - "start": 65, - "end": 66, + "start": 68, + "end": 69, "loc": { "start": { "line": 4, @@ -439,8 +259,8 @@ }, { "type": "AssignmentPattern", - "start": 68, - "end": 73, + "start": 71, + "end": 76, "loc": { "start": { "line": 4, @@ -453,8 +273,8 @@ }, "left": { "type": "Identifier", - "start": 68, - "end": 69, + "start": 71, + "end": 72, "loc": { "start": { "line": 4, @@ -470,8 +290,8 @@ }, "right": { "type": "NumericLiteral", - "start": 72, - "end": 73, + "start": 75, + "end": 76, "loc": { "start": { "line": 4, @@ -487,14 +307,16 @@ "raw": "2" }, "value": 2 - } + }, + "isNowAssign": false } ] }, + "test": null, "consequent": { "type": "ExpressionStatement", - "start": 77, - "end": 86, + "start": 80, + "end": 89, "loc": { "start": { "line": 4, @@ -507,8 +329,8 @@ }, "expression": { "type": "BinaryExpression", - "start": 77, - "end": 86, + "start": 80, + "end": 89, "loc": { "start": { "line": 4, @@ -521,8 +343,8 @@ }, "left": { "type": "BinaryExpression", - "start": 77, - "end": 82, + "start": 80, + "end": 85, "loc": { "start": { "line": 4, @@ -535,8 +357,8 @@ }, "left": { "type": "Identifier", - "start": 77, - "end": 78, + "start": 80, + "end": 81, "loc": { "start": { "line": 4, @@ -553,8 +375,8 @@ "operator": "+", "right": { "type": "Identifier", - "start": 81, - "end": 82, + "start": 84, + "end": 85, "loc": { "start": { "line": 4, @@ -572,8 +394,8 @@ "operator": "-", "right": { "type": "NumericLiteral", - "start": 85, - "end": 86, + "start": 88, + "end": 89, "loc": { "start": { "line": 4, @@ -595,8 +417,8 @@ }, { "type": "MatchCase", - "start": 89, - "end": 115, + "start": 92, + "end": 118, "loc": { "start": { "line": 5, @@ -607,10 +429,10 @@ "column": 28 } }, - "test": { + "binding": { "type": "ArrayPattern", - "start": 91, - "end": 102, + "start": 94, + "end": 105, "loc": { "start": { "line": 5, @@ -624,8 +446,8 @@ "elements": [ { "type": "Identifier", - "start": 93, - "end": 94, + "start": 96, + "end": 97, "loc": { "start": { "line": 5, @@ -641,8 +463,8 @@ }, { "type": "RestElement", - "start": 96, - "end": 100, + "start": 99, + "end": 103, "loc": { "start": { "line": 5, @@ -655,8 +477,8 @@ }, "argument": { "type": "Identifier", - "start": 99, - "end": 100, + "start": 102, + "end": 103, "loc": { "start": { "line": 5, @@ -673,10 +495,11 @@ } ] }, + "test": null, "consequent": { "type": "ExpressionStatement", - "start": 104, - "end": 115, + "start": 107, + "end": 118, "loc": { "start": { "line": 5, @@ -689,8 +512,8 @@ }, "expression": { "type": "CallExpression", - "start": 104, - "end": 115, + "start": 107, + "end": 118, "loc": { "start": { "line": 5, @@ -703,8 +526,8 @@ }, "callee": { "type": "MemberExpression", - "start": 104, - "end": 112, + "start": 107, + "end": 115, "loc": { "start": { "line": 5, @@ -717,8 +540,8 @@ }, "object": { "type": "Identifier", - "start": 104, - "end": 105, + "start": 107, + "end": 108, "loc": { "start": { "line": 5, @@ -734,8 +557,8 @@ }, "property": { "type": "Identifier", - "start": 106, - "end": 112, + "start": 109, + "end": 115, "loc": { "start": { "line": 5, @@ -754,8 +577,8 @@ "arguments": [ { "type": "Identifier", - "start": 113, - "end": 114, + "start": 116, + "end": 117, "loc": { "start": { "line": 5, @@ -775,8 +598,8 @@ }, { "type": "MatchCase", - "start": 118, - "end": 225, + "start": 121, + "end": 228, "loc": { "start": { "line": 6, @@ -787,10 +610,10 @@ "column": 28 } }, - "test": { + "binding": { "type": "ArrayPattern", - "start": 120, - "end": 195, + "start": 123, + "end": 198, "loc": { "start": { "line": 6, @@ -804,8 +627,8 @@ "elements": [ { "type": "ArrayPattern", - "start": 128, - "end": 163, + "start": 131, + "end": 166, "loc": { "start": { "line": 7, @@ -819,8 +642,8 @@ "elements": [ { "type": "Identifier", - "start": 138, - "end": 139, + "start": 141, + "end": 142, "loc": { "start": { "line": 8, @@ -836,8 +659,8 @@ }, { "type": "AssignmentPattern", - "start": 148, - "end": 155, + "start": 151, + "end": 158, "loc": { "start": { "line": 9, @@ -850,8 +673,8 @@ }, "left": { "type": "Identifier", - "start": 148, - "end": 149, + "start": 151, + "end": 152, "loc": { "start": { "line": 9, @@ -867,8 +690,8 @@ }, "right": { "type": "StringLiteral", - "start": 152, - "end": 155, + "start": 155, + "end": 158, "loc": { "start": { "line": 9, @@ -884,14 +707,15 @@ "raw": "'e'" }, "value": "e" - } + }, + "isNowAssign": false } ] }, { "type": "ArrayPattern", - "start": 170, - "end": 180, + "start": 173, + "end": 183, "loc": { "start": { "line": 11, @@ -905,8 +729,8 @@ "elements": [ { "type": "Identifier", - "start": 172, - "end": 173, + "start": 175, + "end": 176, "loc": { "start": { "line": 11, @@ -923,8 +747,8 @@ null, { "type": "Identifier", - "start": 177, - "end": 178, + "start": 180, + "end": 181, "loc": { "start": { "line": 11, @@ -942,8 +766,8 @@ }, { "type": "RestElement", - "start": 187, - "end": 191, + "start": 190, + "end": 194, "loc": { "start": { "line": 12, @@ -956,8 +780,8 @@ }, "argument": { "type": "Identifier", - "start": 190, - "end": 191, + "start": 193, + "end": 194, "loc": { "start": { "line": 12, @@ -974,10 +798,11 @@ } ] }, + "test": null, "consequent": { "type": "BlockStatement", - "start": 195, - "end": 225, + "start": 198, + "end": 228, "loc": { "start": { "line": 13, @@ -991,8 +816,8 @@ "body": [ { "type": "ExpressionStatement", - "start": 201, - "end": 225, + "start": 204, + "end": 228, "loc": { "start": { "line": 14, @@ -1005,8 +830,8 @@ }, "expression": { "type": "CallExpression", - "start": 201, - "end": 225, + "start": 204, + "end": 228, "loc": { "start": { "line": 14, @@ -1019,8 +844,8 @@ }, "callee": { "type": "MemberExpression", - "start": 201, - "end": 221, + "start": 204, + "end": 224, "loc": { "start": { "line": 14, @@ -1033,8 +858,8 @@ }, "object": { "type": "ArrayExpression", - "start": 201, - "end": 216, + "start": 204, + "end": 219, "loc": { "start": { "line": 14, @@ -1048,8 +873,8 @@ "elements": [ { "type": "Identifier", - "start": 202, - "end": 203, + "start": 205, + "end": 206, "loc": { "start": { "line": 14, @@ -1065,8 +890,8 @@ }, { "type": "Identifier", - "start": 205, - "end": 206, + "start": 208, + "end": 209, "loc": { "start": { "line": 14, @@ -1082,8 +907,8 @@ }, { "type": "Identifier", - "start": 208, - "end": 209, + "start": 211, + "end": 212, "loc": { "start": { "line": 14, @@ -1099,8 +924,8 @@ }, { "type": "SpreadElement", - "start": 211, - "end": 215, + "start": 214, + "end": 218, "loc": { "start": { "line": 14, @@ -1113,8 +938,8 @@ }, "argument": { "type": "Identifier", - "start": 214, - "end": 215, + "start": 217, + "end": 218, "loc": { "start": { "line": 14, @@ -1133,8 +958,8 @@ }, "property": { "type": "Identifier", - "start": 217, - "end": 221, + "start": 220, + "end": 224, "loc": { "start": { "line": 14, @@ -1153,8 +978,8 @@ "arguments": [ { "type": "StringLiteral", - "start": 222, - "end": 224, + "start": 225, + "end": 227, "loc": { "start": { "line": 14, @@ -1185,5 +1010,23 @@ } ], "directives": [] - } + }, + "comments": [ + { + "type": "CommentLine", + "value": " | [ a, b ] and a > 1: a + b", + "start": 11, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 32 + } + } + } + ] } \ No newline at end of file diff --git a/test/fixtures/lightscript/match/destructuring-obj-arr-mixed/expected.json b/test/fixtures/lightscript/match/destructuring-obj-arr-mixed/expected.json index 160cd21e8b..34f7a8aca8 100644 --- a/test/fixtures/lightscript/match/destructuring-obj-arr-mixed/expected.json +++ b/test/fixtures/lightscript/match/destructuring-obj-arr-mixed/expected.json @@ -74,7 +74,7 @@ "column": 34 } }, - "test": { + "binding": { "type": "ObjectPattern", "start": 13, "end": 123, @@ -493,6 +493,7 @@ } ] }, + "test": null, "consequent": { "type": "BlockStatement", "start": 123, 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..d104c9c720 --- /dev/null +++ b/test/fixtures/lightscript/match/destructuring-obj-basic/actual.js @@ -0,0 +1,2 @@ +match x: + | { 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..077c99b19f --- /dev/null +++ b/test/fixtures/lightscript/match/destructuring-obj-basic/expected.json @@ -0,0 +1,276 @@ +{ + "type": "File", + "start": 0, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "sourceType": "script", + "body": [ + { + "type": "MatchStatement", + "start": 0, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "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": 28, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "binding": { + "type": "ObjectPattern", + "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 + } + } + ] + }, + "test": null, + "consequent": { + "type": "ExpressionStatement", + "start": 23, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "expression": { + "type": "BinaryExpression", + "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": "a" + }, + "name": "a" + }, + "operator": "-", + "right": { + "type": "Identifier", + "start": 27, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 19 + }, + "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..827ab53733 --- /dev/null +++ b/test/fixtures/lightscript/match/destructuring-obj-default/actual.js @@ -0,0 +1,2 @@ +match x: + | { 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..1a4f3fa73d --- /dev/null +++ b/test/fixtures/lightscript/match/destructuring-obj-default/expected.json @@ -0,0 +1,311 @@ +{ + "type": "File", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "sourceType": "script", + "body": [ + { + "type": "MatchStatement", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "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": 32, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "binding": { + "type": "ObjectPattern", + "start": 13, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "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": 23, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "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": "AssignmentPattern", + "start": 18, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "left": { + "type": "Identifier", + "start": 18, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 10 + }, + "identifierName": "b" + }, + "name": "b" + }, + "right": { + "type": "NumericLiteral", + "start": 22, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + }, + "extra": { + "shorthand": true + } + } + ] + }, + "test": null, + "consequent": { + "type": "ExpressionStatement", + "start": 27, + "end": 32, + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "expression": { + "type": "BinaryExpression", + "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": "a" + }, + "name": "a" + }, + "operator": "-", + "right": { + "type": "Identifier", + "start": 31, + "end": 32, + "loc": { + "start": { + "line": 2, + "column": 22 + }, + "end": { + "line": 2, + "column": 23 + }, + "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 index 6eca5e504c..7f6fb621a1 100644 --- a/test/fixtures/lightscript/match/destructuring-obj/actual.js +++ b/test/fixtures/lightscript/match/destructuring-obj/actual.js @@ -1,5 +1,5 @@ match x: - | ~isObject() and { a, b } and a~isNumber() and a > 1: a + b + | ~isObject() and .a and .a~isNumber() and .a > 1 with { a, b }: a + b | { a, b }: a - b | { a, b = 2 }: a + b - 2 | { diff --git a/test/fixtures/lightscript/match/destructuring-obj/expected.json b/test/fixtures/lightscript/match/destructuring-obj/expected.json index aff864a79e..538d555a9b 100644 --- a/test/fixtures/lightscript/match/destructuring-obj/expected.json +++ b/test/fixtures/lightscript/match/destructuring-obj/expected.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 242, + "end": 252, "loc": { "start": { "line": 1, @@ -15,7 +15,7 @@ "program": { "type": "Program", "start": 0, - "end": 242, + "end": 252, "loc": { "start": { "line": 1, @@ -31,7 +31,7 @@ { "type": "MatchStatement", "start": 0, - "end": 242, + "end": 252, "loc": { "start": { "line": 1, @@ -63,7 +63,7 @@ { "type": "MatchCase", "start": 11, - "end": 71, + "end": 81, "loc": { "start": { "line": 2, @@ -71,13 +71,13 @@ }, "end": { "line": 2, - "column": 62 + "column": 72 } }, "test": { "type": "LogicalExpression", "start": 13, - "end": 64, + "end": 60, "loc": { "start": { "line": 2, @@ -85,13 +85,13 @@ }, "end": { "line": 2, - "column": 55 + "column": 51 } }, "left": { "type": "LogicalExpression", "start": 13, - "end": 54, + "end": 49, "loc": { "start": { "line": 2, @@ -99,13 +99,13 @@ }, "end": { "line": 2, - "column": 45 + "column": 40 } }, "left": { "type": "LogicalExpression", "start": 13, - "end": 37, + "end": 31, "loc": { "start": { "line": 2, @@ -113,7 +113,7 @@ }, "end": { "line": 2, - "column": 28 + "column": 22 } }, "left": { @@ -166,9 +166,9 @@ }, "operator": "&&", "right": { - "type": "ObjectPattern", + "type": "MemberExpression", "start": 29, - "end": 37, + "end": 31, "loc": { "start": { "line": 2, @@ -176,167 +176,119 @@ }, "end": { "line": 2, - "column": 28 + "column": 22 } }, - "properties": [ - { - "type": "ObjectProperty", - "start": 31, - "end": 32, - "loc": { - "start": { - "line": 2, - "column": 22 - }, - "end": { - "line": 2, - "column": 23 - } - }, - "method": false, - "shorthand": true, - "computed": false, - "key": { - "type": "Identifier", - "start": 31, - "end": 32, - "loc": { - "start": { - "line": 2, - "column": 22 - }, - "end": { - "line": 2, - "column": 23 - }, - "identifierName": "a" - }, - "name": "a" - }, - "value": { - "type": "Identifier", - "start": 31, - "end": 32, - "loc": { - "start": { - "line": 2, - "column": 22 - }, - "end": { - "line": 2, - "column": 23 - }, - "identifierName": "a" - }, - "name": "a" + "object": { + "type": "PlaceholderExpression", + "start": 28, + "end": 29, + "loc": { + "start": { + "line": 2, + "column": 19 }, - "extra": { - "shorthand": true + "end": { + "line": 2, + "column": 20 } - }, - { - "type": "ObjectProperty", - "start": 34, - "end": 35, - "loc": { - "start": { - "line": 2, - "column": 25 - }, - "end": { - "line": 2, - "column": 26 - } - }, - "method": false, - "shorthand": true, - "computed": false, - "key": { - "type": "Identifier", - "start": 34, - "end": 35, - "loc": { - "start": { - "line": 2, - "column": 25 - }, - "end": { - "line": 2, - "column": 26 - }, - "identifierName": "b" - }, - "name": "b" + } + }, + "property": { + "type": "Identifier", + "start": 30, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 21 }, - "value": { - "type": "Identifier", - "start": 34, - "end": 35, - "loc": { - "start": { - "line": 2, - "column": 25 - }, - "end": { - "line": 2, - "column": 26 - }, - "identifierName": "b" - }, - "name": "b" + "end": { + "line": 2, + "column": 22 }, - "extra": { - "shorthand": true - } - } - ] + "identifierName": "a" + }, + "name": "a" + }, + "computed": false } }, "operator": "&&", "right": { "type": "TildeCallExpression", - "start": 42, - "end": 54, + "start": 36, + "end": 49, "loc": { "start": { "line": 2, - "column": 33 + "column": 27 }, "end": { "line": 2, - "column": 45 + "column": 40 } }, "left": { - "type": "Identifier", - "start": 42, - "end": 43, + "type": "MemberExpression", + "start": 36, + "end": 38, "loc": { "start": { "line": 2, - "column": 33 + "column": 27 }, "end": { "line": 2, - "column": 34 + "column": 29 + } + }, + "object": { + "type": "PlaceholderExpression", + "start": 35, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 26 + }, + "end": { + "line": 2, + "column": 27 + } + } + }, + "property": { + "type": "Identifier", + "start": 37, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 28 + }, + "end": { + "line": 2, + "column": 29 + }, + "identifierName": "a" }, - "identifierName": "a" + "name": "a" }, - "name": "a" + "computed": false }, "right": { "type": "Identifier", - "start": 44, - "end": 52, + "start": 39, + "end": 47, "loc": { "start": { "line": 2, - "column": 35 + "column": 30 }, "end": { "line": 2, - "column": 43 + "column": 38 }, "identifierName": "isNumber" }, @@ -348,48 +300,79 @@ "operator": "&&", "right": { "type": "BinaryExpression", - "start": 59, - "end": 64, + "start": 54, + "end": 60, "loc": { "start": { "line": 2, - "column": 50 + "column": 45 }, "end": { "line": 2, - "column": 55 + "column": 51 } }, "left": { - "type": "Identifier", - "start": 59, - "end": 60, + "type": "MemberExpression", + "start": 54, + "end": 56, "loc": { "start": { "line": 2, - "column": 50 + "column": 45 }, "end": { "line": 2, - "column": 51 + "column": 47 + } + }, + "object": { + "type": "PlaceholderExpression", + "start": 53, + "end": 54, + "loc": { + "start": { + "line": 2, + "column": 44 + }, + "end": { + "line": 2, + "column": 45 + } + } + }, + "property": { + "type": "Identifier", + "start": 55, + "end": 56, + "loc": { + "start": { + "line": 2, + "column": 46 + }, + "end": { + "line": 2, + "column": 47 + }, + "identifierName": "a" }, - "identifierName": "a" + "name": "a" }, - "name": "a" + "computed": false }, "operator": ">", "right": { "type": "NumericLiteral", - "start": 63, - "end": 64, + "start": 59, + "end": 60, "loc": { "start": { "line": 2, - "column": 54 + "column": 50 }, "end": { "line": 2, - "column": 55 + "column": 51 } }, "extra": { @@ -400,10 +383,10 @@ } } }, - "consequent": { - "type": "ExpressionStatement", + "binding": { + "type": "ObjectPattern", "start": 66, - "end": 71, + "end": 74, "loc": { "start": { "line": 2, @@ -411,35 +394,162 @@ }, "end": { "line": 2, - "column": 62 + "column": 65 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 68, + "end": 69, + "loc": { + "start": { + "line": 2, + "column": 59 + }, + "end": { + "line": 2, + "column": 60 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 68, + "end": 69, + "loc": { + "start": { + "line": 2, + "column": 59 + }, + "end": { + "line": 2, + "column": 60 + }, + "identifierName": "a" + }, + "name": "a" + }, + "value": { + "type": "Identifier", + "start": 68, + "end": 69, + "loc": { + "start": { + "line": 2, + "column": 59 + }, + "end": { + "line": 2, + "column": 60 + }, + "identifierName": "a" + }, + "name": "a" + }, + "extra": { + "shorthand": true + } + }, + { + "type": "ObjectProperty", + "start": 71, + "end": 72, + "loc": { + "start": { + "line": 2, + "column": 62 + }, + "end": { + "line": 2, + "column": 63 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 71, + "end": 72, + "loc": { + "start": { + "line": 2, + "column": 62 + }, + "end": { + "line": 2, + "column": 63 + }, + "identifierName": "b" + }, + "name": "b" + }, + "value": { + "type": "Identifier", + "start": 71, + "end": 72, + "loc": { + "start": { + "line": 2, + "column": 62 + }, + "end": { + "line": 2, + "column": 63 + }, + "identifierName": "b" + }, + "name": "b" + }, + "extra": { + "shorthand": true + } + } + ] + }, + "consequent": { + "type": "ExpressionStatement", + "start": 76, + "end": 81, + "loc": { + "start": { + "line": 2, + "column": 67 + }, + "end": { + "line": 2, + "column": 72 } }, "expression": { "type": "BinaryExpression", - "start": 66, - "end": 71, + "start": 76, + "end": 81, "loc": { "start": { "line": 2, - "column": 57 + "column": 67 }, "end": { "line": 2, - "column": 62 + "column": 72 } }, "left": { "type": "Identifier", - "start": 66, - "end": 67, + "start": 76, + "end": 77, "loc": { "start": { "line": 2, - "column": 57 + "column": 67 }, "end": { "line": 2, - "column": 58 + "column": 68 }, "identifierName": "a" }, @@ -448,16 +558,16 @@ "operator": "+", "right": { "type": "Identifier", - "start": 70, - "end": 71, + "start": 80, + "end": 81, "loc": { "start": { "line": 2, - "column": 61 + "column": 71 }, "end": { "line": 2, - "column": 62 + "column": 72 }, "identifierName": "b" }, @@ -468,8 +578,8 @@ }, { "type": "MatchCase", - "start": 74, - "end": 91, + "start": 84, + "end": 101, "loc": { "start": { "line": 3, @@ -480,10 +590,10 @@ "column": 19 } }, - "test": { + "binding": { "type": "ObjectPattern", - "start": 76, - "end": 84, + "start": 86, + "end": 94, "loc": { "start": { "line": 3, @@ -497,8 +607,8 @@ "properties": [ { "type": "ObjectProperty", - "start": 78, - "end": 79, + "start": 88, + "end": 89, "loc": { "start": { "line": 3, @@ -514,8 +624,8 @@ "computed": false, "key": { "type": "Identifier", - "start": 78, - "end": 79, + "start": 88, + "end": 89, "loc": { "start": { "line": 3, @@ -531,8 +641,8 @@ }, "value": { "type": "Identifier", - "start": 78, - "end": 79, + "start": 88, + "end": 89, "loc": { "start": { "line": 3, @@ -552,8 +662,8 @@ }, { "type": "ObjectProperty", - "start": 81, - "end": 82, + "start": 91, + "end": 92, "loc": { "start": { "line": 3, @@ -569,8 +679,8 @@ "computed": false, "key": { "type": "Identifier", - "start": 81, - "end": 82, + "start": 91, + "end": 92, "loc": { "start": { "line": 3, @@ -586,8 +696,8 @@ }, "value": { "type": "Identifier", - "start": 81, - "end": 82, + "start": 91, + "end": 92, "loc": { "start": { "line": 3, @@ -607,10 +717,11 @@ } ] }, + "test": null, "consequent": { "type": "ExpressionStatement", - "start": 86, - "end": 91, + "start": 96, + "end": 101, "loc": { "start": { "line": 3, @@ -623,8 +734,8 @@ }, "expression": { "type": "BinaryExpression", - "start": 86, - "end": 91, + "start": 96, + "end": 101, "loc": { "start": { "line": 3, @@ -637,8 +748,8 @@ }, "left": { "type": "Identifier", - "start": 86, - "end": 87, + "start": 96, + "end": 97, "loc": { "start": { "line": 3, @@ -655,8 +766,8 @@ "operator": "-", "right": { "type": "Identifier", - "start": 90, - "end": 91, + "start": 100, + "end": 101, "loc": { "start": { "line": 3, @@ -675,8 +786,8 @@ }, { "type": "MatchCase", - "start": 94, - "end": 119, + "start": 104, + "end": 129, "loc": { "start": { "line": 4, @@ -687,10 +798,10 @@ "column": 27 } }, - "test": { + "binding": { "type": "ObjectPattern", - "start": 96, - "end": 108, + "start": 106, + "end": 118, "loc": { "start": { "line": 4, @@ -704,8 +815,8 @@ "properties": [ { "type": "ObjectProperty", - "start": 98, - "end": 99, + "start": 108, + "end": 109, "loc": { "start": { "line": 4, @@ -721,8 +832,8 @@ "computed": false, "key": { "type": "Identifier", - "start": 98, - "end": 99, + "start": 108, + "end": 109, "loc": { "start": { "line": 4, @@ -738,8 +849,8 @@ }, "value": { "type": "Identifier", - "start": 98, - "end": 99, + "start": 108, + "end": 109, "loc": { "start": { "line": 4, @@ -759,8 +870,8 @@ }, { "type": "ObjectProperty", - "start": 101, - "end": 106, + "start": 111, + "end": 116, "loc": { "start": { "line": 4, @@ -776,8 +887,8 @@ "computed": false, "key": { "type": "Identifier", - "start": 101, - "end": 102, + "start": 111, + "end": 112, "loc": { "start": { "line": 4, @@ -793,8 +904,8 @@ }, "value": { "type": "AssignmentPattern", - "start": 101, - "end": 106, + "start": 111, + "end": 116, "loc": { "start": { "line": 4, @@ -807,8 +918,8 @@ }, "left": { "type": "Identifier", - "start": 101, - "end": 102, + "start": 111, + "end": 112, "loc": { "start": { "line": 4, @@ -824,8 +935,8 @@ }, "right": { "type": "NumericLiteral", - "start": 105, - "end": 106, + "start": 115, + "end": 116, "loc": { "start": { "line": 4, @@ -849,10 +960,11 @@ } ] }, + "test": null, "consequent": { "type": "ExpressionStatement", - "start": 110, - "end": 119, + "start": 120, + "end": 129, "loc": { "start": { "line": 4, @@ -865,8 +977,8 @@ }, "expression": { "type": "BinaryExpression", - "start": 110, - "end": 119, + "start": 120, + "end": 129, "loc": { "start": { "line": 4, @@ -879,8 +991,8 @@ }, "left": { "type": "BinaryExpression", - "start": 110, - "end": 115, + "start": 120, + "end": 125, "loc": { "start": { "line": 4, @@ -893,8 +1005,8 @@ }, "left": { "type": "Identifier", - "start": 110, - "end": 111, + "start": 120, + "end": 121, "loc": { "start": { "line": 4, @@ -911,8 +1023,8 @@ "operator": "+", "right": { "type": "Identifier", - "start": 114, - "end": 115, + "start": 124, + "end": 125, "loc": { "start": { "line": 4, @@ -930,8 +1042,8 @@ "operator": "-", "right": { "type": "NumericLiteral", - "start": 118, - "end": 119, + "start": 128, + "end": 129, "loc": { "start": { "line": 4, @@ -953,8 +1065,8 @@ }, { "type": "MatchCase", - "start": 122, - "end": 206, + "start": 132, + "end": 216, "loc": { "start": { "line": 5, @@ -965,10 +1077,10 @@ "column": 22 } }, - "test": { + "binding": { "type": "ObjectPattern", - "start": 124, - "end": 182, + "start": 134, + "end": 192, "loc": { "start": { "line": 5, @@ -982,8 +1094,8 @@ "properties": [ { "type": "ObjectProperty", - "start": 130, - "end": 162, + "start": 140, + "end": 172, "loc": { "start": { "line": 6, @@ -999,8 +1111,8 @@ "computed": false, "key": { "type": "Identifier", - "start": 130, - "end": 131, + "start": 140, + "end": 141, "loc": { "start": { "line": 6, @@ -1016,8 +1128,8 @@ }, "value": { "type": "ObjectPattern", - "start": 133, - "end": 162, + "start": 143, + "end": 172, "loc": { "start": { "line": 6, @@ -1031,8 +1143,8 @@ "properties": [ { "type": "ObjectProperty", - "start": 141, - "end": 142, + "start": 151, + "end": 152, "loc": { "start": { "line": 7, @@ -1048,8 +1160,8 @@ "computed": false, "key": { "type": "Identifier", - "start": 141, - "end": 142, + "start": 151, + "end": 152, "loc": { "start": { "line": 7, @@ -1065,8 +1177,8 @@ }, "value": { "type": "Identifier", - "start": 141, - "end": 142, + "start": 151, + "end": 152, "loc": { "start": { "line": 7, @@ -1086,8 +1198,8 @@ }, { "type": "ObjectProperty", - "start": 149, - "end": 156, + "start": 159, + "end": 166, "loc": { "start": { "line": 8, @@ -1103,8 +1215,8 @@ "computed": false, "key": { "type": "Identifier", - "start": 149, - "end": 150, + "start": 159, + "end": 160, "loc": { "start": { "line": 8, @@ -1120,8 +1232,8 @@ }, "value": { "type": "AssignmentPattern", - "start": 149, - "end": 156, + "start": 159, + "end": 166, "loc": { "start": { "line": 8, @@ -1134,8 +1246,8 @@ }, "left": { "type": "Identifier", - "start": 149, - "end": 150, + "start": 159, + "end": 160, "loc": { "start": { "line": 8, @@ -1151,8 +1263,8 @@ }, "right": { "type": "StringLiteral", - "start": 153, - "end": 156, + "start": 163, + "end": 166, "loc": { "start": { "line": 8, @@ -1179,8 +1291,8 @@ }, { "type": "ObjectProperty", - "start": 167, - "end": 178, + "start": 177, + "end": 188, "loc": { "start": { "line": 10, @@ -1196,8 +1308,8 @@ "computed": false, "key": { "type": "Identifier", - "start": 167, - "end": 168, + "start": 177, + "end": 178, "loc": { "start": { "line": 10, @@ -1213,8 +1325,8 @@ }, "value": { "type": "ObjectPattern", - "start": 170, - "end": 178, + "start": 180, + "end": 188, "loc": { "start": { "line": 10, @@ -1228,8 +1340,8 @@ "properties": [ { "type": "RestProperty", - "start": 172, - "end": 176, + "start": 182, + "end": 186, "loc": { "start": { "line": 10, @@ -1242,8 +1354,8 @@ }, "argument": { "type": "Identifier", - "start": 175, - "end": 176, + "start": 185, + "end": 186, "loc": { "start": { "line": 10, @@ -1263,10 +1375,11 @@ } ] }, + "test": null, "consequent": { "type": "BlockStatement", - "start": 182, - "end": 206, + "start": 192, + "end": 216, "loc": { "start": { "line": 11, @@ -1280,8 +1393,8 @@ "body": [ { "type": "ExpressionStatement", - "start": 188, - "end": 206, + "start": 198, + "end": 216, "loc": { "start": { "line": 12, @@ -1294,8 +1407,8 @@ }, "expression": { "type": "CallExpression", - "start": 188, - "end": 206, + "start": 198, + "end": 216, "loc": { "start": { "line": 12, @@ -1308,8 +1421,8 @@ }, "callee": { "type": "MemberExpression", - "start": 188, - "end": 202, + "start": 198, + "end": 212, "loc": { "start": { "line": 12, @@ -1322,8 +1435,8 @@ }, "object": { "type": "ArrayExpression", - "start": 188, - "end": 197, + "start": 198, + "end": 207, "loc": { "start": { "line": 12, @@ -1337,8 +1450,8 @@ "elements": [ { "type": "Identifier", - "start": 189, - "end": 190, + "start": 199, + "end": 200, "loc": { "start": { "line": 12, @@ -1354,8 +1467,8 @@ }, { "type": "Identifier", - "start": 192, - "end": 193, + "start": 202, + "end": 203, "loc": { "start": { "line": 12, @@ -1371,8 +1484,8 @@ }, { "type": "Identifier", - "start": 195, - "end": 196, + "start": 205, + "end": 206, "loc": { "start": { "line": 12, @@ -1390,8 +1503,8 @@ }, "property": { "type": "Identifier", - "start": 198, - "end": 202, + "start": 208, + "end": 212, "loc": { "start": { "line": 12, @@ -1410,8 +1523,8 @@ "arguments": [ { "type": "StringLiteral", - "start": 203, - "end": 205, + "start": 213, + "end": 215, "loc": { "start": { "line": 12, @@ -1440,8 +1553,8 @@ }, { "type": "MatchCase", - "start": 209, - "end": 242, + "start": 219, + "end": 252, "loc": { "start": { "line": 13, @@ -1452,10 +1565,10 @@ "column": 35 } }, - "test": { + "binding": { "type": "ObjectPattern", - "start": 211, - "end": 222, + "start": 221, + "end": 232, "loc": { "start": { "line": 13, @@ -1469,8 +1582,8 @@ "properties": [ { "type": "ObjectProperty", - "start": 213, - "end": 214, + "start": 223, + "end": 224, "loc": { "start": { "line": 13, @@ -1486,8 +1599,8 @@ "computed": false, "key": { "type": "Identifier", - "start": 213, - "end": 214, + "start": 223, + "end": 224, "loc": { "start": { "line": 13, @@ -1503,8 +1616,8 @@ }, "value": { "type": "Identifier", - "start": 213, - "end": 214, + "start": 223, + "end": 224, "loc": { "start": { "line": 13, @@ -1524,8 +1637,8 @@ }, { "type": "RestProperty", - "start": 216, - "end": 220, + "start": 226, + "end": 230, "loc": { "start": { "line": 13, @@ -1538,8 +1651,8 @@ }, "argument": { "type": "Identifier", - "start": 219, - "end": 220, + "start": 229, + "end": 230, "loc": { "start": { "line": 13, @@ -1556,10 +1669,11 @@ } ] }, + "test": null, "consequent": { "type": "ExpressionStatement", - "start": 224, - "end": 242, + "start": 234, + "end": 252, "loc": { "start": { "line": 13, @@ -1572,8 +1686,8 @@ }, "expression": { "type": "CallExpression", - "start": 224, - "end": 242, + "start": 234, + "end": 252, "loc": { "start": { "line": 13, @@ -1586,8 +1700,8 @@ }, "callee": { "type": "MemberExpression", - "start": 224, - "end": 238, + "start": 234, + "end": 248, "loc": { "start": { "line": 13, @@ -1600,8 +1714,8 @@ }, "object": { "type": "ArrayExpression", - "start": 224, - "end": 233, + "start": 234, + "end": 243, "loc": { "start": { "line": 13, @@ -1615,8 +1729,8 @@ "elements": [ { "type": "Identifier", - "start": 225, - "end": 226, + "start": 235, + "end": 236, "loc": { "start": { "line": 13, @@ -1632,8 +1746,8 @@ }, { "type": "Identifier", - "start": 228, - "end": 229, + "start": 238, + "end": 239, "loc": { "start": { "line": 13, @@ -1649,8 +1763,8 @@ }, { "type": "Identifier", - "start": 231, - "end": 232, + "start": 241, + "end": 242, "loc": { "start": { "line": 13, @@ -1668,8 +1782,8 @@ }, "property": { "type": "Identifier", - "start": 234, - "end": 238, + "start": 244, + "end": 248, "loc": { "start": { "line": 13, @@ -1688,8 +1802,8 @@ "arguments": [ { "type": "StringLiteral", - "start": 239, - "end": 241, + "start": 249, + "end": 251, "loc": { "start": { "line": 13, diff --git a/test/fixtures/lightscript/match/illegal-destructure-and-as/actual.js b/test/fixtures/lightscript/match/illegal-destructure-and-as/actual.js deleted file mode 100644 index 98e7a41ca7..0000000000 --- a/test/fixtures/lightscript/match/illegal-destructure-and-as/actual.js +++ /dev/null @@ -1,2 +0,0 @@ -match x: - | { a } as obj: "not allowed" diff --git a/test/fixtures/lightscript/match/illegal-destructure-and-as/options.json b/test/fixtures/lightscript/match/illegal-destructure-and-as/options.json deleted file mode 100644 index c13a638b56..0000000000 --- a/test/fixtures/lightscript/match/illegal-destructure-and-as/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Cannot rename after destructuring. (2:10)" -} 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..bf0b0e528d --- /dev/null +++ b/test/fixtures/lightscript/match/illegal-destructure-and-with/actual.js @@ -0,0 +1,2 @@ +match x: + | { a } with { a }: "not allowed" diff --git a/test/fixtures/lightscript/match/illegal-destructure-and-with/options.json b/test/fixtures/lightscript/match/illegal-destructure-and-with/options.json new file mode 100644 index 0000000000..eb311191fb --- /dev/null +++ b/test/fixtures/lightscript/match/illegal-destructure-and-with/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Cannot destructure twice. (2:10)" +} diff --git a/test/fixtures/lightscript/match/illegal-multi-pattern-1/actual.js b/test/fixtures/lightscript/match/illegal-multi-pattern-1/actual.js deleted file mode 100644 index 224b73451e..0000000000 --- a/test/fixtures/lightscript/match/illegal-multi-pattern-1/actual.js +++ /dev/null @@ -1,2 +0,0 @@ -match x: - | true and {a} or [a]: "not allowed" diff --git a/test/fixtures/lightscript/match/illegal-multi-pattern-1/options.json b/test/fixtures/lightscript/match/illegal-multi-pattern-1/options.json deleted file mode 100644 index 46a08cef29..0000000000 --- a/test/fixtures/lightscript/match/illegal-multi-pattern-1/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Only one pattern allowed per match case test. (2:20)" -} diff --git a/test/fixtures/lightscript/match/illegal-multi-pattern-2/actual.js b/test/fixtures/lightscript/match/illegal-multi-pattern-2/actual.js deleted file mode 100644 index bde1ba7de3..0000000000 --- a/test/fixtures/lightscript/match/illegal-multi-pattern-2/actual.js +++ /dev/null @@ -1,2 +0,0 @@ -match x: - | true and {a} or {a}: "not allowed" diff --git a/test/fixtures/lightscript/match/illegal-multi-pattern-2/options.json b/test/fixtures/lightscript/match/illegal-multi-pattern-2/options.json deleted file mode 100644 index 46a08cef29..0000000000 --- a/test/fixtures/lightscript/match/illegal-multi-pattern-2/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Only one pattern allowed per match case test. (2:20)" -} diff --git a/test/fixtures/lightscript/match/illegal-multi-pattern-3/actual.js b/test/fixtures/lightscript/match/illegal-multi-pattern-3/actual.js deleted file mode 100644 index 290fd5e05d..0000000000 --- a/test/fixtures/lightscript/match/illegal-multi-pattern-3/actual.js +++ /dev/null @@ -1,2 +0,0 @@ -match x: - | true and [a] or {a}: "not allowed" diff --git a/test/fixtures/lightscript/match/illegal-multi-pattern-3/options.json b/test/fixtures/lightscript/match/illegal-multi-pattern-3/options.json deleted file mode 100644 index 46a08cef29..0000000000 --- a/test/fixtures/lightscript/match/illegal-multi-pattern-3/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Only one pattern allowed per match case test. (2:20)" -} diff --git a/test/fixtures/lightscript/match/illegal-multi-pattern-4/actual.js b/test/fixtures/lightscript/match/illegal-multi-pattern-4/actual.js deleted file mode 100644 index 88d6ac8804..0000000000 --- a/test/fixtures/lightscript/match/illegal-multi-pattern-4/actual.js +++ /dev/null @@ -1,2 +0,0 @@ -match x: - | true and [a] or [a]: "not allowed" diff --git a/test/fixtures/lightscript/match/illegal-multi-pattern-4/options.json b/test/fixtures/lightscript/match/illegal-multi-pattern-4/options.json deleted file mode 100644 index 46a08cef29..0000000000 --- a/test/fixtures/lightscript/match/illegal-multi-pattern-4/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Only one pattern allowed per match case test. (2:20)" -} diff --git a/test/fixtures/lightscript/match/nested/actual.js b/test/fixtures/lightscript/match/nested/actual.js index 7c75d0c9bd..36dbc5528f 100644 --- a/test/fixtures/lightscript/match/nested/actual.js +++ b/test/fixtures/lightscript/match/nested/actual.js @@ -1,5 +1,5 @@ match x: - | > 2 as y: match y: + | > 2: match x: | > 10: "soo big" | > 5: "still pretty big" | else: "kinda big" diff --git a/test/fixtures/lightscript/match/nested/expected.json b/test/fixtures/lightscript/match/nested/expected.json index 0385cfcc7e..6e6b4acba7 100644 --- a/test/fixtures/lightscript/match/nested/expected.json +++ b/test/fixtures/lightscript/match/nested/expected.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 136, + "end": 131, "loc": { "start": { "line": 1, @@ -15,7 +15,7 @@ "program": { "type": "Program", "start": 0, - "end": 136, + "end": 131, "loc": { "start": { "line": 1, @@ -31,7 +31,7 @@ { "type": "MatchStatement", "start": 0, - "end": 136, + "end": 131, "loc": { "start": { "line": 1, @@ -63,7 +63,7 @@ { "type": "MatchCase", "start": 11, - "end": 107, + "end": 102, "loc": { "start": { "line": 2, @@ -125,31 +125,14 @@ "value": 2 } }, - "binding": { - "type": "Identifier", - "start": 20, - "end": 21, - "loc": { - "start": { - "line": 2, - "column": 11 - }, - "end": { - "line": 2, - "column": 12 - }, - "identifierName": "y" - }, - "name": "y" - }, "consequent": { "type": "MatchStatement", - "start": 23, - "end": 107, + "start": 18, + "end": 102, "loc": { "start": { "line": 2, - "column": 14 + "column": 9 }, "end": { "line": 5, @@ -158,26 +141,26 @@ }, "discriminant": { "type": "Identifier", - "start": 29, - "end": 30, + "start": 24, + "end": 25, "loc": { "start": { "line": 2, - "column": 20 + "column": 15 }, "end": { "line": 2, - "column": 21 + "column": 16 }, - "identifierName": "y" + "identifierName": "x" }, - "name": "y" + "name": "x" }, "cases": [ { "type": "MatchCase", - "start": 36, - "end": 53, + "start": 31, + "end": 48, "loc": { "start": { "line": 3, @@ -190,8 +173,8 @@ }, "test": { "type": "BinaryExpression", - "start": 38, - "end": 42, + "start": 33, + "end": 37, "loc": { "start": { "line": 3, @@ -204,8 +187,8 @@ }, "left": { "type": "PlaceholderExpression", - "start": 37, - "end": 38, + "start": 32, + "end": 33, "loc": { "start": { "line": 3, @@ -220,8 +203,8 @@ "operator": ">", "right": { "type": "NumericLiteral", - "start": 40, - "end": 42, + "start": 35, + "end": 37, "loc": { "start": { "line": 3, @@ -241,8 +224,8 @@ }, "consequent": { "type": "ExpressionStatement", - "start": 44, - "end": 53, + "start": 39, + "end": 48, "loc": { "start": { "line": 3, @@ -255,8 +238,8 @@ }, "expression": { "type": "StringLiteral", - "start": 44, - "end": 53, + "start": 39, + "end": 48, "loc": { "start": { "line": 3, @@ -277,8 +260,8 @@ }, { "type": "MatchCase", - "start": 58, - "end": 83, + "start": 53, + "end": 78, "loc": { "start": { "line": 4, @@ -291,8 +274,8 @@ }, "test": { "type": "BinaryExpression", - "start": 60, - "end": 63, + "start": 55, + "end": 58, "loc": { "start": { "line": 4, @@ -305,8 +288,8 @@ }, "left": { "type": "PlaceholderExpression", - "start": 59, - "end": 60, + "start": 54, + "end": 55, "loc": { "start": { "line": 4, @@ -321,8 +304,8 @@ "operator": ">", "right": { "type": "NumericLiteral", - "start": 62, - "end": 63, + "start": 57, + "end": 58, "loc": { "start": { "line": 4, @@ -342,8 +325,8 @@ }, "consequent": { "type": "ExpressionStatement", - "start": 65, - "end": 83, + "start": 60, + "end": 78, "loc": { "start": { "line": 4, @@ -356,8 +339,8 @@ }, "expression": { "type": "StringLiteral", - "start": 65, - "end": 83, + "start": 60, + "end": 78, "loc": { "start": { "line": 4, @@ -378,8 +361,8 @@ }, { "type": "MatchCase", - "start": 88, - "end": 107, + "start": 83, + "end": 102, "loc": { "start": { "line": 5, @@ -392,8 +375,8 @@ }, "test": { "type": "MatchElse", - "start": 90, - "end": 94, + "start": 85, + "end": 89, "loc": { "start": { "line": 5, @@ -407,8 +390,8 @@ }, "consequent": { "type": "ExpressionStatement", - "start": 96, - "end": 107, + "start": 91, + "end": 102, "loc": { "start": { "line": 5, @@ -421,8 +404,8 @@ }, "expression": { "type": "StringLiteral", - "start": 96, - "end": 107, + "start": 91, + "end": 102, "loc": { "start": { "line": 5, @@ -446,8 +429,8 @@ }, { "type": "MatchCase", - "start": 110, - "end": 136, + "start": 105, + "end": 131, "loc": { "start": { "line": 6, @@ -460,8 +443,8 @@ }, "test": { "type": "MatchElse", - "start": 112, - "end": 116, + "start": 107, + "end": 111, "loc": { "start": { "line": 6, @@ -475,8 +458,8 @@ }, "consequent": { "type": "ExpressionStatement", - "start": 118, - "end": 136, + "start": 113, + "end": 131, "loc": { "start": { "line": 6, @@ -489,8 +472,8 @@ }, "expression": { "type": "StringLiteral", - "start": 118, - "end": 136, + "start": 113, + "end": 131, "loc": { "start": { "line": 6, diff --git a/test/fixtures/lightscript/match/parenthesized-destructuring-illegal/actual.js b/test/fixtures/lightscript/match/parenthesized-destructuring-illegal/actual.js index d5037008b6..c89d86c9f2 100644 --- a/test/fixtures/lightscript/match/parenthesized-destructuring-illegal/actual.js +++ b/test/fixtures/lightscript/match/parenthesized-destructuring-illegal/actual.js @@ -1,2 +1,2 @@ a = match x: - | 3 as (three): three + | 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 index 3c68e9be75..8551537138 100644 --- a/test/fixtures/lightscript/match/parenthesized-destructuring-illegal/options.json +++ b/test/fixtures/lightscript/match/parenthesized-destructuring-illegal/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token (2:9)" + "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 From 347d118bb0a71f6d18cf5347673457fbf0ce8297 Mon Sep 17 00:00:00 2001 From: Alex Rattray Date: Wed, 7 Jun 2017 14:48:13 -0700 Subject: [PATCH 09/12] Enforce matching | indent levels --- src/plugins/lightscript.js | 11 +- .../mismatched-indent-level-curly/actual.js | 4 + .../expected.json | 192 ++++++++++++++++++ .../mismatched-indent-level-illegal/actual.js | 3 + .../options.json | 3 + .../match/overindent-allowed/actual.js | 3 + .../match/overindent-allowed/expected.json | 192 ++++++++++++++++++ 7 files changed, 405 insertions(+), 3 deletions(-) create mode 100644 test/fixtures/lightscript/match/mismatched-indent-level-curly/actual.js create mode 100644 test/fixtures/lightscript/match/mismatched-indent-level-curly/expected.json create mode 100644 test/fixtures/lightscript/match/mismatched-indent-level-illegal/actual.js create mode 100644 test/fixtures/lightscript/match/mismatched-indent-level-illegal/options.json create mode 100644 test/fixtures/lightscript/match/overindent-allowed/actual.js create mode 100644 test/fixtures/lightscript/match/overindent-allowed/expected.json diff --git a/src/plugins/lightscript.js b/src/plugins/lightscript.js index a3428db0ce..854b1d318e 100644 --- a/src/plugins/lightscript.js +++ b/src/plugins/lightscript.js @@ -563,8 +563,9 @@ pp.parseMatch = function (node, isExpression) { this.expect(tt._match); node.discriminant = this.parseParenExpression(); + const isColon = this.match(tt.colon); let isEnd; - if (this.match(tt.colon)) { + if (isColon) { const indentLevel = this.state.indentLevel; this.next(); isEnd = () => this.state.indentLevel <= indentLevel || this.match(tt.eof); @@ -574,11 +575,15 @@ pp.parseMatch = function (node, isExpression) { } 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") { @@ -632,7 +637,7 @@ pp.parseMatchCaseTest = function (node) { // disambiguate `| { a, b }:` from `| { a, b }~someFn():` const bindingOrTest = this.parseExprOps(false, { start: 0 }); try { - node.binding = this.toAssignable(bindingOrTest.__clone(), true, 'match test'); + node.binding = this.toAssignable(bindingOrTest.__clone(), true, "match test"); node.test = null; } catch (_err) { node.test = bindingOrTest; @@ -642,7 +647,7 @@ pp.parseMatchCaseTest = function (node) { } if (this.eat(tt._with)) { - if (node.binding) this.unexpected(this.state.lastTokStart, "Cannot destructure twice.") + 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(); } 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/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 From d8f7417c4fe9e74d3185ba7f8c2c848e191c7ec1 Mon Sep 17 00:00:00 2001 From: Alex Rattray Date: Thu, 8 Jun 2017 22:59:01 -0700 Subject: [PATCH 10/12] Remove match placeholders --- src/parser/expression.js | 27 +- src/plugins/lightscript.js | 60 - src/tokenizer/state.js | 2 - .../match/binary-both-subscripts/actual.js | 2 - .../binary-both-subscripts/expected.json | 230 ---- .../lightscript/match/binary/actual.js | 8 - .../lightscript/match/binary/expected.json | 1103 ---------------- .../match/curlies-parens/actual.js | 2 +- .../match/curlies-parens/expected.json | 97 +- .../lightscript/match/curlies/actual.js | 2 +- .../lightscript/match/curlies/expected.json | 97 +- .../match/destructured-renaming/actual.js | 4 +- .../match/destructured-renaming/expected.json | 278 ++-- .../match/destructuring-obj/actual.js | 2 +- .../match/destructuring-obj/expected.json | 688 +++------- .../match/dot-then-binary-illegal/actual.js | 2 - .../dot-then-binary-illegal/options.json | 3 - .../lightscript/match/in-assignment/actual.js | 2 +- .../match/in-assignment/expected.json | 97 +- .../match/jsx-test-illegal/options.json | 2 +- .../lightscript/match/less-than/actual.js | 3 - .../lightscript/match/less-than/expected.json | 270 ---- .../match/multi-subscripts-illegal/actual.js | 2 - .../multi-subscripts-illegal/options.json | 3 - .../multi-subscripts-number-illegal/actual.js | 2 - .../options.json | 3 - .../match/multi-subscripts-number/actual.js | 3 - .../multi-subscripts-number/expected.json | 370 ------ .../match/multi-subscripts/actual.js | 3 - .../match/multi-subscripts/expected.json | 425 ------- .../lightscript/match/nested/actual.js | 6 +- .../lightscript/match/nested/expected.json | 190 +-- test/fixtures/lightscript/match/not/actual.js | 9 - .../lightscript/match/not/expected.json | 1118 ----------------- .../match/parens-no-curlies/actual.js | 2 +- .../match/parens-no-curlies/expected.json | 97 +- .../match/subscript-in-tilde/actual.js | 2 - .../match/subscript-in-tilde/expected.json | 215 ---- .../lightscript/match/subscripts/actual.js | 6 - .../match/subscripts/expected.json | 561 --------- 40 files changed, 584 insertions(+), 5414 deletions(-) delete mode 100644 test/fixtures/lightscript/match/binary-both-subscripts/actual.js delete mode 100644 test/fixtures/lightscript/match/binary-both-subscripts/expected.json delete mode 100644 test/fixtures/lightscript/match/binary/actual.js delete mode 100644 test/fixtures/lightscript/match/binary/expected.json delete mode 100644 test/fixtures/lightscript/match/dot-then-binary-illegal/actual.js delete mode 100644 test/fixtures/lightscript/match/dot-then-binary-illegal/options.json delete mode 100644 test/fixtures/lightscript/match/less-than/actual.js delete mode 100644 test/fixtures/lightscript/match/less-than/expected.json delete mode 100644 test/fixtures/lightscript/match/multi-subscripts-illegal/actual.js delete mode 100644 test/fixtures/lightscript/match/multi-subscripts-illegal/options.json delete mode 100644 test/fixtures/lightscript/match/multi-subscripts-number-illegal/actual.js delete mode 100644 test/fixtures/lightscript/match/multi-subscripts-number-illegal/options.json delete mode 100644 test/fixtures/lightscript/match/multi-subscripts-number/actual.js delete mode 100644 test/fixtures/lightscript/match/multi-subscripts-number/expected.json delete mode 100644 test/fixtures/lightscript/match/multi-subscripts/actual.js delete mode 100644 test/fixtures/lightscript/match/multi-subscripts/expected.json delete mode 100644 test/fixtures/lightscript/match/not/actual.js delete mode 100644 test/fixtures/lightscript/match/not/expected.json delete mode 100644 test/fixtures/lightscript/match/subscript-in-tilde/actual.js delete mode 100644 test/fixtures/lightscript/match/subscript-in-tilde/expected.json delete mode 100644 test/fixtures/lightscript/match/subscripts/actual.js delete mode 100644 test/fixtures/lightscript/match/subscripts/expected.json diff --git a/src/parser/expression.js b/src/parser/expression.js index 01c551c710..f55c378fbd 100644 --- a/src/parser/expression.js +++ b/src/parser/expression.js @@ -291,13 +291,7 @@ pp.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, noIn) { // Parse unary operators, both prefix and postfix. pp.parseMaybeUnary = function (refShorthandDefaultPos) { - const matchCaseBinaryPlusMin = this.hasPlugin("lightscript") && - this.state.inMatchCaseTest && - this.match(tt.plusMin) && - this.state.tokens[this.state.tokens.length - 1].value !== "!" && - this.isNextCharWhitespace(); - - if (this.state.type.prefix && !matchCaseBinaryPlusMin) { + if (this.state.type.prefix) { if (this.hasPlugin("lightscript") && this.match(tt.plusMin)) { if (this.isNextCharWhitespace()) this.unexpected(null, "Unary +/- cannot be followed by a space in lightscript."); } @@ -313,19 +307,7 @@ pp.parseMaybeUnary = function (refShorthandDefaultPos) { this.next(); const argType = this.state.type; - - // change precedence / allow autofill of `not` within `match` test - if (this.hasPlugin("lightscript") && node.operator === "!" && this.state.inMatchCaseTest && !argType.startsExpr) { - if (this.match(tt.colon) || this.match(tt.logicalOR) || this.match(tt.logicalAND)) { - // allow `| not:`, `| !!:`, `| not or x:` - node.argument = this.parseMatchCasePlaceholder(); - } else { - // change precedence of `| not < 3:` to `!(x < 3)` from `(!x) < 3` - node.argument = this.parseExprOps(); - } - } else { - node.argument = this.parseMaybeUnary(); - } + node.argument = this.parseMaybeUnary(); this.addExtra(node, "parenthesizedArgument", argType === tt.parenL && (!node.argument.extra || !node.argument.extra.parenthesized)); @@ -763,14 +745,11 @@ pp.parseExprAtom = function (refShorthandDefaultPos) { } case tt.dot: - if (this.hasPlugin("lightscript") && this.lookahead().type === tt.num && !this.allowMatchCasePlaceholder()) { + if (this.hasPlugin("lightscript") && this.lookahead().type === tt.num) { this.unexpected(null, "Decimal numbers must be prefixed with a `0` in LightScript (eg; `0.1`)."); } default: - if (this.hasPlugin("lightscript") && this.allowMatchCasePlaceholder()) { - return this.parseMatchCasePlaceholder(); - } this.unexpected(); } }; diff --git a/src/plugins/lightscript.js b/src/plugins/lightscript.js index 854b1d318e..d55836ebcf 100644 --- a/src/plugins/lightscript.js +++ b/src/plugins/lightscript.js @@ -655,66 +655,6 @@ pp.parseMatchCaseTest = function (node) { this.state.inMatchCaseTest = false; }; -pp.isBinaryTokenForMatchCase = function (tokenType) { - return ( - tokenType.binop != null && - tokenType !== tt.logicalOR && - tokenType !== tt.logicalAND && - tokenType !== tt.bitwiseOR - ); -}; - -pp.isSubscriptTokenForMatchCase = function (tokenType) { - return ( - tokenType === tt.dot || - tokenType === tt.elvis || - tokenType === tt.tilde - ); -}; - -pp.allowMatchCasePlaceholder = function () { - if (!this.state.inMatchCaseTest) { - return false; - } - const cur = this.state.type; - const prev = this.state.tokens[this.state.tokens.length - 1].type; - - // don't allow two binary tokens in a row to use placeholders, eg; `+ *` - if (this.isBinaryTokenForMatchCase(cur)) { - return !this.isBinaryTokenForMatchCase(prev); - } - // don't allow two subscripts in a row to use placeholders, eg; `..` - if (this.isSubscriptTokenForMatchCase(cur)) { - return !this.isSubscriptTokenForMatchCase(prev); - } - return false; -}; - -pp.parseMatchCaseTestPattern = function () { - if (!this.state.allowMatchCaseTestPattern) { - this.unexpected(null, "Only one pattern allowed per match case test."); - } - - const oldInMatchCaseTestPattern = this.state.inMatchCaseTestPattern; - this.state.inMatchCaseTestPattern = true; - - const node = this.parseBindingAtom(); - - // once we have finished recursing through a pattern, disallow future patterns - this.state.inMatchCaseTestPattern = oldInMatchCaseTestPattern; - if (this.state.inMatchCaseTestPattern === false) { - this.state.allowMatchCaseTestPattern = false; - } - - return node; -}; - -pp.parseMatchCasePlaceholder = function () { - // use the blank space as an empty value (perhaps 0-length would be better) - const node = this.startNodeAt(this.state.lastTokEnd, this.state.lastTokEndLoc); - return this.finishNodeAt(node, "PlaceholderExpression", this.state.start, this.state.startLoc); -}; - export default function (instance) { diff --git a/src/tokenizer/state.js b/src/tokenizer/state.js index 5313aca266..9e19e9f21c 100644 --- a/src/tokenizer/state.js +++ b/src/tokenizer/state.js @@ -41,8 +41,6 @@ export default class State { // for lightscript this.indentLevel = 0; this.inMatchCaseTest = false; - this.inMatchCaseTestPattern = false; - this.allowMatchCaseTestPattern = false; this.type = tt.eof; this.value = null; diff --git a/test/fixtures/lightscript/match/binary-both-subscripts/actual.js b/test/fixtures/lightscript/match/binary-both-subscripts/actual.js deleted file mode 100644 index 5bf62633da..0000000000 --- a/test/fixtures/lightscript/match/binary-both-subscripts/actual.js +++ /dev/null @@ -1,2 +0,0 @@ -match x: - | .a + .b: 'has a and b' diff --git a/test/fixtures/lightscript/match/binary-both-subscripts/expected.json b/test/fixtures/lightscript/match/binary-both-subscripts/expected.json deleted file mode 100644 index eeff4263d5..0000000000 --- a/test/fixtures/lightscript/match/binary-both-subscripts/expected.json +++ /dev/null @@ -1,230 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 35, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 2, - "column": 26 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 35, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 2, - "column": 26 - } - }, - "sourceType": "script", - "body": [ - { - "type": "MatchStatement", - "start": 0, - "end": 35, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 2, - "column": 26 - } - }, - "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": 35, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 26 - } - }, - "test": { - "type": "BinaryExpression", - "start": 13, - "end": 20, - "loc": { - "start": { - "line": 2, - "column": 4 - }, - "end": { - "line": 2, - "column": 11 - } - }, - "left": { - "type": "MemberExpression", - "start": 13, - "end": 15, - "loc": { - "start": { - "line": 2, - "column": 4 - }, - "end": { - "line": 2, - "column": 6 - } - }, - "object": { - "type": "PlaceholderExpression", - "start": 12, - "end": 13, - "loc": { - "start": { - "line": 2, - "column": 3 - }, - "end": { - "line": 2, - "column": 4 - } - } - }, - "property": { - "type": "Identifier", - "start": 14, - "end": 15, - "loc": { - "start": { - "line": 2, - "column": 5 - }, - "end": { - "line": 2, - "column": 6 - }, - "identifierName": "a" - }, - "name": "a" - }, - "computed": false - }, - "operator": "+", - "right": { - "type": "MemberExpression", - "start": 18, - "end": 20, - "loc": { - "start": { - "line": 2, - "column": 9 - }, - "end": { - "line": 2, - "column": 11 - } - }, - "object": { - "type": "PlaceholderExpression", - "start": 17, - "end": 18, - "loc": { - "start": { - "line": 2, - "column": 8 - }, - "end": { - "line": 2, - "column": 9 - } - } - }, - "property": { - "type": "Identifier", - "start": 19, - "end": 20, - "loc": { - "start": { - "line": 2, - "column": 10 - }, - "end": { - "line": 2, - "column": 11 - }, - "identifierName": "b" - }, - "name": "b" - }, - "computed": false - } - }, - "consequent": { - "type": "ExpressionStatement", - "start": 22, - "end": 35, - "loc": { - "start": { - "line": 2, - "column": 13 - }, - "end": { - "line": 2, - "column": 26 - } - }, - "expression": { - "type": "StringLiteral", - "start": 22, - "end": 35, - "loc": { - "start": { - "line": 2, - "column": 13 - }, - "end": { - "line": 2, - "column": 26 - } - }, - "extra": { - "rawValue": "has a and b", - "raw": "'has a and b'" - }, - "value": "has a and b" - } - } - } - ] - } - ], - "directives": [] - } -} \ No newline at end of file diff --git a/test/fixtures/lightscript/match/binary/actual.js b/test/fixtures/lightscript/match/binary/actual.js deleted file mode 100644 index fe654095fc..0000000000 --- a/test/fixtures/lightscript/match/binary/actual.js +++ /dev/null @@ -1,8 +0,0 @@ -match x: - | > 2: "bigger than two" - | > 3 and > 2: "so cool" - | + 3 == 4: "its one shhh" - | +1 or -1: "equal to one or negative one" - | -1 or +1: "equal to one or negative one" - | instanceof Class: "its a Class thing!" - | ** 2 == b ** 2 + c ** 2: "triangle?" diff --git a/test/fixtures/lightscript/match/binary/expected.json b/test/fixtures/lightscript/match/binary/expected.json deleted file mode 100644 index eb3700d5ce..0000000000 --- a/test/fixtures/lightscript/match/binary/expected.json +++ /dev/null @@ -1,1103 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 265, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 8, - "column": 40 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 265, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 8, - "column": 40 - } - }, - "sourceType": "script", - "body": [ - { - "type": "MatchStatement", - "start": 0, - "end": 265, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 8, - "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": 35, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 26 - } - }, - "test": { - "type": "BinaryExpression", - "start": 13, - "end": 16, - "loc": { - "start": { - "line": 2, - "column": 4 - }, - "end": { - "line": 2, - "column": 7 - } - }, - "left": { - "type": "PlaceholderExpression", - "start": 12, - "end": 13, - "loc": { - "start": { - "line": 2, - "column": 3 - }, - "end": { - "line": 2, - "column": 4 - } - } - }, - "operator": ">", - "right": { - "type": "NumericLiteral", - "start": 15, - "end": 16, - "loc": { - "start": { - "line": 2, - "column": 6 - }, - "end": { - "line": 2, - "column": 7 - } - }, - "extra": { - "rawValue": 2, - "raw": "2" - }, - "value": 2 - } - }, - "consequent": { - "type": "ExpressionStatement", - "start": 18, - "end": 35, - "loc": { - "start": { - "line": 2, - "column": 9 - }, - "end": { - "line": 2, - "column": 26 - } - }, - "expression": { - "type": "StringLiteral", - "start": 18, - "end": 35, - "loc": { - "start": { - "line": 2, - "column": 9 - }, - "end": { - "line": 2, - "column": 26 - } - }, - "extra": { - "rawValue": "bigger than two", - "raw": "\"bigger than two\"" - }, - "value": "bigger than two" - } - } - }, - { - "type": "MatchCase", - "start": 38, - "end": 62, - "loc": { - "start": { - "line": 3, - "column": 2 - }, - "end": { - "line": 3, - "column": 26 - } - }, - "test": { - "type": "LogicalExpression", - "start": 40, - "end": 51, - "loc": { - "start": { - "line": 3, - "column": 4 - }, - "end": { - "line": 3, - "column": 15 - } - }, - "left": { - "type": "BinaryExpression", - "start": 40, - "end": 43, - "loc": { - "start": { - "line": 3, - "column": 4 - }, - "end": { - "line": 3, - "column": 7 - } - }, - "left": { - "type": "PlaceholderExpression", - "start": 39, - "end": 40, - "loc": { - "start": { - "line": 3, - "column": 3 - }, - "end": { - "line": 3, - "column": 4 - } - } - }, - "operator": ">", - "right": { - "type": "NumericLiteral", - "start": 42, - "end": 43, - "loc": { - "start": { - "line": 3, - "column": 6 - }, - "end": { - "line": 3, - "column": 7 - } - }, - "extra": { - "rawValue": 3, - "raw": "3" - }, - "value": 3 - } - }, - "operator": "&&", - "right": { - "type": "BinaryExpression", - "start": 48, - "end": 51, - "loc": { - "start": { - "line": 3, - "column": 12 - }, - "end": { - "line": 3, - "column": 15 - } - }, - "left": { - "type": "PlaceholderExpression", - "start": 47, - "end": 48, - "loc": { - "start": { - "line": 3, - "column": 11 - }, - "end": { - "line": 3, - "column": 12 - } - } - }, - "operator": ">", - "right": { - "type": "NumericLiteral", - "start": 50, - "end": 51, - "loc": { - "start": { - "line": 3, - "column": 14 - }, - "end": { - "line": 3, - "column": 15 - } - }, - "extra": { - "rawValue": 2, - "raw": "2" - }, - "value": 2 - } - } - }, - "consequent": { - "type": "ExpressionStatement", - "start": 53, - "end": 62, - "loc": { - "start": { - "line": 3, - "column": 17 - }, - "end": { - "line": 3, - "column": 26 - } - }, - "expression": { - "type": "StringLiteral", - "start": 53, - "end": 62, - "loc": { - "start": { - "line": 3, - "column": 17 - }, - "end": { - "line": 3, - "column": 26 - } - }, - "extra": { - "rawValue": "so cool", - "raw": "\"so cool\"" - }, - "value": "so cool" - } - } - }, - { - "type": "MatchCase", - "start": 65, - "end": 91, - "loc": { - "start": { - "line": 4, - "column": 2 - }, - "end": { - "line": 4, - "column": 28 - } - }, - "test": { - "type": "BinaryExpression", - "start": 67, - "end": 75, - "loc": { - "start": { - "line": 4, - "column": 4 - }, - "end": { - "line": 4, - "column": 12 - } - }, - "left": { - "type": "BinaryExpression", - "start": 67, - "end": 70, - "loc": { - "start": { - "line": 4, - "column": 4 - }, - "end": { - "line": 4, - "column": 7 - } - }, - "left": { - "type": "PlaceholderExpression", - "start": 66, - "end": 67, - "loc": { - "start": { - "line": 4, - "column": 3 - }, - "end": { - "line": 4, - "column": 4 - } - } - }, - "operator": "+", - "right": { - "type": "NumericLiteral", - "start": 69, - "end": 70, - "loc": { - "start": { - "line": 4, - "column": 6 - }, - "end": { - "line": 4, - "column": 7 - } - }, - "extra": { - "rawValue": 3, - "raw": "3" - }, - "value": 3 - } - }, - "operator": "===", - "right": { - "type": "NumericLiteral", - "start": 74, - "end": 75, - "loc": { - "start": { - "line": 4, - "column": 11 - }, - "end": { - "line": 4, - "column": 12 - } - }, - "extra": { - "rawValue": 4, - "raw": "4" - }, - "value": 4 - } - }, - "consequent": { - "type": "ExpressionStatement", - "start": 77, - "end": 91, - "loc": { - "start": { - "line": 4, - "column": 14 - }, - "end": { - "line": 4, - "column": 28 - } - }, - "expression": { - "type": "StringLiteral", - "start": 77, - "end": 91, - "loc": { - "start": { - "line": 4, - "column": 14 - }, - "end": { - "line": 4, - "column": 28 - } - }, - "extra": { - "rawValue": "its one shhh", - "raw": "\"its one shhh\"" - }, - "value": "its one shhh" - } - } - }, - { - "type": "MatchCase", - "start": 94, - "end": 136, - "loc": { - "start": { - "line": 5, - "column": 2 - }, - "end": { - "line": 5, - "column": 44 - } - }, - "test": { - "type": "LogicalExpression", - "start": 96, - "end": 104, - "loc": { - "start": { - "line": 5, - "column": 4 - }, - "end": { - "line": 5, - "column": 12 - } - }, - "left": { - "type": "UnaryExpression", - "start": 96, - "end": 98, - "loc": { - "start": { - "line": 5, - "column": 4 - }, - "end": { - "line": 5, - "column": 6 - } - }, - "operator": "+", - "prefix": true, - "argument": { - "type": "NumericLiteral", - "start": 97, - "end": 98, - "loc": { - "start": { - "line": 5, - "column": 5 - }, - "end": { - "line": 5, - "column": 6 - } - }, - "extra": { - "rawValue": 1, - "raw": "1" - }, - "value": 1 - }, - "extra": { - "parenthesizedArgument": false - } - }, - "operator": "||", - "right": { - "type": "UnaryExpression", - "start": 102, - "end": 104, - "loc": { - "start": { - "line": 5, - "column": 10 - }, - "end": { - "line": 5, - "column": 12 - } - }, - "operator": "-", - "prefix": true, - "argument": { - "type": "NumericLiteral", - "start": 103, - "end": 104, - "loc": { - "start": { - "line": 5, - "column": 11 - }, - "end": { - "line": 5, - "column": 12 - } - }, - "extra": { - "rawValue": 1, - "raw": "1" - }, - "value": 1 - }, - "extra": { - "parenthesizedArgument": false - } - } - }, - "consequent": { - "type": "ExpressionStatement", - "start": 106, - "end": 136, - "loc": { - "start": { - "line": 5, - "column": 14 - }, - "end": { - "line": 5, - "column": 44 - } - }, - "expression": { - "type": "StringLiteral", - "start": 106, - "end": 136, - "loc": { - "start": { - "line": 5, - "column": 14 - }, - "end": { - "line": 5, - "column": 44 - } - }, - "extra": { - "rawValue": "equal to one or negative one", - "raw": "\"equal to one or negative one\"" - }, - "value": "equal to one or negative one" - } - } - }, - { - "type": "MatchCase", - "start": 139, - "end": 181, - "loc": { - "start": { - "line": 6, - "column": 2 - }, - "end": { - "line": 6, - "column": 44 - } - }, - "test": { - "type": "LogicalExpression", - "start": 141, - "end": 149, - "loc": { - "start": { - "line": 6, - "column": 4 - }, - "end": { - "line": 6, - "column": 12 - } - }, - "left": { - "type": "UnaryExpression", - "start": 141, - "end": 143, - "loc": { - "start": { - "line": 6, - "column": 4 - }, - "end": { - "line": 6, - "column": 6 - } - }, - "operator": "-", - "prefix": true, - "argument": { - "type": "NumericLiteral", - "start": 142, - "end": 143, - "loc": { - "start": { - "line": 6, - "column": 5 - }, - "end": { - "line": 6, - "column": 6 - } - }, - "extra": { - "rawValue": 1, - "raw": "1" - }, - "value": 1 - }, - "extra": { - "parenthesizedArgument": false - } - }, - "operator": "||", - "right": { - "type": "UnaryExpression", - "start": 147, - "end": 149, - "loc": { - "start": { - "line": 6, - "column": 10 - }, - "end": { - "line": 6, - "column": 12 - } - }, - "operator": "+", - "prefix": true, - "argument": { - "type": "NumericLiteral", - "start": 148, - "end": 149, - "loc": { - "start": { - "line": 6, - "column": 11 - }, - "end": { - "line": 6, - "column": 12 - } - }, - "extra": { - "rawValue": 1, - "raw": "1" - }, - "value": 1 - }, - "extra": { - "parenthesizedArgument": false - } - } - }, - "consequent": { - "type": "ExpressionStatement", - "start": 151, - "end": 181, - "loc": { - "start": { - "line": 6, - "column": 14 - }, - "end": { - "line": 6, - "column": 44 - } - }, - "expression": { - "type": "StringLiteral", - "start": 151, - "end": 181, - "loc": { - "start": { - "line": 6, - "column": 14 - }, - "end": { - "line": 6, - "column": 44 - } - }, - "extra": { - "rawValue": "equal to one or negative one", - "raw": "\"equal to one or negative one\"" - }, - "value": "equal to one or negative one" - } - } - }, - { - "type": "MatchCase", - "start": 184, - "end": 224, - "loc": { - "start": { - "line": 7, - "column": 2 - }, - "end": { - "line": 7, - "column": 42 - } - }, - "test": { - "type": "BinaryExpression", - "start": 186, - "end": 202, - "loc": { - "start": { - "line": 7, - "column": 4 - }, - "end": { - "line": 7, - "column": 20 - } - }, - "left": { - "type": "PlaceholderExpression", - "start": 185, - "end": 186, - "loc": { - "start": { - "line": 7, - "column": 3 - }, - "end": { - "line": 7, - "column": 4 - } - } - }, - "operator": "instanceof", - "right": { - "type": "Identifier", - "start": 197, - "end": 202, - "loc": { - "start": { - "line": 7, - "column": 15 - }, - "end": { - "line": 7, - "column": 20 - }, - "identifierName": "Class" - }, - "name": "Class" - } - }, - "consequent": { - "type": "ExpressionStatement", - "start": 204, - "end": 224, - "loc": { - "start": { - "line": 7, - "column": 22 - }, - "end": { - "line": 7, - "column": 42 - } - }, - "expression": { - "type": "StringLiteral", - "start": 204, - "end": 224, - "loc": { - "start": { - "line": 7, - "column": 22 - }, - "end": { - "line": 7, - "column": 42 - } - }, - "extra": { - "rawValue": "its a Class thing!", - "raw": "\"its a Class thing!\"" - }, - "value": "its a Class thing!" - } - } - }, - { - "type": "MatchCase", - "start": 227, - "end": 265, - "loc": { - "start": { - "line": 8, - "column": 2 - }, - "end": { - "line": 8, - "column": 40 - } - }, - "test": { - "type": "BinaryExpression", - "start": 229, - "end": 252, - "loc": { - "start": { - "line": 8, - "column": 4 - }, - "end": { - "line": 8, - "column": 27 - } - }, - "left": { - "type": "BinaryExpression", - "start": 229, - "end": 233, - "loc": { - "start": { - "line": 8, - "column": 4 - }, - "end": { - "line": 8, - "column": 8 - } - }, - "left": { - "type": "PlaceholderExpression", - "start": 228, - "end": 229, - "loc": { - "start": { - "line": 8, - "column": 3 - }, - "end": { - "line": 8, - "column": 4 - } - } - }, - "operator": "**", - "right": { - "type": "NumericLiteral", - "start": 232, - "end": 233, - "loc": { - "start": { - "line": 8, - "column": 7 - }, - "end": { - "line": 8, - "column": 8 - } - }, - "extra": { - "rawValue": 2, - "raw": "2" - }, - "value": 2 - } - }, - "operator": "===", - "right": { - "type": "BinaryExpression", - "start": 237, - "end": 252, - "loc": { - "start": { - "line": 8, - "column": 12 - }, - "end": { - "line": 8, - "column": 27 - } - }, - "left": { - "type": "BinaryExpression", - "start": 237, - "end": 243, - "loc": { - "start": { - "line": 8, - "column": 12 - }, - "end": { - "line": 8, - "column": 18 - } - }, - "left": { - "type": "Identifier", - "start": 237, - "end": 238, - "loc": { - "start": { - "line": 8, - "column": 12 - }, - "end": { - "line": 8, - "column": 13 - }, - "identifierName": "b" - }, - "name": "b" - }, - "operator": "**", - "right": { - "type": "NumericLiteral", - "start": 242, - "end": 243, - "loc": { - "start": { - "line": 8, - "column": 17 - }, - "end": { - "line": 8, - "column": 18 - } - }, - "extra": { - "rawValue": 2, - "raw": "2" - }, - "value": 2 - } - }, - "operator": "+", - "right": { - "type": "BinaryExpression", - "start": 246, - "end": 252, - "loc": { - "start": { - "line": 8, - "column": 21 - }, - "end": { - "line": 8, - "column": 27 - } - }, - "left": { - "type": "Identifier", - "start": 246, - "end": 247, - "loc": { - "start": { - "line": 8, - "column": 21 - }, - "end": { - "line": 8, - "column": 22 - }, - "identifierName": "c" - }, - "name": "c" - }, - "operator": "**", - "right": { - "type": "NumericLiteral", - "start": 251, - "end": 252, - "loc": { - "start": { - "line": 8, - "column": 26 - }, - "end": { - "line": 8, - "column": 27 - } - }, - "extra": { - "rawValue": 2, - "raw": "2" - }, - "value": 2 - } - } - } - }, - "consequent": { - "type": "ExpressionStatement", - "start": 254, - "end": 265, - "loc": { - "start": { - "line": 8, - "column": 29 - }, - "end": { - "line": 8, - "column": 40 - } - }, - "expression": { - "type": "StringLiteral", - "start": 254, - "end": 265, - "loc": { - "start": { - "line": 8, - "column": 29 - }, - "end": { - "line": 8, - "column": 40 - } - }, - "extra": { - "rawValue": "triangle?", - "raw": "\"triangle?\"" - }, - "value": "triangle?" - } - } - } - ] - } - ], - "directives": [] - } -} \ No newline at end of file diff --git a/test/fixtures/lightscript/match/curlies-parens/actual.js b/test/fixtures/lightscript/match/curlies-parens/actual.js index b66cfe13e0..4493dca9ce 100644 --- a/test/fixtures/lightscript/match/curlies-parens/actual.js +++ b/test/fixtures/lightscript/match/curlies-parens/actual.js @@ -1,4 +1,4 @@ a = match (x) { -| > 2: "bigger than two" +| 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 index be434e3f41..e8af002e3c 100644 --- a/test/fixtures/lightscript/match/curlies-parens/expected.json +++ b/test/fixtures/lightscript/match/curlies-parens/expected.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 69, + "end": 58, "loc": { "start": { "line": 1, @@ -15,7 +15,7 @@ "program": { "type": "Program", "start": 0, - "end": 69, + "end": 58, "loc": { "start": { "line": 1, @@ -31,7 +31,7 @@ { "type": "VariableDeclaration", "start": 0, - "end": 69, + "end": 58, "loc": { "start": { "line": 1, @@ -50,7 +50,7 @@ { "type": "VariableDeclarator", "start": 0, - "end": 69, + "end": 58, "loc": { "start": { "line": 1, @@ -81,7 +81,7 @@ "init": { "type": "MatchExpression", "start": 4, - "end": 69, + "end": 58, "loc": { "start": { "line": 1, @@ -114,7 +114,7 @@ { "type": "MatchCase", "start": 16, - "end": 40, + "end": 29, "loc": { "start": { "line": 2, @@ -122,13 +122,13 @@ }, "end": { "line": 2, - "column": 24 + "column": 13 } }, "test": { - "type": "BinaryExpression", + "type": "NumericLiteral", "start": 18, - "end": 21, + "end": 19, "loc": { "start": { "line": 2, @@ -136,86 +136,55 @@ }, "end": { "line": 2, - "column": 5 + "column": 3 } }, - "left": { - "type": "PlaceholderExpression", - "start": 17, - "end": 18, - "loc": { - "start": { - "line": 2, - "column": 1 - }, - "end": { - "line": 2, - "column": 2 - } - } + "extra": { + "rawValue": 2, + "raw": "2" }, - "operator": ">", - "right": { - "type": "NumericLiteral", - "start": 20, - "end": 21, - "loc": { - "start": { - "line": 2, - "column": 4 - }, - "end": { - "line": 2, - "column": 5 - } - }, - "extra": { - "rawValue": 2, - "raw": "2" - }, - "value": 2 - } + "value": 2 }, "consequent": { "type": "ExpressionStatement", - "start": 23, - "end": 40, + "start": 21, + "end": 29, "loc": { "start": { "line": 2, - "column": 7 + "column": 5 }, "end": { "line": 2, - "column": 24 + "column": 13 } }, "expression": { "type": "StringLiteral", - "start": 23, - "end": 40, + "start": 21, + "end": 29, "loc": { "start": { "line": 2, - "column": 7 + "column": 5 }, "end": { "line": 2, - "column": 24 + "column": 13 } }, "extra": { - "rawValue": "bigger than two", - "raw": "\"bigger than two\"" + "rawValue": "eq two", + "raw": "\"eq two\"" }, - "value": "bigger than two" + "value": "eq two" } } }, { "type": "MatchCase", - "start": 41, - "end": 67, + "start": 30, + "end": 56, "loc": { "start": { "line": 3, @@ -228,8 +197,8 @@ }, "test": { "type": "MatchElse", - "start": 43, - "end": 47, + "start": 32, + "end": 36, "loc": { "start": { "line": 3, @@ -243,8 +212,8 @@ }, "consequent": { "type": "ExpressionStatement", - "start": 49, - "end": 67, + "start": 38, + "end": 56, "loc": { "start": { "line": 3, @@ -257,8 +226,8 @@ }, "expression": { "type": "StringLiteral", - "start": 49, - "end": 67, + "start": 38, + "end": 56, "loc": { "start": { "line": 3, diff --git a/test/fixtures/lightscript/match/curlies/actual.js b/test/fixtures/lightscript/match/curlies/actual.js index e0523ad8e2..f2b35475f7 100644 --- a/test/fixtures/lightscript/match/curlies/actual.js +++ b/test/fixtures/lightscript/match/curlies/actual.js @@ -1,4 +1,4 @@ a = match x { -| > 2: "bigger than two" +| 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 index 629ff940ec..f1139a3a48 100644 --- a/test/fixtures/lightscript/match/curlies/expected.json +++ b/test/fixtures/lightscript/match/curlies/expected.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 67, + "end": 56, "loc": { "start": { "line": 1, @@ -15,7 +15,7 @@ "program": { "type": "Program", "start": 0, - "end": 67, + "end": 56, "loc": { "start": { "line": 1, @@ -31,7 +31,7 @@ { "type": "VariableDeclaration", "start": 0, - "end": 67, + "end": 56, "loc": { "start": { "line": 1, @@ -50,7 +50,7 @@ { "type": "VariableDeclarator", "start": 0, - "end": 67, + "end": 56, "loc": { "start": { "line": 1, @@ -81,7 +81,7 @@ "init": { "type": "MatchExpression", "start": 4, - "end": 67, + "end": 56, "loc": { "start": { "line": 1, @@ -113,7 +113,7 @@ { "type": "MatchCase", "start": 14, - "end": 38, + "end": 27, "loc": { "start": { "line": 2, @@ -121,13 +121,13 @@ }, "end": { "line": 2, - "column": 24 + "column": 13 } }, "test": { - "type": "BinaryExpression", + "type": "NumericLiteral", "start": 16, - "end": 19, + "end": 17, "loc": { "start": { "line": 2, @@ -135,86 +135,55 @@ }, "end": { "line": 2, - "column": 5 + "column": 3 } }, - "left": { - "type": "PlaceholderExpression", - "start": 15, - "end": 16, - "loc": { - "start": { - "line": 2, - "column": 1 - }, - "end": { - "line": 2, - "column": 2 - } - } + "extra": { + "rawValue": 2, + "raw": "2" }, - "operator": ">", - "right": { - "type": "NumericLiteral", - "start": 18, - "end": 19, - "loc": { - "start": { - "line": 2, - "column": 4 - }, - "end": { - "line": 2, - "column": 5 - } - }, - "extra": { - "rawValue": 2, - "raw": "2" - }, - "value": 2 - } + "value": 2 }, "consequent": { "type": "ExpressionStatement", - "start": 21, - "end": 38, + "start": 19, + "end": 27, "loc": { "start": { "line": 2, - "column": 7 + "column": 5 }, "end": { "line": 2, - "column": 24 + "column": 13 } }, "expression": { "type": "StringLiteral", - "start": 21, - "end": 38, + "start": 19, + "end": 27, "loc": { "start": { "line": 2, - "column": 7 + "column": 5 }, "end": { "line": 2, - "column": 24 + "column": 13 } }, "extra": { - "rawValue": "bigger than two", - "raw": "\"bigger than two\"" + "rawValue": "eq two", + "raw": "\"eq two\"" }, - "value": "bigger than two" + "value": "eq two" } } }, { "type": "MatchCase", - "start": 39, - "end": 65, + "start": 28, + "end": 54, "loc": { "start": { "line": 3, @@ -227,8 +196,8 @@ }, "test": { "type": "MatchElse", - "start": 41, - "end": 45, + "start": 30, + "end": 34, "loc": { "start": { "line": 3, @@ -242,8 +211,8 @@ }, "consequent": { "type": "ExpressionStatement", - "start": 47, - "end": 65, + "start": 36, + "end": 54, "loc": { "start": { "line": 3, @@ -256,8 +225,8 @@ }, "expression": { "type": "StringLiteral", - "start": 47, - "end": 65, + "start": 36, + "end": 54, "loc": { "start": { "line": 3, diff --git a/test/fixtures/lightscript/match/destructured-renaming/actual.js b/test/fixtures/lightscript/match/destructured-renaming/actual.js index be745c223f..34f6b78509 100644 --- a/test/fixtures/lightscript/match/destructured-renaming/actual.js +++ b/test/fixtures/lightscript/match/destructured-renaming/actual.js @@ -1,3 +1,3 @@ match x: - | .a with { a, b = 1 }: a + b - | .0 and .1 with [ a, b ]: a + b + | 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 index c669c43850..5e790e10bc 100644 --- a/test/fixtures/lightscript/match/destructured-renaming/expected.json +++ b/test/fixtures/lightscript/match/destructured-renaming/expected.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 75, + "end": 78, "loc": { "start": { "line": 1, @@ -9,13 +9,13 @@ }, "end": { "line": 3, - "column": 34 + "column": 36 } }, "program": { "type": "Program", "start": 0, - "end": 75, + "end": 78, "loc": { "start": { "line": 1, @@ -23,7 +23,7 @@ }, "end": { "line": 3, - "column": 34 + "column": 36 } }, "sourceType": "script", @@ -31,7 +31,7 @@ { "type": "MatchStatement", "start": 0, - "end": 75, + "end": 78, "loc": { "start": { "line": 1, @@ -39,7 +39,7 @@ }, "end": { "line": 3, - "column": 34 + "column": 36 } }, "discriminant": { @@ -63,7 +63,7 @@ { "type": "MatchCase", "start": 11, - "end": 40, + "end": 41, "loc": { "start": { "line": 2, @@ -71,13 +71,13 @@ }, "end": { "line": 2, - "column": 31 + "column": 32 } }, "test": { "type": "MemberExpression", "start": 13, - "end": 15, + "end": 16, "loc": { "start": { "line": 2, @@ -85,36 +85,38 @@ }, "end": { "line": 2, - "column": 6 + "column": 7 } }, "object": { - "type": "PlaceholderExpression", - "start": 12, - "end": 13, + "type": "Identifier", + "start": 13, + "end": 14, "loc": { "start": { "line": 2, - "column": 3 + "column": 4 }, "end": { "line": 2, - "column": 4 - } - } + "column": 5 + }, + "identifierName": "x" + }, + "name": "x" }, "property": { "type": "Identifier", - "start": 14, - "end": 15, + "start": 15, + "end": 16, "loc": { "start": { "line": 2, - "column": 5 + "column": 6 }, "end": { "line": 2, - "column": 6 + "column": 7 }, "identifierName": "a" }, @@ -124,31 +126,31 @@ }, "binding": { "type": "ObjectPattern", - "start": 21, - "end": 33, + "start": 22, + "end": 34, "loc": { "start": { "line": 2, - "column": 12 + "column": 13 }, "end": { "line": 2, - "column": 24 + "column": 25 } }, "properties": [ { "type": "ObjectProperty", - "start": 23, - "end": 24, + "start": 24, + "end": 25, "loc": { "start": { "line": 2, - "column": 14 + "column": 15 }, "end": { "line": 2, - "column": 15 + "column": 16 } }, "method": false, @@ -156,16 +158,16 @@ "computed": false, "key": { "type": "Identifier", - "start": 23, - "end": 24, + "start": 24, + "end": 25, "loc": { "start": { "line": 2, - "column": 14 + "column": 15 }, "end": { "line": 2, - "column": 15 + "column": 16 }, "identifierName": "a" }, @@ -173,16 +175,16 @@ }, "value": { "type": "Identifier", - "start": 23, - "end": 24, + "start": 24, + "end": 25, "loc": { "start": { "line": 2, - "column": 14 + "column": 15 }, "end": { "line": 2, - "column": 15 + "column": 16 }, "identifierName": "a" }, @@ -194,16 +196,16 @@ }, { "type": "ObjectProperty", - "start": 26, - "end": 31, + "start": 27, + "end": 32, "loc": { "start": { "line": 2, - "column": 17 + "column": 18 }, "end": { "line": 2, - "column": 22 + "column": 23 } }, "method": false, @@ -211,16 +213,16 @@ "computed": false, "key": { "type": "Identifier", - "start": 26, - "end": 27, + "start": 27, + "end": 28, "loc": { "start": { "line": 2, - "column": 17 + "column": 18 }, "end": { "line": 2, - "column": 18 + "column": 19 }, "identifierName": "b" }, @@ -228,30 +230,30 @@ }, "value": { "type": "AssignmentPattern", - "start": 26, - "end": 31, + "start": 27, + "end": 32, "loc": { "start": { "line": 2, - "column": 17 + "column": 18 }, "end": { "line": 2, - "column": 22 + "column": 23 } }, "left": { "type": "Identifier", - "start": 26, - "end": 27, + "start": 27, + "end": 28, "loc": { "start": { "line": 2, - "column": 17 + "column": 18 }, "end": { "line": 2, - "column": 18 + "column": 19 }, "identifierName": "b" }, @@ -259,16 +261,16 @@ }, "right": { "type": "NumericLiteral", - "start": 30, - "end": 31, + "start": 31, + "end": 32, "loc": { "start": { "line": 2, - "column": 21 + "column": 22 }, "end": { "line": 2, - "column": 22 + "column": 23 } }, "extra": { @@ -286,44 +288,44 @@ }, "consequent": { "type": "ExpressionStatement", - "start": 35, - "end": 40, + "start": 36, + "end": 41, "loc": { "start": { "line": 2, - "column": 26 + "column": 27 }, "end": { "line": 2, - "column": 31 + "column": 32 } }, "expression": { "type": "BinaryExpression", - "start": 35, - "end": 40, + "start": 36, + "end": 41, "loc": { "start": { "line": 2, - "column": 26 + "column": 27 }, "end": { "line": 2, - "column": 31 + "column": 32 } }, "left": { "type": "Identifier", - "start": 35, - "end": 36, + "start": 36, + "end": 37, "loc": { "start": { "line": 2, - "column": 26 + "column": 27 }, "end": { "line": 2, - "column": 27 + "column": 28 }, "identifierName": "a" }, @@ -332,16 +334,16 @@ "operator": "+", "right": { "type": "Identifier", - "start": 39, - "end": 40, + "start": 40, + "end": 41, "loc": { "start": { "line": 2, - "column": 30 + "column": 31 }, "end": { "line": 2, - "column": 31 + "column": 32 }, "identifierName": "b" }, @@ -352,8 +354,8 @@ }, { "type": "MatchCase", - "start": 43, - "end": 75, + "start": 44, + "end": 78, "loc": { "start": { "line": 3, @@ -361,13 +363,13 @@ }, "end": { "line": 3, - "column": 34 + "column": 36 } }, "test": { "type": "LogicalExpression", - "start": 45, - "end": 54, + "start": 46, + "end": 57, "loc": { "start": { "line": 3, @@ -375,13 +377,13 @@ }, "end": { "line": 3, - "column": 13 + "column": 15 } }, "left": { "type": "MemberExpression", - "start": 45, - "end": 47, + "start": 46, + "end": 49, "loc": { "start": { "line": 3, @@ -389,36 +391,38 @@ }, "end": { "line": 3, - "column": 6 + "column": 7 } }, "object": { - "type": "PlaceholderExpression", - "start": 44, - "end": 45, + "type": "Identifier", + "start": 46, + "end": 47, "loc": { "start": { "line": 3, - "column": 3 + "column": 4 }, "end": { "line": 3, - "column": 4 - } - } + "column": 5 + }, + "identifierName": "x" + }, + "name": "x" }, "property": { "type": "NumericLiteral", - "start": 46, - "end": 47, + "start": 48, + "end": 49, "loc": { "start": { "line": 3, - "column": 5 + "column": 6 }, "end": { "line": 3, - "column": 6 + "column": 7 } }, "extra": { @@ -432,45 +436,47 @@ "operator": "&&", "right": { "type": "MemberExpression", - "start": 52, - "end": 54, + "start": 54, + "end": 57, "loc": { "start": { "line": 3, - "column": 11 + "column": 12 }, "end": { "line": 3, - "column": 13 + "column": 15 } }, "object": { - "type": "PlaceholderExpression", - "start": 51, - "end": 52, + "type": "Identifier", + "start": 54, + "end": 55, "loc": { "start": { "line": 3, - "column": 10 + "column": 12 }, "end": { "line": 3, - "column": 11 - } - } + "column": 13 + }, + "identifierName": "x" + }, + "name": "x" }, "property": { "type": "NumericLiteral", - "start": 53, - "end": 54, + "start": 56, + "end": 57, "loc": { "start": { "line": 3, - "column": 12 + "column": 14 }, "end": { "line": 3, - "column": 13 + "column": 15 } }, "extra": { @@ -484,31 +490,31 @@ }, "binding": { "type": "ArrayPattern", - "start": 60, - "end": 68, + "start": 63, + "end": 71, "loc": { "start": { "line": 3, - "column": 19 + "column": 21 }, "end": { "line": 3, - "column": 27 + "column": 29 } }, "elements": [ { "type": "Identifier", - "start": 62, - "end": 63, + "start": 65, + "end": 66, "loc": { "start": { "line": 3, - "column": 21 + "column": 23 }, "end": { "line": 3, - "column": 22 + "column": 24 }, "identifierName": "a" }, @@ -516,16 +522,16 @@ }, { "type": "Identifier", - "start": 65, - "end": 66, + "start": 68, + "end": 69, "loc": { "start": { "line": 3, - "column": 24 + "column": 26 }, "end": { "line": 3, - "column": 25 + "column": 27 }, "identifierName": "b" }, @@ -535,44 +541,44 @@ }, "consequent": { "type": "ExpressionStatement", - "start": 70, - "end": 75, + "start": 73, + "end": 78, "loc": { "start": { "line": 3, - "column": 29 + "column": 31 }, "end": { "line": 3, - "column": 34 + "column": 36 } }, "expression": { "type": "BinaryExpression", - "start": 70, - "end": 75, + "start": 73, + "end": 78, "loc": { "start": { "line": 3, - "column": 29 + "column": 31 }, "end": { "line": 3, - "column": 34 + "column": 36 } }, "left": { "type": "Identifier", - "start": 70, - "end": 71, + "start": 73, + "end": 74, "loc": { "start": { "line": 3, - "column": 29 + "column": 31 }, "end": { "line": 3, - "column": 30 + "column": 32 }, "identifierName": "a" }, @@ -581,16 +587,16 @@ "operator": "+", "right": { "type": "Identifier", - "start": 74, - "end": 75, + "start": 77, + "end": 78, "loc": { "start": { "line": 3, - "column": 33 + "column": 35 }, "end": { "line": 3, - "column": 34 + "column": 36 }, "identifierName": "b" }, diff --git a/test/fixtures/lightscript/match/destructuring-obj/actual.js b/test/fixtures/lightscript/match/destructuring-obj/actual.js index 7f6fb621a1..e11f36d8bb 100644 --- a/test/fixtures/lightscript/match/destructuring-obj/actual.js +++ b/test/fixtures/lightscript/match/destructuring-obj/actual.js @@ -1,5 +1,5 @@ match x: - | ~isObject() and .a and .a~isNumber() and .a > 1 with { a, b }: a + b + | foo with { a, b }: a + b | { a, b }: a - b | { a, b = 2 }: a + b - 2 | { diff --git a/test/fixtures/lightscript/match/destructuring-obj/expected.json b/test/fixtures/lightscript/match/destructuring-obj/expected.json index 538d555a9b..fb229a4341 100644 --- a/test/fixtures/lightscript/match/destructuring-obj/expected.json +++ b/test/fixtures/lightscript/match/destructuring-obj/expected.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 252, + "end": 208, "loc": { "start": { "line": 1, @@ -15,7 +15,7 @@ "program": { "type": "Program", "start": 0, - "end": 252, + "end": 208, "loc": { "start": { "line": 1, @@ -31,7 +31,7 @@ { "type": "MatchStatement", "start": 0, - "end": 252, + "end": 208, "loc": { "start": { "line": 1, @@ -63,7 +63,7 @@ { "type": "MatchCase", "start": 11, - "end": 81, + "end": 37, "loc": { "start": { "line": 2, @@ -71,13 +71,13 @@ }, "end": { "line": 2, - "column": 72 + "column": 28 } }, "test": { - "type": "LogicalExpression", + "type": "Identifier", "start": 13, - "end": 60, + "end": 16, "loc": { "start": { "line": 2, @@ -85,331 +85,39 @@ }, "end": { "line": 2, - "column": 51 - } - }, - "left": { - "type": "LogicalExpression", - "start": 13, - "end": 49, - "loc": { - "start": { - "line": 2, - "column": 4 - }, - "end": { - "line": 2, - "column": 40 - } + "column": 7 }, - "left": { - "type": "LogicalExpression", - "start": 13, - "end": 31, - "loc": { - "start": { - "line": 2, - "column": 4 - }, - "end": { - "line": 2, - "column": 22 - } - }, - "left": { - "type": "TildeCallExpression", - "start": 13, - "end": 24, - "loc": { - "start": { - "line": 2, - "column": 4 - }, - "end": { - "line": 2, - "column": 15 - } - }, - "left": { - "type": "PlaceholderExpression", - "start": 12, - "end": 13, - "loc": { - "start": { - "line": 2, - "column": 3 - }, - "end": { - "line": 2, - "column": 4 - } - } - }, - "right": { - "type": "Identifier", - "start": 14, - "end": 22, - "loc": { - "start": { - "line": 2, - "column": 5 - }, - "end": { - "line": 2, - "column": 13 - }, - "identifierName": "isObject" - }, - "name": "isObject" - }, - "arguments": [] - }, - "operator": "&&", - "right": { - "type": "MemberExpression", - "start": 29, - "end": 31, - "loc": { - "start": { - "line": 2, - "column": 20 - }, - "end": { - "line": 2, - "column": 22 - } - }, - "object": { - "type": "PlaceholderExpression", - "start": 28, - "end": 29, - "loc": { - "start": { - "line": 2, - "column": 19 - }, - "end": { - "line": 2, - "column": 20 - } - } - }, - "property": { - "type": "Identifier", - "start": 30, - "end": 31, - "loc": { - "start": { - "line": 2, - "column": 21 - }, - "end": { - "line": 2, - "column": 22 - }, - "identifierName": "a" - }, - "name": "a" - }, - "computed": false - } - }, - "operator": "&&", - "right": { - "type": "TildeCallExpression", - "start": 36, - "end": 49, - "loc": { - "start": { - "line": 2, - "column": 27 - }, - "end": { - "line": 2, - "column": 40 - } - }, - "left": { - "type": "MemberExpression", - "start": 36, - "end": 38, - "loc": { - "start": { - "line": 2, - "column": 27 - }, - "end": { - "line": 2, - "column": 29 - } - }, - "object": { - "type": "PlaceholderExpression", - "start": 35, - "end": 36, - "loc": { - "start": { - "line": 2, - "column": 26 - }, - "end": { - "line": 2, - "column": 27 - } - } - }, - "property": { - "type": "Identifier", - "start": 37, - "end": 38, - "loc": { - "start": { - "line": 2, - "column": 28 - }, - "end": { - "line": 2, - "column": 29 - }, - "identifierName": "a" - }, - "name": "a" - }, - "computed": false - }, - "right": { - "type": "Identifier", - "start": 39, - "end": 47, - "loc": { - "start": { - "line": 2, - "column": 30 - }, - "end": { - "line": 2, - "column": 38 - }, - "identifierName": "isNumber" - }, - "name": "isNumber" - }, - "arguments": [] - } + "identifierName": "foo" }, - "operator": "&&", - "right": { - "type": "BinaryExpression", - "start": 54, - "end": 60, - "loc": { - "start": { - "line": 2, - "column": 45 - }, - "end": { - "line": 2, - "column": 51 - } - }, - "left": { - "type": "MemberExpression", - "start": 54, - "end": 56, - "loc": { - "start": { - "line": 2, - "column": 45 - }, - "end": { - "line": 2, - "column": 47 - } - }, - "object": { - "type": "PlaceholderExpression", - "start": 53, - "end": 54, - "loc": { - "start": { - "line": 2, - "column": 44 - }, - "end": { - "line": 2, - "column": 45 - } - } - }, - "property": { - "type": "Identifier", - "start": 55, - "end": 56, - "loc": { - "start": { - "line": 2, - "column": 46 - }, - "end": { - "line": 2, - "column": 47 - }, - "identifierName": "a" - }, - "name": "a" - }, - "computed": false - }, - "operator": ">", - "right": { - "type": "NumericLiteral", - "start": 59, - "end": 60, - "loc": { - "start": { - "line": 2, - "column": 50 - }, - "end": { - "line": 2, - "column": 51 - } - }, - "extra": { - "rawValue": 1, - "raw": "1" - }, - "value": 1 - } - } + "name": "foo" }, "binding": { "type": "ObjectPattern", - "start": 66, - "end": 74, + "start": 22, + "end": 30, "loc": { "start": { "line": 2, - "column": 57 + "column": 13 }, "end": { "line": 2, - "column": 65 + "column": 21 } }, "properties": [ { "type": "ObjectProperty", - "start": 68, - "end": 69, + "start": 24, + "end": 25, "loc": { "start": { "line": 2, - "column": 59 + "column": 15 }, "end": { "line": 2, - "column": 60 + "column": 16 } }, "method": false, @@ -417,16 +125,16 @@ "computed": false, "key": { "type": "Identifier", - "start": 68, - "end": 69, + "start": 24, + "end": 25, "loc": { "start": { "line": 2, - "column": 59 + "column": 15 }, "end": { "line": 2, - "column": 60 + "column": 16 }, "identifierName": "a" }, @@ -434,16 +142,16 @@ }, "value": { "type": "Identifier", - "start": 68, - "end": 69, + "start": 24, + "end": 25, "loc": { "start": { "line": 2, - "column": 59 + "column": 15 }, "end": { "line": 2, - "column": 60 + "column": 16 }, "identifierName": "a" }, @@ -455,16 +163,16 @@ }, { "type": "ObjectProperty", - "start": 71, - "end": 72, + "start": 27, + "end": 28, "loc": { "start": { "line": 2, - "column": 62 + "column": 18 }, "end": { "line": 2, - "column": 63 + "column": 19 } }, "method": false, @@ -472,16 +180,16 @@ "computed": false, "key": { "type": "Identifier", - "start": 71, - "end": 72, + "start": 27, + "end": 28, "loc": { "start": { "line": 2, - "column": 62 + "column": 18 }, "end": { "line": 2, - "column": 63 + "column": 19 }, "identifierName": "b" }, @@ -489,16 +197,16 @@ }, "value": { "type": "Identifier", - "start": 71, - "end": 72, + "start": 27, + "end": 28, "loc": { "start": { "line": 2, - "column": 62 + "column": 18 }, "end": { "line": 2, - "column": 63 + "column": 19 }, "identifierName": "b" }, @@ -512,44 +220,44 @@ }, "consequent": { "type": "ExpressionStatement", - "start": 76, - "end": 81, + "start": 32, + "end": 37, "loc": { "start": { "line": 2, - "column": 67 + "column": 23 }, "end": { "line": 2, - "column": 72 + "column": 28 } }, "expression": { "type": "BinaryExpression", - "start": 76, - "end": 81, + "start": 32, + "end": 37, "loc": { "start": { "line": 2, - "column": 67 + "column": 23 }, "end": { "line": 2, - "column": 72 + "column": 28 } }, "left": { "type": "Identifier", - "start": 76, - "end": 77, + "start": 32, + "end": 33, "loc": { "start": { "line": 2, - "column": 67 + "column": 23 }, "end": { "line": 2, - "column": 68 + "column": 24 }, "identifierName": "a" }, @@ -558,16 +266,16 @@ "operator": "+", "right": { "type": "Identifier", - "start": 80, - "end": 81, + "start": 36, + "end": 37, "loc": { "start": { "line": 2, - "column": 71 + "column": 27 }, "end": { "line": 2, - "column": 72 + "column": 28 }, "identifierName": "b" }, @@ -578,8 +286,8 @@ }, { "type": "MatchCase", - "start": 84, - "end": 101, + "start": 40, + "end": 57, "loc": { "start": { "line": 3, @@ -592,8 +300,8 @@ }, "binding": { "type": "ObjectPattern", - "start": 86, - "end": 94, + "start": 42, + "end": 50, "loc": { "start": { "line": 3, @@ -607,8 +315,8 @@ "properties": [ { "type": "ObjectProperty", - "start": 88, - "end": 89, + "start": 44, + "end": 45, "loc": { "start": { "line": 3, @@ -624,8 +332,8 @@ "computed": false, "key": { "type": "Identifier", - "start": 88, - "end": 89, + "start": 44, + "end": 45, "loc": { "start": { "line": 3, @@ -641,8 +349,8 @@ }, "value": { "type": "Identifier", - "start": 88, - "end": 89, + "start": 44, + "end": 45, "loc": { "start": { "line": 3, @@ -662,8 +370,8 @@ }, { "type": "ObjectProperty", - "start": 91, - "end": 92, + "start": 47, + "end": 48, "loc": { "start": { "line": 3, @@ -679,8 +387,8 @@ "computed": false, "key": { "type": "Identifier", - "start": 91, - "end": 92, + "start": 47, + "end": 48, "loc": { "start": { "line": 3, @@ -696,8 +404,8 @@ }, "value": { "type": "Identifier", - "start": 91, - "end": 92, + "start": 47, + "end": 48, "loc": { "start": { "line": 3, @@ -720,8 +428,8 @@ "test": null, "consequent": { "type": "ExpressionStatement", - "start": 96, - "end": 101, + "start": 52, + "end": 57, "loc": { "start": { "line": 3, @@ -734,8 +442,8 @@ }, "expression": { "type": "BinaryExpression", - "start": 96, - "end": 101, + "start": 52, + "end": 57, "loc": { "start": { "line": 3, @@ -748,8 +456,8 @@ }, "left": { "type": "Identifier", - "start": 96, - "end": 97, + "start": 52, + "end": 53, "loc": { "start": { "line": 3, @@ -766,8 +474,8 @@ "operator": "-", "right": { "type": "Identifier", - "start": 100, - "end": 101, + "start": 56, + "end": 57, "loc": { "start": { "line": 3, @@ -786,8 +494,8 @@ }, { "type": "MatchCase", - "start": 104, - "end": 129, + "start": 60, + "end": 85, "loc": { "start": { "line": 4, @@ -800,8 +508,8 @@ }, "binding": { "type": "ObjectPattern", - "start": 106, - "end": 118, + "start": 62, + "end": 74, "loc": { "start": { "line": 4, @@ -815,8 +523,8 @@ "properties": [ { "type": "ObjectProperty", - "start": 108, - "end": 109, + "start": 64, + "end": 65, "loc": { "start": { "line": 4, @@ -832,8 +540,8 @@ "computed": false, "key": { "type": "Identifier", - "start": 108, - "end": 109, + "start": 64, + "end": 65, "loc": { "start": { "line": 4, @@ -849,8 +557,8 @@ }, "value": { "type": "Identifier", - "start": 108, - "end": 109, + "start": 64, + "end": 65, "loc": { "start": { "line": 4, @@ -870,8 +578,8 @@ }, { "type": "ObjectProperty", - "start": 111, - "end": 116, + "start": 67, + "end": 72, "loc": { "start": { "line": 4, @@ -887,8 +595,8 @@ "computed": false, "key": { "type": "Identifier", - "start": 111, - "end": 112, + "start": 67, + "end": 68, "loc": { "start": { "line": 4, @@ -904,8 +612,8 @@ }, "value": { "type": "AssignmentPattern", - "start": 111, - "end": 116, + "start": 67, + "end": 72, "loc": { "start": { "line": 4, @@ -918,8 +626,8 @@ }, "left": { "type": "Identifier", - "start": 111, - "end": 112, + "start": 67, + "end": 68, "loc": { "start": { "line": 4, @@ -935,8 +643,8 @@ }, "right": { "type": "NumericLiteral", - "start": 115, - "end": 116, + "start": 71, + "end": 72, "loc": { "start": { "line": 4, @@ -963,8 +671,8 @@ "test": null, "consequent": { "type": "ExpressionStatement", - "start": 120, - "end": 129, + "start": 76, + "end": 85, "loc": { "start": { "line": 4, @@ -977,8 +685,8 @@ }, "expression": { "type": "BinaryExpression", - "start": 120, - "end": 129, + "start": 76, + "end": 85, "loc": { "start": { "line": 4, @@ -991,8 +699,8 @@ }, "left": { "type": "BinaryExpression", - "start": 120, - "end": 125, + "start": 76, + "end": 81, "loc": { "start": { "line": 4, @@ -1005,8 +713,8 @@ }, "left": { "type": "Identifier", - "start": 120, - "end": 121, + "start": 76, + "end": 77, "loc": { "start": { "line": 4, @@ -1023,8 +731,8 @@ "operator": "+", "right": { "type": "Identifier", - "start": 124, - "end": 125, + "start": 80, + "end": 81, "loc": { "start": { "line": 4, @@ -1042,8 +750,8 @@ "operator": "-", "right": { "type": "NumericLiteral", - "start": 128, - "end": 129, + "start": 84, + "end": 85, "loc": { "start": { "line": 4, @@ -1065,8 +773,8 @@ }, { "type": "MatchCase", - "start": 132, - "end": 216, + "start": 88, + "end": 172, "loc": { "start": { "line": 5, @@ -1079,8 +787,8 @@ }, "binding": { "type": "ObjectPattern", - "start": 134, - "end": 192, + "start": 90, + "end": 148, "loc": { "start": { "line": 5, @@ -1094,8 +802,8 @@ "properties": [ { "type": "ObjectProperty", - "start": 140, - "end": 172, + "start": 96, + "end": 128, "loc": { "start": { "line": 6, @@ -1111,8 +819,8 @@ "computed": false, "key": { "type": "Identifier", - "start": 140, - "end": 141, + "start": 96, + "end": 97, "loc": { "start": { "line": 6, @@ -1128,8 +836,8 @@ }, "value": { "type": "ObjectPattern", - "start": 143, - "end": 172, + "start": 99, + "end": 128, "loc": { "start": { "line": 6, @@ -1143,8 +851,8 @@ "properties": [ { "type": "ObjectProperty", - "start": 151, - "end": 152, + "start": 107, + "end": 108, "loc": { "start": { "line": 7, @@ -1160,8 +868,8 @@ "computed": false, "key": { "type": "Identifier", - "start": 151, - "end": 152, + "start": 107, + "end": 108, "loc": { "start": { "line": 7, @@ -1177,8 +885,8 @@ }, "value": { "type": "Identifier", - "start": 151, - "end": 152, + "start": 107, + "end": 108, "loc": { "start": { "line": 7, @@ -1198,8 +906,8 @@ }, { "type": "ObjectProperty", - "start": 159, - "end": 166, + "start": 115, + "end": 122, "loc": { "start": { "line": 8, @@ -1215,8 +923,8 @@ "computed": false, "key": { "type": "Identifier", - "start": 159, - "end": 160, + "start": 115, + "end": 116, "loc": { "start": { "line": 8, @@ -1232,8 +940,8 @@ }, "value": { "type": "AssignmentPattern", - "start": 159, - "end": 166, + "start": 115, + "end": 122, "loc": { "start": { "line": 8, @@ -1246,8 +954,8 @@ }, "left": { "type": "Identifier", - "start": 159, - "end": 160, + "start": 115, + "end": 116, "loc": { "start": { "line": 8, @@ -1263,8 +971,8 @@ }, "right": { "type": "StringLiteral", - "start": 163, - "end": 166, + "start": 119, + "end": 122, "loc": { "start": { "line": 8, @@ -1291,8 +999,8 @@ }, { "type": "ObjectProperty", - "start": 177, - "end": 188, + "start": 133, + "end": 144, "loc": { "start": { "line": 10, @@ -1308,8 +1016,8 @@ "computed": false, "key": { "type": "Identifier", - "start": 177, - "end": 178, + "start": 133, + "end": 134, "loc": { "start": { "line": 10, @@ -1325,8 +1033,8 @@ }, "value": { "type": "ObjectPattern", - "start": 180, - "end": 188, + "start": 136, + "end": 144, "loc": { "start": { "line": 10, @@ -1340,8 +1048,8 @@ "properties": [ { "type": "RestProperty", - "start": 182, - "end": 186, + "start": 138, + "end": 142, "loc": { "start": { "line": 10, @@ -1354,8 +1062,8 @@ }, "argument": { "type": "Identifier", - "start": 185, - "end": 186, + "start": 141, + "end": 142, "loc": { "start": { "line": 10, @@ -1378,8 +1086,8 @@ "test": null, "consequent": { "type": "BlockStatement", - "start": 192, - "end": 216, + "start": 148, + "end": 172, "loc": { "start": { "line": 11, @@ -1393,8 +1101,8 @@ "body": [ { "type": "ExpressionStatement", - "start": 198, - "end": 216, + "start": 154, + "end": 172, "loc": { "start": { "line": 12, @@ -1407,8 +1115,8 @@ }, "expression": { "type": "CallExpression", - "start": 198, - "end": 216, + "start": 154, + "end": 172, "loc": { "start": { "line": 12, @@ -1421,8 +1129,8 @@ }, "callee": { "type": "MemberExpression", - "start": 198, - "end": 212, + "start": 154, + "end": 168, "loc": { "start": { "line": 12, @@ -1435,8 +1143,8 @@ }, "object": { "type": "ArrayExpression", - "start": 198, - "end": 207, + "start": 154, + "end": 163, "loc": { "start": { "line": 12, @@ -1450,8 +1158,8 @@ "elements": [ { "type": "Identifier", - "start": 199, - "end": 200, + "start": 155, + "end": 156, "loc": { "start": { "line": 12, @@ -1467,8 +1175,8 @@ }, { "type": "Identifier", - "start": 202, - "end": 203, + "start": 158, + "end": 159, "loc": { "start": { "line": 12, @@ -1484,8 +1192,8 @@ }, { "type": "Identifier", - "start": 205, - "end": 206, + "start": 161, + "end": 162, "loc": { "start": { "line": 12, @@ -1503,8 +1211,8 @@ }, "property": { "type": "Identifier", - "start": 208, - "end": 212, + "start": 164, + "end": 168, "loc": { "start": { "line": 12, @@ -1523,8 +1231,8 @@ "arguments": [ { "type": "StringLiteral", - "start": 213, - "end": 215, + "start": 169, + "end": 171, "loc": { "start": { "line": 12, @@ -1553,8 +1261,8 @@ }, { "type": "MatchCase", - "start": 219, - "end": 252, + "start": 175, + "end": 208, "loc": { "start": { "line": 13, @@ -1567,8 +1275,8 @@ }, "binding": { "type": "ObjectPattern", - "start": 221, - "end": 232, + "start": 177, + "end": 188, "loc": { "start": { "line": 13, @@ -1582,8 +1290,8 @@ "properties": [ { "type": "ObjectProperty", - "start": 223, - "end": 224, + "start": 179, + "end": 180, "loc": { "start": { "line": 13, @@ -1599,8 +1307,8 @@ "computed": false, "key": { "type": "Identifier", - "start": 223, - "end": 224, + "start": 179, + "end": 180, "loc": { "start": { "line": 13, @@ -1616,8 +1324,8 @@ }, "value": { "type": "Identifier", - "start": 223, - "end": 224, + "start": 179, + "end": 180, "loc": { "start": { "line": 13, @@ -1637,8 +1345,8 @@ }, { "type": "RestProperty", - "start": 226, - "end": 230, + "start": 182, + "end": 186, "loc": { "start": { "line": 13, @@ -1651,8 +1359,8 @@ }, "argument": { "type": "Identifier", - "start": 229, - "end": 230, + "start": 185, + "end": 186, "loc": { "start": { "line": 13, @@ -1672,8 +1380,8 @@ "test": null, "consequent": { "type": "ExpressionStatement", - "start": 234, - "end": 252, + "start": 190, + "end": 208, "loc": { "start": { "line": 13, @@ -1686,8 +1394,8 @@ }, "expression": { "type": "CallExpression", - "start": 234, - "end": 252, + "start": 190, + "end": 208, "loc": { "start": { "line": 13, @@ -1700,8 +1408,8 @@ }, "callee": { "type": "MemberExpression", - "start": 234, - "end": 248, + "start": 190, + "end": 204, "loc": { "start": { "line": 13, @@ -1714,8 +1422,8 @@ }, "object": { "type": "ArrayExpression", - "start": 234, - "end": 243, + "start": 190, + "end": 199, "loc": { "start": { "line": 13, @@ -1729,8 +1437,8 @@ "elements": [ { "type": "Identifier", - "start": 235, - "end": 236, + "start": 191, + "end": 192, "loc": { "start": { "line": 13, @@ -1746,8 +1454,8 @@ }, { "type": "Identifier", - "start": 238, - "end": 239, + "start": 194, + "end": 195, "loc": { "start": { "line": 13, @@ -1763,8 +1471,8 @@ }, { "type": "Identifier", - "start": 241, - "end": 242, + "start": 197, + "end": 198, "loc": { "start": { "line": 13, @@ -1782,8 +1490,8 @@ }, "property": { "type": "Identifier", - "start": 244, - "end": 248, + "start": 200, + "end": 204, "loc": { "start": { "line": 13, @@ -1802,8 +1510,8 @@ "arguments": [ { "type": "StringLiteral", - "start": 249, - "end": 251, + "start": 205, + "end": 207, "loc": { "start": { "line": 13, diff --git a/test/fixtures/lightscript/match/dot-then-binary-illegal/actual.js b/test/fixtures/lightscript/match/dot-then-binary-illegal/actual.js deleted file mode 100644 index 25ab7a780e..0000000000 --- a/test/fixtures/lightscript/match/dot-then-binary-illegal/actual.js +++ /dev/null @@ -1,2 +0,0 @@ -match x: - | . < 4: 'bad' diff --git a/test/fixtures/lightscript/match/dot-then-binary-illegal/options.json b/test/fixtures/lightscript/match/dot-then-binary-illegal/options.json deleted file mode 100644 index 9660494a29..0000000000 --- a/test/fixtures/lightscript/match/dot-then-binary-illegal/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (2:6)" -} diff --git a/test/fixtures/lightscript/match/in-assignment/actual.js b/test/fixtures/lightscript/match/in-assignment/actual.js index babf04660e..aa9ea91eea 100644 --- a/test/fixtures/lightscript/match/in-assignment/actual.js +++ b/test/fixtures/lightscript/match/in-assignment/actual.js @@ -1,3 +1,3 @@ a = match x: - | > 2: "bigger than two" + | 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 index d6d93ac148..0150cc4179 100644 --- a/test/fixtures/lightscript/match/in-assignment/expected.json +++ b/test/fixtures/lightscript/match/in-assignment/expected.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 68, + "end": 57, "loc": { "start": { "line": 1, @@ -15,7 +15,7 @@ "program": { "type": "Program", "start": 0, - "end": 68, + "end": 57, "loc": { "start": { "line": 1, @@ -31,7 +31,7 @@ { "type": "VariableDeclaration", "start": 0, - "end": 68, + "end": 57, "loc": { "start": { "line": 1, @@ -50,7 +50,7 @@ { "type": "VariableDeclarator", "start": 0, - "end": 68, + "end": 57, "loc": { "start": { "line": 1, @@ -81,7 +81,7 @@ "init": { "type": "MatchExpression", "start": 4, - "end": 68, + "end": 57, "loc": { "start": { "line": 1, @@ -113,7 +113,7 @@ { "type": "MatchCase", "start": 15, - "end": 39, + "end": 28, "loc": { "start": { "line": 2, @@ -121,13 +121,13 @@ }, "end": { "line": 2, - "column": 26 + "column": 15 } }, "test": { - "type": "BinaryExpression", + "type": "NumericLiteral", "start": 17, - "end": 20, + "end": 18, "loc": { "start": { "line": 2, @@ -135,86 +135,55 @@ }, "end": { "line": 2, - "column": 7 + "column": 5 } }, - "left": { - "type": "PlaceholderExpression", - "start": 16, - "end": 17, - "loc": { - "start": { - "line": 2, - "column": 3 - }, - "end": { - "line": 2, - "column": 4 - } - } + "extra": { + "rawValue": 2, + "raw": "2" }, - "operator": ">", - "right": { - "type": "NumericLiteral", - "start": 19, - "end": 20, - "loc": { - "start": { - "line": 2, - "column": 6 - }, - "end": { - "line": 2, - "column": 7 - } - }, - "extra": { - "rawValue": 2, - "raw": "2" - }, - "value": 2 - } + "value": 2 }, "consequent": { "type": "ExpressionStatement", - "start": 22, - "end": 39, + "start": 20, + "end": 28, "loc": { "start": { "line": 2, - "column": 9 + "column": 7 }, "end": { "line": 2, - "column": 26 + "column": 15 } }, "expression": { "type": "StringLiteral", - "start": 22, - "end": 39, + "start": 20, + "end": 28, "loc": { "start": { "line": 2, - "column": 9 + "column": 7 }, "end": { "line": 2, - "column": 26 + "column": 15 } }, "extra": { - "rawValue": "bigger than two", - "raw": "\"bigger than two\"" + "rawValue": "eq two", + "raw": "\"eq two\"" }, - "value": "bigger than two" + "value": "eq two" } } }, { "type": "MatchCase", - "start": 42, - "end": 68, + "start": 31, + "end": 57, "loc": { "start": { "line": 3, @@ -227,8 +196,8 @@ }, "test": { "type": "MatchElse", - "start": 44, - "end": 48, + "start": 33, + "end": 37, "loc": { "start": { "line": 3, @@ -242,8 +211,8 @@ }, "consequent": { "type": "ExpressionStatement", - "start": 50, - "end": 68, + "start": 39, + "end": 57, "loc": { "start": { "line": 3, @@ -256,8 +225,8 @@ }, "expression": { "type": "StringLiteral", - "start": 50, - "end": 68, + "start": 39, + "end": 57, "loc": { "start": { "line": 3, diff --git a/test/fixtures/lightscript/match/jsx-test-illegal/options.json b/test/fixtures/lightscript/match/jsx-test-illegal/options.json index 7c05159f45..b2f4797ad8 100644 --- a/test/fixtures/lightscript/match/jsx-test-illegal/options.json +++ b/test/fixtures/lightscript/match/jsx-test-illegal/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token (2:10)" + "throws": "Unexpected token (2:4)" } diff --git a/test/fixtures/lightscript/match/less-than/actual.js b/test/fixtures/lightscript/match/less-than/actual.js deleted file mode 100644 index 1d87d891d3..0000000000 --- a/test/fixtures/lightscript/match/less-than/actual.js +++ /dev/null @@ -1,3 +0,0 @@ -match x: - | < 3: "not jsx" - | <3: "not jsx" diff --git a/test/fixtures/lightscript/match/less-than/expected.json b/test/fixtures/lightscript/match/less-than/expected.json deleted file mode 100644 index 98dc23bb80..0000000000 --- a/test/fixtures/lightscript/match/less-than/expected.json +++ /dev/null @@ -1,270 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 45, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 3, - "column": 17 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 45, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 3, - "column": 17 - } - }, - "sourceType": "script", - "body": [ - { - "type": "MatchStatement", - "start": 0, - "end": 45, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 3, - "column": 17 - } - }, - "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": 27, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 18 - } - }, - "test": { - "type": "BinaryExpression", - "start": 13, - "end": 16, - "loc": { - "start": { - "line": 2, - "column": 4 - }, - "end": { - "line": 2, - "column": 7 - } - }, - "left": { - "type": "PlaceholderExpression", - "start": 12, - "end": 13, - "loc": { - "start": { - "line": 2, - "column": 3 - }, - "end": { - "line": 2, - "column": 4 - } - } - }, - "operator": "<", - "right": { - "type": "NumericLiteral", - "start": 15, - "end": 16, - "loc": { - "start": { - "line": 2, - "column": 6 - }, - "end": { - "line": 2, - "column": 7 - } - }, - "extra": { - "rawValue": 3, - "raw": "3" - }, - "value": 3 - } - }, - "consequent": { - "type": "ExpressionStatement", - "start": 18, - "end": 27, - "loc": { - "start": { - "line": 2, - "column": 9 - }, - "end": { - "line": 2, - "column": 18 - } - }, - "expression": { - "type": "StringLiteral", - "start": 18, - "end": 27, - "loc": { - "start": { - "line": 2, - "column": 9 - }, - "end": { - "line": 2, - "column": 18 - } - }, - "extra": { - "rawValue": "not jsx", - "raw": "\"not jsx\"" - }, - "value": "not jsx" - } - } - }, - { - "type": "MatchCase", - "start": 30, - "end": 45, - "loc": { - "start": { - "line": 3, - "column": 2 - }, - "end": { - "line": 3, - "column": 17 - } - }, - "test": { - "type": "BinaryExpression", - "start": 32, - "end": 34, - "loc": { - "start": { - "line": 3, - "column": 4 - }, - "end": { - "line": 3, - "column": 6 - } - }, - "left": { - "type": "PlaceholderExpression", - "start": 31, - "end": 32, - "loc": { - "start": { - "line": 3, - "column": 3 - }, - "end": { - "line": 3, - "column": 4 - } - } - }, - "operator": "<", - "right": { - "type": "NumericLiteral", - "start": 33, - "end": 34, - "loc": { - "start": { - "line": 3, - "column": 5 - }, - "end": { - "line": 3, - "column": 6 - } - }, - "extra": { - "rawValue": 3, - "raw": "3" - }, - "value": 3 - } - }, - "consequent": { - "type": "ExpressionStatement", - "start": 36, - "end": 45, - "loc": { - "start": { - "line": 3, - "column": 8 - }, - "end": { - "line": 3, - "column": 17 - } - }, - "expression": { - "type": "StringLiteral", - "start": 36, - "end": 45, - "loc": { - "start": { - "line": 3, - "column": 8 - }, - "end": { - "line": 3, - "column": 17 - } - }, - "extra": { - "rawValue": "not jsx", - "raw": "\"not jsx\"" - }, - "value": "not jsx" - } - } - } - ] - } - ], - "directives": [] - } -} \ No newline at end of file diff --git a/test/fixtures/lightscript/match/multi-subscripts-illegal/actual.js b/test/fixtures/lightscript/match/multi-subscripts-illegal/actual.js deleted file mode 100644 index b30b867cf7..0000000000 --- a/test/fixtures/lightscript/match/multi-subscripts-illegal/actual.js +++ /dev/null @@ -1,2 +0,0 @@ -match x: - | ..d: 'nope' diff --git a/test/fixtures/lightscript/match/multi-subscripts-illegal/options.json b/test/fixtures/lightscript/match/multi-subscripts-illegal/options.json deleted file mode 100644 index 34002b17a3..0000000000 --- a/test/fixtures/lightscript/match/multi-subscripts-illegal/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (2:5)" -} diff --git a/test/fixtures/lightscript/match/multi-subscripts-number-illegal/actual.js b/test/fixtures/lightscript/match/multi-subscripts-number-illegal/actual.js deleted file mode 100644 index 43170a3961..0000000000 --- a/test/fixtures/lightscript/match/multi-subscripts-number-illegal/actual.js +++ /dev/null @@ -1,2 +0,0 @@ -match x: - | ..0: 'bad' diff --git a/test/fixtures/lightscript/match/multi-subscripts-number-illegal/options.json b/test/fixtures/lightscript/match/multi-subscripts-number-illegal/options.json deleted file mode 100644 index 34002b17a3..0000000000 --- a/test/fixtures/lightscript/match/multi-subscripts-number-illegal/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (2:5)" -} diff --git a/test/fixtures/lightscript/match/multi-subscripts-number/actual.js b/test/fixtures/lightscript/match/multi-subscripts-number/actual.js deleted file mode 100644 index 1c0f753907..0000000000 --- a/test/fixtures/lightscript/match/multi-subscripts-number/actual.js +++ /dev/null @@ -1,3 +0,0 @@ -match x: - | .a and .0: 'has a and first child' - | .0.0: 'first child of first child' diff --git a/test/fixtures/lightscript/match/multi-subscripts-number/expected.json b/test/fixtures/lightscript/match/multi-subscripts-number/expected.json deleted file mode 100644 index aa3b1ef5eb..0000000000 --- a/test/fixtures/lightscript/match/multi-subscripts-number/expected.json +++ /dev/null @@ -1,370 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 86, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 3, - "column": 38 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 86, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 3, - "column": 38 - } - }, - "sourceType": "script", - "body": [ - { - "type": "MatchStatement", - "start": 0, - "end": 86, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 3, - "column": 38 - } - }, - "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": 47, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 38 - } - }, - "test": { - "type": "LogicalExpression", - "start": 13, - "end": 22, - "loc": { - "start": { - "line": 2, - "column": 4 - }, - "end": { - "line": 2, - "column": 13 - } - }, - "left": { - "type": "MemberExpression", - "start": 13, - "end": 15, - "loc": { - "start": { - "line": 2, - "column": 4 - }, - "end": { - "line": 2, - "column": 6 - } - }, - "object": { - "type": "PlaceholderExpression", - "start": 12, - "end": 13, - "loc": { - "start": { - "line": 2, - "column": 3 - }, - "end": { - "line": 2, - "column": 4 - } - } - }, - "property": { - "type": "Identifier", - "start": 14, - "end": 15, - "loc": { - "start": { - "line": 2, - "column": 5 - }, - "end": { - "line": 2, - "column": 6 - }, - "identifierName": "a" - }, - "name": "a" - }, - "computed": false - }, - "operator": "&&", - "right": { - "type": "MemberExpression", - "start": 20, - "end": 22, - "loc": { - "start": { - "line": 2, - "column": 11 - }, - "end": { - "line": 2, - "column": 13 - } - }, - "object": { - "type": "PlaceholderExpression", - "start": 19, - "end": 20, - "loc": { - "start": { - "line": 2, - "column": 10 - }, - "end": { - "line": 2, - "column": 11 - } - } - }, - "property": { - "type": "NumericLiteral", - "start": 21, - "end": 22, - "loc": { - "start": { - "line": 2, - "column": 12 - }, - "end": { - "line": 2, - "column": 13 - } - }, - "extra": { - "rawValue": 0, - "raw": "0" - }, - "value": 0 - }, - "computed": true - } - }, - "consequent": { - "type": "ExpressionStatement", - "start": 24, - "end": 47, - "loc": { - "start": { - "line": 2, - "column": 15 - }, - "end": { - "line": 2, - "column": 38 - } - }, - "expression": { - "type": "StringLiteral", - "start": 24, - "end": 47, - "loc": { - "start": { - "line": 2, - "column": 15 - }, - "end": { - "line": 2, - "column": 38 - } - }, - "extra": { - "rawValue": "has a and first child", - "raw": "'has a and first child'" - }, - "value": "has a and first child" - } - } - }, - { - "type": "MatchCase", - "start": 50, - "end": 86, - "loc": { - "start": { - "line": 3, - "column": 2 - }, - "end": { - "line": 3, - "column": 38 - } - }, - "test": { - "type": "MemberExpression", - "start": 52, - "end": 56, - "loc": { - "start": { - "line": 3, - "column": 4 - }, - "end": { - "line": 3, - "column": 8 - } - }, - "object": { - "type": "MemberExpression", - "start": 52, - "end": 54, - "loc": { - "start": { - "line": 3, - "column": 4 - }, - "end": { - "line": 3, - "column": 6 - } - }, - "object": { - "type": "PlaceholderExpression", - "start": 51, - "end": 52, - "loc": { - "start": { - "line": 3, - "column": 3 - }, - "end": { - "line": 3, - "column": 4 - } - } - }, - "property": { - "type": "NumericLiteral", - "start": 53, - "end": 54, - "loc": { - "start": { - "line": 3, - "column": 5 - }, - "end": { - "line": 3, - "column": 6 - } - }, - "extra": { - "rawValue": 0, - "raw": "0" - }, - "value": 0 - }, - "computed": true - }, - "property": { - "type": "NumericLiteral", - "start": 55, - "end": 56, - "loc": { - "start": { - "line": 3, - "column": 7 - }, - "end": { - "line": 3, - "column": 8 - } - }, - "extra": { - "rawValue": 0, - "raw": "0" - }, - "value": 0 - }, - "computed": true - }, - "consequent": { - "type": "ExpressionStatement", - "start": 58, - "end": 86, - "loc": { - "start": { - "line": 3, - "column": 10 - }, - "end": { - "line": 3, - "column": 38 - } - }, - "expression": { - "type": "StringLiteral", - "start": 58, - "end": 86, - "loc": { - "start": { - "line": 3, - "column": 10 - }, - "end": { - "line": 3, - "column": 38 - } - }, - "extra": { - "rawValue": "first child of first child", - "raw": "'first child of first child'" - }, - "value": "first child of first child" - } - } - } - ] - } - ], - "directives": [] - } -} \ No newline at end of file diff --git a/test/fixtures/lightscript/match/multi-subscripts/actual.js b/test/fixtures/lightscript/match/multi-subscripts/actual.js deleted file mode 100644 index 77489eb1e0..0000000000 --- a/test/fixtures/lightscript/match/multi-subscripts/actual.js +++ /dev/null @@ -1,3 +0,0 @@ -match x: - | .a and .b.c: 'has a and b.c' - | ~c() or ~d(): 'its a func' diff --git a/test/fixtures/lightscript/match/multi-subscripts/expected.json b/test/fixtures/lightscript/match/multi-subscripts/expected.json deleted file mode 100644 index 25980932df..0000000000 --- a/test/fixtures/lightscript/match/multi-subscripts/expected.json +++ /dev/null @@ -1,425 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 72, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 3, - "column": 30 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 72, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 3, - "column": 30 - } - }, - "sourceType": "script", - "body": [ - { - "type": "MatchStatement", - "start": 0, - "end": 72, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 3, - "column": 30 - } - }, - "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": "LogicalExpression", - "start": 13, - "end": 24, - "loc": { - "start": { - "line": 2, - "column": 4 - }, - "end": { - "line": 2, - "column": 15 - } - }, - "left": { - "type": "MemberExpression", - "start": 13, - "end": 15, - "loc": { - "start": { - "line": 2, - "column": 4 - }, - "end": { - "line": 2, - "column": 6 - } - }, - "object": { - "type": "PlaceholderExpression", - "start": 12, - "end": 13, - "loc": { - "start": { - "line": 2, - "column": 3 - }, - "end": { - "line": 2, - "column": 4 - } - } - }, - "property": { - "type": "Identifier", - "start": 14, - "end": 15, - "loc": { - "start": { - "line": 2, - "column": 5 - }, - "end": { - "line": 2, - "column": 6 - }, - "identifierName": "a" - }, - "name": "a" - }, - "computed": false - }, - "operator": "&&", - "right": { - "type": "MemberExpression", - "start": 20, - "end": 24, - "loc": { - "start": { - "line": 2, - "column": 11 - }, - "end": { - "line": 2, - "column": 15 - } - }, - "object": { - "type": "MemberExpression", - "start": 20, - "end": 22, - "loc": { - "start": { - "line": 2, - "column": 11 - }, - "end": { - "line": 2, - "column": 13 - } - }, - "object": { - "type": "PlaceholderExpression", - "start": 19, - "end": 20, - "loc": { - "start": { - "line": 2, - "column": 10 - }, - "end": { - "line": 2, - "column": 11 - } - } - }, - "property": { - "type": "Identifier", - "start": 21, - "end": 22, - "loc": { - "start": { - "line": 2, - "column": 12 - }, - "end": { - "line": 2, - "column": 13 - }, - "identifierName": "b" - }, - "name": "b" - }, - "computed": false - }, - "property": { - "type": "Identifier", - "start": 23, - "end": 24, - "loc": { - "start": { - "line": 2, - "column": 14 - }, - "end": { - "line": 2, - "column": 15 - }, - "identifierName": "c" - }, - "name": "c" - }, - "computed": false - } - }, - "consequent": { - "type": "ExpressionStatement", - "start": 26, - "end": 41, - "loc": { - "start": { - "line": 2, - "column": 17 - }, - "end": { - "line": 2, - "column": 32 - } - }, - "expression": { - "type": "StringLiteral", - "start": 26, - "end": 41, - "loc": { - "start": { - "line": 2, - "column": 17 - }, - "end": { - "line": 2, - "column": 32 - } - }, - "extra": { - "rawValue": "has a and b.c", - "raw": "'has a and b.c'" - }, - "value": "has a and b.c" - } - } - }, - { - "type": "MatchCase", - "start": 44, - "end": 72, - "loc": { - "start": { - "line": 3, - "column": 2 - }, - "end": { - "line": 3, - "column": 30 - } - }, - "test": { - "type": "LogicalExpression", - "start": 46, - "end": 58, - "loc": { - "start": { - "line": 3, - "column": 4 - }, - "end": { - "line": 3, - "column": 16 - } - }, - "left": { - "type": "TildeCallExpression", - "start": 46, - "end": 50, - "loc": { - "start": { - "line": 3, - "column": 4 - }, - "end": { - "line": 3, - "column": 8 - } - }, - "left": { - "type": "PlaceholderExpression", - "start": 45, - "end": 46, - "loc": { - "start": { - "line": 3, - "column": 3 - }, - "end": { - "line": 3, - "column": 4 - } - } - }, - "right": { - "type": "Identifier", - "start": 47, - "end": 48, - "loc": { - "start": { - "line": 3, - "column": 5 - }, - "end": { - "line": 3, - "column": 6 - }, - "identifierName": "c" - }, - "name": "c" - }, - "arguments": [] - }, - "operator": "||", - "right": { - "type": "TildeCallExpression", - "start": 54, - "end": 58, - "loc": { - "start": { - "line": 3, - "column": 12 - }, - "end": { - "line": 3, - "column": 16 - } - }, - "left": { - "type": "PlaceholderExpression", - "start": 53, - "end": 54, - "loc": { - "start": { - "line": 3, - "column": 11 - }, - "end": { - "line": 3, - "column": 12 - } - } - }, - "right": { - "type": "Identifier", - "start": 55, - "end": 56, - "loc": { - "start": { - "line": 3, - "column": 13 - }, - "end": { - "line": 3, - "column": 14 - }, - "identifierName": "d" - }, - "name": "d" - }, - "arguments": [] - } - }, - "consequent": { - "type": "ExpressionStatement", - "start": 60, - "end": 72, - "loc": { - "start": { - "line": 3, - "column": 18 - }, - "end": { - "line": 3, - "column": 30 - } - }, - "expression": { - "type": "StringLiteral", - "start": 60, - "end": 72, - "loc": { - "start": { - "line": 3, - "column": 18 - }, - "end": { - "line": 3, - "column": 30 - } - }, - "extra": { - "rawValue": "its a func", - "raw": "'its a func'" - }, - "value": "its a func" - } - } - } - ] - } - ], - "directives": [] - } -} \ No newline at end of file diff --git a/test/fixtures/lightscript/match/nested/actual.js b/test/fixtures/lightscript/match/nested/actual.js index 36dbc5528f..2e436ad960 100644 --- a/test/fixtures/lightscript/match/nested/actual.js +++ b/test/fixtures/lightscript/match/nested/actual.js @@ -1,6 +1,6 @@ match x: - | > 2: match x: - | > 10: "soo big" - | > 5: "still pretty big" + | 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 index 6e6b4acba7..cb608e0bc0 100644 --- a/test/fixtures/lightscript/match/nested/expected.json +++ b/test/fixtures/lightscript/match/nested/expected.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 131, + "end": 137, "loc": { "start": { "line": 1, @@ -15,7 +15,7 @@ "program": { "type": "Program", "start": 0, - "end": 131, + "end": 137, "loc": { "start": { "line": 1, @@ -31,7 +31,7 @@ { "type": "MatchStatement", "start": 0, - "end": 131, + "end": 137, "loc": { "start": { "line": 1, @@ -63,7 +63,7 @@ { "type": "MatchCase", "start": 11, - "end": 102, + "end": 108, "loc": { "start": { "line": 2, @@ -77,7 +77,7 @@ "test": { "type": "BinaryExpression", "start": 13, - "end": 16, + "end": 18, "loc": { "start": { "line": 2, @@ -85,37 +85,39 @@ }, "end": { "line": 2, - "column": 7 + "column": 9 } }, "left": { - "type": "PlaceholderExpression", - "start": 12, - "end": 13, + "type": "Identifier", + "start": 13, + "end": 14, "loc": { "start": { "line": 2, - "column": 3 + "column": 4 }, "end": { "line": 2, - "column": 4 - } - } + "column": 5 + }, + "identifierName": "x" + }, + "name": "x" }, "operator": ">", "right": { "type": "NumericLiteral", - "start": 15, - "end": 16, + "start": 17, + "end": 18, "loc": { "start": { "line": 2, - "column": 6 + "column": 8 }, "end": { "line": 2, - "column": 7 + "column": 9 } }, "extra": { @@ -127,12 +129,12 @@ }, "consequent": { "type": "MatchStatement", - "start": 18, - "end": 102, + "start": 20, + "end": 108, "loc": { "start": { "line": 2, - "column": 9 + "column": 11 }, "end": { "line": 5, @@ -141,26 +143,26 @@ }, "discriminant": { "type": "Identifier", - "start": 24, - "end": 25, + "start": 26, + "end": 27, "loc": { "start": { "line": 2, - "column": 15 + "column": 17 }, "end": { "line": 2, - "column": 16 + "column": 18 }, - "identifierName": "x" + "identifierName": "y" }, - "name": "x" + "name": "y" }, "cases": [ { "type": "MatchCase", - "start": 31, - "end": 48, + "start": 33, + "end": 52, "loc": { "start": { "line": 3, @@ -168,13 +170,13 @@ }, "end": { "line": 3, - "column": 21 + "column": 23 } }, "test": { "type": "BinaryExpression", - "start": 33, - "end": 37, + "start": 35, + "end": 41, "loc": { "start": { "line": 3, @@ -182,37 +184,39 @@ }, "end": { "line": 3, - "column": 10 + "column": 12 } }, "left": { - "type": "PlaceholderExpression", - "start": 32, - "end": 33, + "type": "Identifier", + "start": 35, + "end": 36, "loc": { "start": { "line": 3, - "column": 5 + "column": 6 }, "end": { "line": 3, - "column": 6 - } - } + "column": 7 + }, + "identifierName": "y" + }, + "name": "y" }, "operator": ">", "right": { "type": "NumericLiteral", - "start": 35, - "end": 37, + "start": 39, + "end": 41, "loc": { "start": { "line": 3, - "column": 8 + "column": 10 }, "end": { "line": 3, - "column": 10 + "column": 12 } }, "extra": { @@ -224,30 +228,30 @@ }, "consequent": { "type": "ExpressionStatement", - "start": 39, - "end": 48, + "start": 43, + "end": 52, "loc": { "start": { "line": 3, - "column": 12 + "column": 14 }, "end": { "line": 3, - "column": 21 + "column": 23 } }, "expression": { "type": "StringLiteral", - "start": 39, - "end": 48, + "start": 43, + "end": 52, "loc": { "start": { "line": 3, - "column": 12 + "column": 14 }, "end": { "line": 3, - "column": 21 + "column": 23 } }, "extra": { @@ -260,8 +264,8 @@ }, { "type": "MatchCase", - "start": 53, - "end": 78, + "start": 57, + "end": 84, "loc": { "start": { "line": 4, @@ -269,13 +273,13 @@ }, "end": { "line": 4, - "column": 29 + "column": 31 } }, "test": { "type": "BinaryExpression", - "start": 55, - "end": 58, + "start": 59, + "end": 64, "loc": { "start": { "line": 4, @@ -283,37 +287,39 @@ }, "end": { "line": 4, - "column": 9 + "column": 11 } }, "left": { - "type": "PlaceholderExpression", - "start": 54, - "end": 55, + "type": "Identifier", + "start": 59, + "end": 60, "loc": { "start": { "line": 4, - "column": 5 + "column": 6 }, "end": { "line": 4, - "column": 6 - } - } + "column": 7 + }, + "identifierName": "y" + }, + "name": "y" }, "operator": ">", "right": { "type": "NumericLiteral", - "start": 57, - "end": 58, + "start": 63, + "end": 64, "loc": { "start": { "line": 4, - "column": 8 + "column": 10 }, "end": { "line": 4, - "column": 9 + "column": 11 } }, "extra": { @@ -325,30 +331,30 @@ }, "consequent": { "type": "ExpressionStatement", - "start": 60, - "end": 78, + "start": 66, + "end": 84, "loc": { "start": { "line": 4, - "column": 11 + "column": 13 }, "end": { "line": 4, - "column": 29 + "column": 31 } }, "expression": { "type": "StringLiteral", - "start": 60, - "end": 78, + "start": 66, + "end": 84, "loc": { "start": { "line": 4, - "column": 11 + "column": 13 }, "end": { "line": 4, - "column": 29 + "column": 31 } }, "extra": { @@ -361,8 +367,8 @@ }, { "type": "MatchCase", - "start": 83, - "end": 102, + "start": 89, + "end": 108, "loc": { "start": { "line": 5, @@ -375,8 +381,8 @@ }, "test": { "type": "MatchElse", - "start": 85, - "end": 89, + "start": 91, + "end": 95, "loc": { "start": { "line": 5, @@ -390,8 +396,8 @@ }, "consequent": { "type": "ExpressionStatement", - "start": 91, - "end": 102, + "start": 97, + "end": 108, "loc": { "start": { "line": 5, @@ -404,8 +410,8 @@ }, "expression": { "type": "StringLiteral", - "start": 91, - "end": 102, + "start": 97, + "end": 108, "loc": { "start": { "line": 5, @@ -429,8 +435,8 @@ }, { "type": "MatchCase", - "start": 105, - "end": 131, + "start": 111, + "end": 137, "loc": { "start": { "line": 6, @@ -443,8 +449,8 @@ }, "test": { "type": "MatchElse", - "start": 107, - "end": 111, + "start": 113, + "end": 117, "loc": { "start": { "line": 6, @@ -458,8 +464,8 @@ }, "consequent": { "type": "ExpressionStatement", - "start": 113, - "end": 131, + "start": 119, + "end": 137, "loc": { "start": { "line": 6, @@ -472,8 +478,8 @@ }, "expression": { "type": "StringLiteral", - "start": 113, - "end": 131, + "start": 119, + "end": 137, "loc": { "start": { "line": 6, diff --git a/test/fixtures/lightscript/match/not/actual.js b/test/fixtures/lightscript/match/not/actual.js deleted file mode 100644 index 7a92dad138..0000000000 --- a/test/fixtures/lightscript/match/not/actual.js +++ /dev/null @@ -1,9 +0,0 @@ -match x: - | not: true - | !!: true - | not < 3: true - | not + 1: true - | ! ~f(): true - | not .prop: true - | not or not not and not: true - | ! or !! and !: true diff --git a/test/fixtures/lightscript/match/not/expected.json b/test/fixtures/lightscript/match/not/expected.json deleted file mode 100644 index b6d3310196..0000000000 --- a/test/fixtures/lightscript/match/not/expected.json +++ /dev/null @@ -1,1118 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 165, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 9, - "column": 23 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 165, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 9, - "column": 23 - } - }, - "sourceType": "script", - "body": [ - { - "type": "MatchStatement", - "start": 0, - "end": 165, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 9, - "column": 23 - } - }, - "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": 22, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 13 - } - }, - "test": { - "type": "UnaryExpression", - "start": 13, - "end": 16, - "loc": { - "start": { - "line": 2, - "column": 4 - }, - "end": { - "line": 2, - "column": 7 - } - }, - "operator": "!", - "prefix": true, - "argument": { - "type": "PlaceholderExpression", - "start": 16, - "end": 16, - "loc": { - "start": { - "line": 2, - "column": 7 - }, - "end": { - "line": 2, - "column": 7 - } - } - }, - "extra": { - "parenthesizedArgument": false - } - }, - "consequent": { - "type": "ExpressionStatement", - "start": 18, - "end": 22, - "loc": { - "start": { - "line": 2, - "column": 9 - }, - "end": { - "line": 2, - "column": 13 - } - }, - "expression": { - "type": "BooleanLiteral", - "start": 18, - "end": 22, - "loc": { - "start": { - "line": 2, - "column": 9 - }, - "end": { - "line": 2, - "column": 13 - } - }, - "value": true - } - } - }, - { - "type": "MatchCase", - "start": 25, - "end": 35, - "loc": { - "start": { - "line": 3, - "column": 2 - }, - "end": { - "line": 3, - "column": 12 - } - }, - "test": { - "type": "UnaryExpression", - "start": 27, - "end": 29, - "loc": { - "start": { - "line": 3, - "column": 4 - }, - "end": { - "line": 3, - "column": 6 - } - }, - "operator": "!", - "prefix": true, - "argument": { - "type": "UnaryExpression", - "start": 28, - "end": 29, - "loc": { - "start": { - "line": 3, - "column": 5 - }, - "end": { - "line": 3, - "column": 6 - } - }, - "operator": "!", - "prefix": true, - "argument": { - "type": "PlaceholderExpression", - "start": 29, - "end": 29, - "loc": { - "start": { - "line": 3, - "column": 6 - }, - "end": { - "line": 3, - "column": 6 - } - } - }, - "extra": { - "parenthesizedArgument": false - } - }, - "extra": { - "parenthesizedArgument": false - } - }, - "consequent": { - "type": "ExpressionStatement", - "start": 31, - "end": 35, - "loc": { - "start": { - "line": 3, - "column": 8 - }, - "end": { - "line": 3, - "column": 12 - } - }, - "expression": { - "type": "BooleanLiteral", - "start": 31, - "end": 35, - "loc": { - "start": { - "line": 3, - "column": 8 - }, - "end": { - "line": 3, - "column": 12 - } - }, - "value": true - } - } - }, - { - "type": "MatchCase", - "start": 38, - "end": 53, - "loc": { - "start": { - "line": 4, - "column": 2 - }, - "end": { - "line": 4, - "column": 17 - } - }, - "test": { - "type": "UnaryExpression", - "start": 40, - "end": 47, - "loc": { - "start": { - "line": 4, - "column": 4 - }, - "end": { - "line": 4, - "column": 11 - } - }, - "operator": "!", - "prefix": true, - "argument": { - "type": "BinaryExpression", - "start": 44, - "end": 47, - "loc": { - "start": { - "line": 4, - "column": 8 - }, - "end": { - "line": 4, - "column": 11 - } - }, - "left": { - "type": "PlaceholderExpression", - "start": 43, - "end": 44, - "loc": { - "start": { - "line": 4, - "column": 7 - }, - "end": { - "line": 4, - "column": 8 - } - } - }, - "operator": "<", - "right": { - "type": "NumericLiteral", - "start": 46, - "end": 47, - "loc": { - "start": { - "line": 4, - "column": 10 - }, - "end": { - "line": 4, - "column": 11 - } - }, - "extra": { - "rawValue": 3, - "raw": "3" - }, - "value": 3 - } - }, - "extra": { - "parenthesizedArgument": false - } - }, - "consequent": { - "type": "ExpressionStatement", - "start": 49, - "end": 53, - "loc": { - "start": { - "line": 4, - "column": 13 - }, - "end": { - "line": 4, - "column": 17 - } - }, - "expression": { - "type": "BooleanLiteral", - "start": 49, - "end": 53, - "loc": { - "start": { - "line": 4, - "column": 13 - }, - "end": { - "line": 4, - "column": 17 - } - }, - "value": true - } - } - }, - { - "type": "MatchCase", - "start": 56, - "end": 71, - "loc": { - "start": { - "line": 5, - "column": 2 - }, - "end": { - "line": 5, - "column": 17 - } - }, - "test": { - "type": "BinaryExpression", - "start": 58, - "end": 65, - "loc": { - "start": { - "line": 5, - "column": 4 - }, - "end": { - "line": 5, - "column": 11 - } - }, - "left": { - "type": "UnaryExpression", - "start": 58, - "end": 61, - "loc": { - "start": { - "line": 5, - "column": 4 - }, - "end": { - "line": 5, - "column": 7 - } - }, - "operator": "!", - "prefix": true, - "argument": { - "type": "PlaceholderExpression", - "start": 61, - "end": 62, - "loc": { - "start": { - "line": 5, - "column": 7 - }, - "end": { - "line": 5, - "column": 8 - } - } - }, - "extra": { - "parenthesizedArgument": false - } - }, - "operator": "+", - "right": { - "type": "NumericLiteral", - "start": 64, - "end": 65, - "loc": { - "start": { - "line": 5, - "column": 10 - }, - "end": { - "line": 5, - "column": 11 - } - }, - "extra": { - "rawValue": 1, - "raw": "1" - }, - "value": 1 - } - }, - "consequent": { - "type": "ExpressionStatement", - "start": 67, - "end": 71, - "loc": { - "start": { - "line": 5, - "column": 13 - }, - "end": { - "line": 5, - "column": 17 - } - }, - "expression": { - "type": "BooleanLiteral", - "start": 67, - "end": 71, - "loc": { - "start": { - "line": 5, - "column": 13 - }, - "end": { - "line": 5, - "column": 17 - } - }, - "value": true - } - } - }, - { - "type": "MatchCase", - "start": 74, - "end": 88, - "loc": { - "start": { - "line": 6, - "column": 2 - }, - "end": { - "line": 6, - "column": 16 - } - }, - "test": { - "type": "UnaryExpression", - "start": 76, - "end": 82, - "loc": { - "start": { - "line": 6, - "column": 4 - }, - "end": { - "line": 6, - "column": 10 - } - }, - "operator": "!", - "prefix": true, - "argument": { - "type": "TildeCallExpression", - "start": 78, - "end": 82, - "loc": { - "start": { - "line": 6, - "column": 6 - }, - "end": { - "line": 6, - "column": 10 - } - }, - "left": { - "type": "PlaceholderExpression", - "start": 77, - "end": 78, - "loc": { - "start": { - "line": 6, - "column": 5 - }, - "end": { - "line": 6, - "column": 6 - } - } - }, - "right": { - "type": "Identifier", - "start": 79, - "end": 80, - "loc": { - "start": { - "line": 6, - "column": 7 - }, - "end": { - "line": 6, - "column": 8 - }, - "identifierName": "f" - }, - "name": "f" - }, - "arguments": [] - }, - "extra": { - "parenthesizedArgument": false - } - }, - "consequent": { - "type": "ExpressionStatement", - "start": 84, - "end": 88, - "loc": { - "start": { - "line": 6, - "column": 12 - }, - "end": { - "line": 6, - "column": 16 - } - }, - "expression": { - "type": "BooleanLiteral", - "start": 84, - "end": 88, - "loc": { - "start": { - "line": 6, - "column": 12 - }, - "end": { - "line": 6, - "column": 16 - } - }, - "value": true - } - } - }, - { - "type": "MatchCase", - "start": 91, - "end": 108, - "loc": { - "start": { - "line": 7, - "column": 2 - }, - "end": { - "line": 7, - "column": 19 - } - }, - "test": { - "type": "UnaryExpression", - "start": 93, - "end": 102, - "loc": { - "start": { - "line": 7, - "column": 4 - }, - "end": { - "line": 7, - "column": 13 - } - }, - "operator": "!", - "prefix": true, - "argument": { - "type": "MemberExpression", - "start": 97, - "end": 102, - "loc": { - "start": { - "line": 7, - "column": 8 - }, - "end": { - "line": 7, - "column": 13 - } - }, - "object": { - "type": "PlaceholderExpression", - "start": 96, - "end": 97, - "loc": { - "start": { - "line": 7, - "column": 7 - }, - "end": { - "line": 7, - "column": 8 - } - } - }, - "property": { - "type": "Identifier", - "start": 98, - "end": 102, - "loc": { - "start": { - "line": 7, - "column": 9 - }, - "end": { - "line": 7, - "column": 13 - }, - "identifierName": "prop" - }, - "name": "prop" - }, - "computed": false - }, - "extra": { - "parenthesizedArgument": false - } - }, - "consequent": { - "type": "ExpressionStatement", - "start": 104, - "end": 108, - "loc": { - "start": { - "line": 7, - "column": 15 - }, - "end": { - "line": 7, - "column": 19 - } - }, - "expression": { - "type": "BooleanLiteral", - "start": 104, - "end": 108, - "loc": { - "start": { - "line": 7, - "column": 15 - }, - "end": { - "line": 7, - "column": 19 - } - }, - "value": true - } - } - }, - { - "type": "MatchCase", - "start": 111, - "end": 141, - "loc": { - "start": { - "line": 8, - "column": 2 - }, - "end": { - "line": 8, - "column": 32 - } - }, - "test": { - "type": "LogicalExpression", - "start": 113, - "end": 135, - "loc": { - "start": { - "line": 8, - "column": 4 - }, - "end": { - "line": 8, - "column": 26 - } - }, - "left": { - "type": "UnaryExpression", - "start": 113, - "end": 116, - "loc": { - "start": { - "line": 8, - "column": 4 - }, - "end": { - "line": 8, - "column": 7 - } - }, - "operator": "!", - "prefix": true, - "argument": { - "type": "PlaceholderExpression", - "start": 116, - "end": 117, - "loc": { - "start": { - "line": 8, - "column": 7 - }, - "end": { - "line": 8, - "column": 8 - } - } - }, - "extra": { - "parenthesizedArgument": false - } - }, - "operator": "||", - "right": { - "type": "LogicalExpression", - "start": 120, - "end": 135, - "loc": { - "start": { - "line": 8, - "column": 11 - }, - "end": { - "line": 8, - "column": 26 - } - }, - "left": { - "type": "UnaryExpression", - "start": 120, - "end": 127, - "loc": { - "start": { - "line": 8, - "column": 11 - }, - "end": { - "line": 8, - "column": 18 - } - }, - "operator": "!", - "prefix": true, - "argument": { - "type": "UnaryExpression", - "start": 124, - "end": 127, - "loc": { - "start": { - "line": 8, - "column": 15 - }, - "end": { - "line": 8, - "column": 18 - } - }, - "operator": "!", - "prefix": true, - "argument": { - "type": "PlaceholderExpression", - "start": 127, - "end": 128, - "loc": { - "start": { - "line": 8, - "column": 18 - }, - "end": { - "line": 8, - "column": 19 - } - } - }, - "extra": { - "parenthesizedArgument": false - } - }, - "extra": { - "parenthesizedArgument": false - } - }, - "operator": "&&", - "right": { - "type": "UnaryExpression", - "start": 132, - "end": 135, - "loc": { - "start": { - "line": 8, - "column": 23 - }, - "end": { - "line": 8, - "column": 26 - } - }, - "operator": "!", - "prefix": true, - "argument": { - "type": "PlaceholderExpression", - "start": 135, - "end": 135, - "loc": { - "start": { - "line": 8, - "column": 26 - }, - "end": { - "line": 8, - "column": 26 - } - } - }, - "extra": { - "parenthesizedArgument": false - } - } - } - }, - "consequent": { - "type": "ExpressionStatement", - "start": 137, - "end": 141, - "loc": { - "start": { - "line": 8, - "column": 28 - }, - "end": { - "line": 8, - "column": 32 - } - }, - "expression": { - "type": "BooleanLiteral", - "start": 137, - "end": 141, - "loc": { - "start": { - "line": 8, - "column": 28 - }, - "end": { - "line": 8, - "column": 32 - } - }, - "value": true - } - } - }, - { - "type": "MatchCase", - "start": 144, - "end": 165, - "loc": { - "start": { - "line": 9, - "column": 2 - }, - "end": { - "line": 9, - "column": 23 - } - }, - "test": { - "type": "LogicalExpression", - "start": 146, - "end": 159, - "loc": { - "start": { - "line": 9, - "column": 4 - }, - "end": { - "line": 9, - "column": 17 - } - }, - "left": { - "type": "UnaryExpression", - "start": 146, - "end": 147, - "loc": { - "start": { - "line": 9, - "column": 4 - }, - "end": { - "line": 9, - "column": 5 - } - }, - "operator": "!", - "prefix": true, - "argument": { - "type": "PlaceholderExpression", - "start": 147, - "end": 148, - "loc": { - "start": { - "line": 9, - "column": 5 - }, - "end": { - "line": 9, - "column": 6 - } - } - }, - "extra": { - "parenthesizedArgument": false - } - }, - "operator": "||", - "right": { - "type": "LogicalExpression", - "start": 151, - "end": 159, - "loc": { - "start": { - "line": 9, - "column": 9 - }, - "end": { - "line": 9, - "column": 17 - } - }, - "left": { - "type": "UnaryExpression", - "start": 151, - "end": 153, - "loc": { - "start": { - "line": 9, - "column": 9 - }, - "end": { - "line": 9, - "column": 11 - } - }, - "operator": "!", - "prefix": true, - "argument": { - "type": "UnaryExpression", - "start": 152, - "end": 153, - "loc": { - "start": { - "line": 9, - "column": 10 - }, - "end": { - "line": 9, - "column": 11 - } - }, - "operator": "!", - "prefix": true, - "argument": { - "type": "PlaceholderExpression", - "start": 153, - "end": 154, - "loc": { - "start": { - "line": 9, - "column": 11 - }, - "end": { - "line": 9, - "column": 12 - } - } - }, - "extra": { - "parenthesizedArgument": false - } - }, - "extra": { - "parenthesizedArgument": false - } - }, - "operator": "&&", - "right": { - "type": "UnaryExpression", - "start": 158, - "end": 159, - "loc": { - "start": { - "line": 9, - "column": 16 - }, - "end": { - "line": 9, - "column": 17 - } - }, - "operator": "!", - "prefix": true, - "argument": { - "type": "PlaceholderExpression", - "start": 159, - "end": 159, - "loc": { - "start": { - "line": 9, - "column": 17 - }, - "end": { - "line": 9, - "column": 17 - } - } - }, - "extra": { - "parenthesizedArgument": false - } - } - } - }, - "consequent": { - "type": "ExpressionStatement", - "start": 161, - "end": 165, - "loc": { - "start": { - "line": 9, - "column": 19 - }, - "end": { - "line": 9, - "column": 23 - } - }, - "expression": { - "type": "BooleanLiteral", - "start": 161, - "end": 165, - "loc": { - "start": { - "line": 9, - "column": 19 - }, - "end": { - "line": 9, - "column": 23 - } - }, - "value": true - } - } - } - ] - } - ], - "directives": [] - } -} \ No newline at end of file diff --git a/test/fixtures/lightscript/match/parens-no-curlies/actual.js b/test/fixtures/lightscript/match/parens-no-curlies/actual.js index 47af3d40ad..b3103df97a 100644 --- a/test/fixtures/lightscript/match/parens-no-curlies/actual.js +++ b/test/fixtures/lightscript/match/parens-no-curlies/actual.js @@ -1,3 +1,3 @@ a = match (x): - | > 2: "bigger than two" + | 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 index c57f23c768..7bfa24b559 100644 --- a/test/fixtures/lightscript/match/parens-no-curlies/expected.json +++ b/test/fixtures/lightscript/match/parens-no-curlies/expected.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 70, + "end": 59, "loc": { "start": { "line": 1, @@ -15,7 +15,7 @@ "program": { "type": "Program", "start": 0, - "end": 70, + "end": 59, "loc": { "start": { "line": 1, @@ -31,7 +31,7 @@ { "type": "VariableDeclaration", "start": 0, - "end": 70, + "end": 59, "loc": { "start": { "line": 1, @@ -50,7 +50,7 @@ { "type": "VariableDeclarator", "start": 0, - "end": 70, + "end": 59, "loc": { "start": { "line": 1, @@ -81,7 +81,7 @@ "init": { "type": "MatchExpression", "start": 4, - "end": 70, + "end": 59, "loc": { "start": { "line": 1, @@ -114,7 +114,7 @@ { "type": "MatchCase", "start": 17, - "end": 41, + "end": 30, "loc": { "start": { "line": 2, @@ -122,13 +122,13 @@ }, "end": { "line": 2, - "column": 26 + "column": 15 } }, "test": { - "type": "BinaryExpression", + "type": "NumericLiteral", "start": 19, - "end": 22, + "end": 20, "loc": { "start": { "line": 2, @@ -136,86 +136,55 @@ }, "end": { "line": 2, - "column": 7 + "column": 5 } }, - "left": { - "type": "PlaceholderExpression", - "start": 18, - "end": 19, - "loc": { - "start": { - "line": 2, - "column": 3 - }, - "end": { - "line": 2, - "column": 4 - } - } + "extra": { + "rawValue": 2, + "raw": "2" }, - "operator": ">", - "right": { - "type": "NumericLiteral", - "start": 21, - "end": 22, - "loc": { - "start": { - "line": 2, - "column": 6 - }, - "end": { - "line": 2, - "column": 7 - } - }, - "extra": { - "rawValue": 2, - "raw": "2" - }, - "value": 2 - } + "value": 2 }, "consequent": { "type": "ExpressionStatement", - "start": 24, - "end": 41, + "start": 22, + "end": 30, "loc": { "start": { "line": 2, - "column": 9 + "column": 7 }, "end": { "line": 2, - "column": 26 + "column": 15 } }, "expression": { "type": "StringLiteral", - "start": 24, - "end": 41, + "start": 22, + "end": 30, "loc": { "start": { "line": 2, - "column": 9 + "column": 7 }, "end": { "line": 2, - "column": 26 + "column": 15 } }, "extra": { - "rawValue": "bigger than two", - "raw": "\"bigger than two\"" + "rawValue": "eq two", + "raw": "\"eq two\"" }, - "value": "bigger than two" + "value": "eq two" } } }, { "type": "MatchCase", - "start": 44, - "end": 70, + "start": 33, + "end": 59, "loc": { "start": { "line": 3, @@ -228,8 +197,8 @@ }, "test": { "type": "MatchElse", - "start": 46, - "end": 50, + "start": 35, + "end": 39, "loc": { "start": { "line": 3, @@ -243,8 +212,8 @@ }, "consequent": { "type": "ExpressionStatement", - "start": 52, - "end": 70, + "start": 41, + "end": 59, "loc": { "start": { "line": 3, @@ -257,8 +226,8 @@ }, "expression": { "type": "StringLiteral", - "start": 52, - "end": 70, + "start": 41, + "end": 59, "loc": { "start": { "line": 3, diff --git a/test/fixtures/lightscript/match/subscript-in-tilde/actual.js b/test/fixtures/lightscript/match/subscript-in-tilde/actual.js deleted file mode 100644 index 9e4dfee2f1..0000000000 --- a/test/fixtures/lightscript/match/subscript-in-tilde/actual.js +++ /dev/null @@ -1,2 +0,0 @@ -match x: - | ~c(.d): 'its a func' diff --git a/test/fixtures/lightscript/match/subscript-in-tilde/expected.json b/test/fixtures/lightscript/match/subscript-in-tilde/expected.json deleted file mode 100644 index fe3e2ae318..0000000000 --- a/test/fixtures/lightscript/match/subscript-in-tilde/expected.json +++ /dev/null @@ -1,215 +0,0 @@ -{ - "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 - } - }, - "test": { - "type": "TildeCallExpression", - "start": 13, - "end": 19, - "loc": { - "start": { - "line": 2, - "column": 4 - }, - "end": { - "line": 2, - "column": 10 - } - }, - "left": { - "type": "PlaceholderExpression", - "start": 12, - "end": 13, - "loc": { - "start": { - "line": 2, - "column": 3 - }, - "end": { - "line": 2, - "column": 4 - } - } - }, - "right": { - "type": "Identifier", - "start": 14, - "end": 15, - "loc": { - "start": { - "line": 2, - "column": 5 - }, - "end": { - "line": 2, - "column": 6 - }, - "identifierName": "c" - }, - "name": "c" - }, - "arguments": [ - { - "type": "MemberExpression", - "start": 16, - "end": 18, - "loc": { - "start": { - "line": 2, - "column": 7 - }, - "end": { - "line": 2, - "column": 9 - } - }, - "object": { - "type": "PlaceholderExpression", - "start": 16, - "end": 16, - "loc": { - "start": { - "line": 2, - "column": 7 - }, - "end": { - "line": 2, - "column": 7 - } - } - }, - "property": { - "type": "Identifier", - "start": 17, - "end": 18, - "loc": { - "start": { - "line": 2, - "column": 8 - }, - "end": { - "line": 2, - "column": 9 - }, - "identifierName": "d" - }, - "name": "d" - }, - "computed": false - } - ] - }, - "consequent": { - "type": "ExpressionStatement", - "start": 21, - "end": 33, - "loc": { - "start": { - "line": 2, - "column": 12 - }, - "end": { - "line": 2, - "column": 24 - } - }, - "expression": { - "type": "StringLiteral", - "start": 21, - "end": 33, - "loc": { - "start": { - "line": 2, - "column": 12 - }, - "end": { - "line": 2, - "column": 24 - } - }, - "extra": { - "rawValue": "its a func", - "raw": "'its a func'" - }, - "value": "its a func" - } - } - } - ] - } - ], - "directives": [] - } -} \ No newline at end of file diff --git a/test/fixtures/lightscript/match/subscripts/actual.js b/test/fixtures/lightscript/match/subscripts/actual.js deleted file mode 100644 index 62d4889664..0000000000 --- a/test/fixtures/lightscript/match/subscripts/actual.js +++ /dev/null @@ -1,6 +0,0 @@ -match x: - | .a: 'has a' - | ?.c: 'has c' - | ?[d]: 'has d' - | .0: 'has first elem' - | ~isFunction(): 'its a func' diff --git a/test/fixtures/lightscript/match/subscripts/expected.json b/test/fixtures/lightscript/match/subscripts/expected.json deleted file mode 100644 index 432b459e6c..0000000000 --- a/test/fixtures/lightscript/match/subscripts/expected.json +++ /dev/null @@ -1,561 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 116, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 6, - "column": 31 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 116, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 6, - "column": 31 - } - }, - "sourceType": "script", - "body": [ - { - "type": "MatchStatement", - "start": 0, - "end": 116, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 6, - "column": 31 - } - }, - "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": 24, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 15 - } - }, - "test": { - "type": "MemberExpression", - "start": 13, - "end": 15, - "loc": { - "start": { - "line": 2, - "column": 4 - }, - "end": { - "line": 2, - "column": 6 - } - }, - "object": { - "type": "PlaceholderExpression", - "start": 12, - "end": 13, - "loc": { - "start": { - "line": 2, - "column": 3 - }, - "end": { - "line": 2, - "column": 4 - } - } - }, - "property": { - "type": "Identifier", - "start": 14, - "end": 15, - "loc": { - "start": { - "line": 2, - "column": 5 - }, - "end": { - "line": 2, - "column": 6 - }, - "identifierName": "a" - }, - "name": "a" - }, - "computed": false - }, - "consequent": { - "type": "ExpressionStatement", - "start": 17, - "end": 24, - "loc": { - "start": { - "line": 2, - "column": 8 - }, - "end": { - "line": 2, - "column": 15 - } - }, - "expression": { - "type": "StringLiteral", - "start": 17, - "end": 24, - "loc": { - "start": { - "line": 2, - "column": 8 - }, - "end": { - "line": 2, - "column": 15 - } - }, - "extra": { - "rawValue": "has a", - "raw": "'has a'" - }, - "value": "has a" - } - } - }, - { - "type": "MatchCase", - "start": 27, - "end": 41, - "loc": { - "start": { - "line": 3, - "column": 2 - }, - "end": { - "line": 3, - "column": 16 - } - }, - "test": { - "type": "SafeMemberExpression", - "start": 29, - "end": 32, - "loc": { - "start": { - "line": 3, - "column": 4 - }, - "end": { - "line": 3, - "column": 7 - } - }, - "object": { - "type": "PlaceholderExpression", - "start": 28, - "end": 29, - "loc": { - "start": { - "line": 3, - "column": 3 - }, - "end": { - "line": 3, - "column": 4 - } - } - }, - "property": { - "type": "Identifier", - "start": 31, - "end": 32, - "loc": { - "start": { - "line": 3, - "column": 6 - }, - "end": { - "line": 3, - "column": 7 - }, - "identifierName": "c" - }, - "name": "c" - }, - "computed": false - }, - "consequent": { - "type": "ExpressionStatement", - "start": 34, - "end": 41, - "loc": { - "start": { - "line": 3, - "column": 9 - }, - "end": { - "line": 3, - "column": 16 - } - }, - "expression": { - "type": "StringLiteral", - "start": 34, - "end": 41, - "loc": { - "start": { - "line": 3, - "column": 9 - }, - "end": { - "line": 3, - "column": 16 - } - }, - "extra": { - "rawValue": "has c", - "raw": "'has c'" - }, - "value": "has c" - } - } - }, - { - "type": "MatchCase", - "start": 44, - "end": 59, - "loc": { - "start": { - "line": 4, - "column": 2 - }, - "end": { - "line": 4, - "column": 17 - } - }, - "test": { - "type": "SafeMemberExpression", - "start": 46, - "end": 50, - "loc": { - "start": { - "line": 4, - "column": 4 - }, - "end": { - "line": 4, - "column": 8 - } - }, - "object": { - "type": "PlaceholderExpression", - "start": 45, - "end": 46, - "loc": { - "start": { - "line": 4, - "column": 3 - }, - "end": { - "line": 4, - "column": 4 - } - } - }, - "property": { - "type": "Identifier", - "start": 48, - "end": 49, - "loc": { - "start": { - "line": 4, - "column": 6 - }, - "end": { - "line": 4, - "column": 7 - }, - "identifierName": "d" - }, - "name": "d" - }, - "computed": true - }, - "consequent": { - "type": "ExpressionStatement", - "start": 52, - "end": 59, - "loc": { - "start": { - "line": 4, - "column": 10 - }, - "end": { - "line": 4, - "column": 17 - } - }, - "expression": { - "type": "StringLiteral", - "start": 52, - "end": 59, - "loc": { - "start": { - "line": 4, - "column": 10 - }, - "end": { - "line": 4, - "column": 17 - } - }, - "extra": { - "rawValue": "has d", - "raw": "'has d'" - }, - "value": "has d" - } - } - }, - { - "type": "MatchCase", - "start": 62, - "end": 84, - "loc": { - "start": { - "line": 5, - "column": 2 - }, - "end": { - "line": 5, - "column": 24 - } - }, - "test": { - "type": "MemberExpression", - "start": 64, - "end": 66, - "loc": { - "start": { - "line": 5, - "column": 4 - }, - "end": { - "line": 5, - "column": 6 - } - }, - "object": { - "type": "PlaceholderExpression", - "start": 63, - "end": 64, - "loc": { - "start": { - "line": 5, - "column": 3 - }, - "end": { - "line": 5, - "column": 4 - } - } - }, - "property": { - "type": "NumericLiteral", - "start": 65, - "end": 66, - "loc": { - "start": { - "line": 5, - "column": 5 - }, - "end": { - "line": 5, - "column": 6 - } - }, - "extra": { - "rawValue": 0, - "raw": "0" - }, - "value": 0 - }, - "computed": true - }, - "consequent": { - "type": "ExpressionStatement", - "start": 68, - "end": 84, - "loc": { - "start": { - "line": 5, - "column": 8 - }, - "end": { - "line": 5, - "column": 24 - } - }, - "expression": { - "type": "StringLiteral", - "start": 68, - "end": 84, - "loc": { - "start": { - "line": 5, - "column": 8 - }, - "end": { - "line": 5, - "column": 24 - } - }, - "extra": { - "rawValue": "has first elem", - "raw": "'has first elem'" - }, - "value": "has first elem" - } - } - }, - { - "type": "MatchCase", - "start": 87, - "end": 116, - "loc": { - "start": { - "line": 6, - "column": 2 - }, - "end": { - "line": 6, - "column": 31 - } - }, - "test": { - "type": "TildeCallExpression", - "start": 89, - "end": 102, - "loc": { - "start": { - "line": 6, - "column": 4 - }, - "end": { - "line": 6, - "column": 17 - } - }, - "left": { - "type": "PlaceholderExpression", - "start": 88, - "end": 89, - "loc": { - "start": { - "line": 6, - "column": 3 - }, - "end": { - "line": 6, - "column": 4 - } - } - }, - "right": { - "type": "Identifier", - "start": 90, - "end": 100, - "loc": { - "start": { - "line": 6, - "column": 5 - }, - "end": { - "line": 6, - "column": 15 - }, - "identifierName": "isFunction" - }, - "name": "isFunction" - }, - "arguments": [] - }, - "consequent": { - "type": "ExpressionStatement", - "start": 104, - "end": 116, - "loc": { - "start": { - "line": 6, - "column": 19 - }, - "end": { - "line": 6, - "column": 31 - } - }, - "expression": { - "type": "StringLiteral", - "start": 104, - "end": 116, - "loc": { - "start": { - "line": 6, - "column": 19 - }, - "end": { - "line": 6, - "column": 31 - } - }, - "extra": { - "rawValue": "its a func", - "raw": "'its a func'" - }, - "value": "its a func" - } - } - } - ] - } - ], - "directives": [] - } -} \ No newline at end of file From 8d2be960ca7ec92d7fa8f310e7ad85236176aa36 Mon Sep 17 00:00:00 2001 From: Alex Rattray Date: Thu, 8 Jun 2017 23:15:47 -0700 Subject: [PATCH 11/12] Match discriminant as --- src/plugins/lightscript.js | 10 +- .../lightscript/match/as-parens/actual.js | 2 + .../lightscript/match/as-parens/expected.json | 219 +++++++++ test/fixtures/lightscript/match/as/actual.js | 2 + .../lightscript/match/as/expected.json | 218 +++++++++ .../discriminant-expression-as/actual.js | 3 + .../discriminant-expression-as/expected.json | 424 ++++++++++++++++++ .../match/discriminant-expression/actual.js | 3 + .../discriminant-expression/expected.json | 407 +++++++++++++++++ 9 files changed, 1286 insertions(+), 2 deletions(-) create mode 100644 test/fixtures/lightscript/match/as-parens/actual.js create mode 100644 test/fixtures/lightscript/match/as-parens/expected.json create mode 100644 test/fixtures/lightscript/match/as/actual.js create mode 100644 test/fixtures/lightscript/match/as/expected.json create mode 100644 test/fixtures/lightscript/match/discriminant-expression-as/actual.js create mode 100644 test/fixtures/lightscript/match/discriminant-expression-as/expected.json create mode 100644 test/fixtures/lightscript/match/discriminant-expression/actual.js create mode 100644 test/fixtures/lightscript/match/discriminant-expression/expected.json diff --git a/src/plugins/lightscript.js b/src/plugins/lightscript.js index d55836ebcf..0e1aca9aa8 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."); } }; @@ -561,7 +562,11 @@ pp.parseMatchStatement = function (node) { 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; @@ -673,7 +678,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/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/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 From d309f4f08be1486e1c1cb62d7f5d21903581cfce Mon Sep 17 00:00:00 2001 From: Alex Rattray Date: Fri, 9 Jun 2017 10:50:01 -0700 Subject: [PATCH 12/12] Enforce with before destructuring in match case --- src/plugins/lightscript.js | 21 +- .../match/destructuring-arr/actual.js | 14 +- .../match/destructuring-arr/expected.json | 1624 +++++++++++--- .../destructuring-obj-arr-mixed/actual.js | 2 +- .../destructuring-obj-arr-mixed/expected.json | 163 +- .../match/destructuring-obj-basic/actual.js | 2 +- .../destructuring-obj-basic/expected.json | 105 +- .../match/destructuring-obj-default/actual.js | 2 +- .../destructuring-obj-default/expected.json | 121 +- .../match/destructuring-obj/actual.js | 14 +- .../match/destructuring-obj/expected.json | 1984 +++++++++++++---- .../illegal-destructure-and-with/actual.js | 2 + .../expected.json | 333 +++ .../illegal-destructure-and-with/options.json | 3 - 14 files changed, 3377 insertions(+), 1013 deletions(-) create mode 100644 test/fixtures/lightscript/match/illegal-destructure-and-with/expected.json delete mode 100644 test/fixtures/lightscript/match/illegal-destructure-and-with/options.json diff --git a/src/plugins/lightscript.js b/src/plugins/lightscript.js index 0e1aca9aa8..13b0e39955 100644 --- a/src/plugins/lightscript.js +++ b/src/plugins/lightscript.js @@ -638,28 +638,25 @@ pp.parseMatchCaseTest = function (node) { const elseNode = this.startNode(); this.next(); node.test = this.finishNode(elseNode, "MatchElse"); - } else if (this.match(tt.braceL) || this.match(tt.bracketL)) { - // disambiguate `| { a, b }:` from `| { a, b }~someFn():` - const bindingOrTest = this.parseExprOps(false, { start: 0 }); - try { - node.binding = this.toAssignable(bindingOrTest.__clone(), true, "match test"); - node.test = null; - } catch (_err) { - node.test = bindingOrTest; - } + } else if (this.eat(tt._with)) { + this.parseMatchCaseBinding(node); } else { node.test = this.parseExprOps(); } if (this.eat(tt._with)) { - 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(); + 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) { diff --git a/test/fixtures/lightscript/match/destructuring-arr/actual.js b/test/fixtures/lightscript/match/destructuring-arr/actual.js index 0a68eb814f..18fcad17f3 100644 --- a/test/fixtures/lightscript/match/destructuring-arr/actual.js +++ b/test/fixtures/lightscript/match/destructuring-arr/actual.js @@ -1,9 +1,8 @@ match x: - // | [ a, b ] and a > 1: a + b - | [ a, b ]: a - b - | [ a, b = 2 ]: a + b - 2 - | [ a, ...b ]: b.concat(a) - | [ + | with [ a, b ]: a - b + | with [ a, b = 2 ]: a + b - 2 + | with [ a, ...b ]: b.concat(a) + | with [ [ b d = 'e' @@ -12,3 +11,8 @@ match x: ...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 index f9cd7789f0..4e1f7c5fec 100644 --- a/test/fixtures/lightscript/match/destructuring-arr/expected.json +++ b/test/fixtures/lightscript/match/destructuring-arr/expected.json @@ -1,28 +1,28 @@ { "type": "File", "start": 0, - "end": 228, + "end": 392, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 14, + "line": 18, "column": 28 } }, "program": { "type": "Program", "start": 0, - "end": 228, + "end": 392, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 14, + "line": 18, "column": 28 } }, @@ -31,14 +31,14 @@ { "type": "MatchStatement", "start": 0, - "end": 228, + "end": 392, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 14, + "line": 18, "column": 28 } }, @@ -62,63 +62,62 @@ "cases": [ { "type": "MatchCase", - "start": 44, - "end": 61, + "start": 11, + "end": 33, "loc": { "start": { - "line": 3, + "line": 2, "column": 2 }, "end": { - "line": 3, - "column": 19 + "line": 2, + "column": 24 } }, "binding": { "type": "ArrayPattern", - "start": 46, - "end": 54, + "start": 18, + "end": 26, "loc": { "start": { - "line": 3, - "column": 4 + "line": 2, + "column": 9 }, "end": { - "line": 3, - "column": 12 + "line": 2, + "column": 17 } }, "elements": [ { "type": "Identifier", - "start": 48, - "end": 49, + "start": 20, + "end": 21, "loc": { "start": { - "line": 3, - "column": 6 + "line": 2, + "column": 11 }, "end": { - "line": 3, - "column": 7 + "line": 2, + "column": 12 }, "identifierName": "a" }, - "name": "a", - "leadingComments": null + "name": "a" }, { "type": "Identifier", - "start": 51, - "end": 52, + "start": 23, + "end": 24, "loc": { "start": { - "line": 3, - "column": 9 + "line": 2, + "column": 14 }, "end": { - "line": 3, - "column": 10 + "line": 2, + "column": 15 }, "identifierName": "b" }, @@ -126,47 +125,46 @@ } ] }, - "test": null, "consequent": { "type": "ExpressionStatement", - "start": 56, - "end": 61, + "start": 28, + "end": 33, "loc": { "start": { - "line": 3, - "column": 14 + "line": 2, + "column": 19 }, "end": { - "line": 3, - "column": 19 + "line": 2, + "column": 24 } }, "expression": { "type": "BinaryExpression", - "start": 56, - "end": 61, + "start": 28, + "end": 33, "loc": { "start": { - "line": 3, - "column": 14 + "line": 2, + "column": 19 }, "end": { - "line": 3, - "column": 19 + "line": 2, + "column": 24 } }, "left": { "type": "Identifier", - "start": 56, - "end": 57, + "start": 28, + "end": 29, "loc": { "start": { - "line": 3, - "column": 14 + "line": 2, + "column": 19 }, "end": { - "line": 3, - "column": 15 + "line": 2, + "column": 20 }, "identifierName": "a" }, @@ -175,83 +173,65 @@ "operator": "-", "right": { "type": "Identifier", - "start": 60, - "end": 61, + "start": 32, + "end": 33, "loc": { "start": { - "line": 3, - "column": 18 + "line": 2, + "column": 23 }, "end": { - "line": 3, - "column": 19 + "line": 2, + "column": 24 }, "identifierName": "b" }, "name": "b" } } - }, - "leadingComments": [ - { - "type": "CommentLine", - "value": " | [ a, b ] and a > 1: a + b", - "start": 11, - "end": 41, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 32 - } - } - } - ] + } }, { "type": "MatchCase", - "start": 64, - "end": 89, + "start": 36, + "end": 66, "loc": { "start": { - "line": 4, + "line": 3, "column": 2 }, "end": { - "line": 4, - "column": 27 + "line": 3, + "column": 32 } }, "binding": { "type": "ArrayPattern", - "start": 66, - "end": 78, + "start": 43, + "end": 55, "loc": { "start": { - "line": 4, - "column": 4 + "line": 3, + "column": 9 }, "end": { - "line": 4, - "column": 16 + "line": 3, + "column": 21 } }, "elements": [ { "type": "Identifier", - "start": 68, - "end": 69, + "start": 45, + "end": 46, "loc": { "start": { - "line": 4, - "column": 6 + "line": 3, + "column": 11 }, "end": { - "line": 4, - "column": 7 + "line": 3, + "column": 12 }, "identifierName": "a" }, @@ -259,30 +239,30 @@ }, { "type": "AssignmentPattern", - "start": 71, - "end": 76, + "start": 48, + "end": 53, "loc": { "start": { - "line": 4, - "column": 9 + "line": 3, + "column": 14 }, "end": { - "line": 4, - "column": 14 + "line": 3, + "column": 19 } }, "left": { "type": "Identifier", - "start": 71, - "end": 72, + "start": 48, + "end": 49, "loc": { "start": { - "line": 4, - "column": 9 + "line": 3, + "column": 14 }, "end": { - "line": 4, - "column": 10 + "line": 3, + "column": 15 }, "identifierName": "b" }, @@ -290,16 +270,16 @@ }, "right": { "type": "NumericLiteral", - "start": 75, - "end": 76, + "start": 52, + "end": 53, "loc": { "start": { - "line": 4, - "column": 13 + "line": 3, + "column": 18 }, "end": { - "line": 4, - "column": 14 + "line": 3, + "column": 19 } }, "extra": { @@ -307,66 +287,64 @@ "raw": "2" }, "value": 2 - }, - "isNowAssign": false + } } ] }, - "test": null, "consequent": { "type": "ExpressionStatement", - "start": 80, - "end": 89, + "start": 57, + "end": 66, "loc": { "start": { - "line": 4, - "column": 18 + "line": 3, + "column": 23 }, "end": { - "line": 4, - "column": 27 + "line": 3, + "column": 32 } }, "expression": { "type": "BinaryExpression", - "start": 80, - "end": 89, + "start": 57, + "end": 66, "loc": { "start": { - "line": 4, - "column": 18 + "line": 3, + "column": 23 }, "end": { - "line": 4, - "column": 27 + "line": 3, + "column": 32 } }, "left": { "type": "BinaryExpression", - "start": 80, - "end": 85, + "start": 57, + "end": 62, "loc": { "start": { - "line": 4, - "column": 18 + "line": 3, + "column": 23 }, "end": { - "line": 4, - "column": 23 + "line": 3, + "column": 28 } }, "left": { "type": "Identifier", - "start": 80, - "end": 81, + "start": 57, + "end": 58, "loc": { "start": { - "line": 4, - "column": 18 + "line": 3, + "column": 23 }, "end": { - "line": 4, - "column": 19 + "line": 3, + "column": 24 }, "identifierName": "a" }, @@ -375,16 +353,16 @@ "operator": "+", "right": { "type": "Identifier", - "start": 84, - "end": 85, + "start": 61, + "end": 62, "loc": { "start": { - "line": 4, - "column": 22 + "line": 3, + "column": 27 }, "end": { - "line": 4, - "column": 23 + "line": 3, + "column": 28 }, "identifierName": "b" }, @@ -394,16 +372,16 @@ "operator": "-", "right": { "type": "NumericLiteral", - "start": 88, - "end": 89, + "start": 65, + "end": 66, "loc": { "start": { - "line": 4, - "column": 26 + "line": 3, + "column": 31 }, "end": { - "line": 4, - "column": 27 + "line": 3, + "column": 32 } }, "extra": { @@ -417,45 +395,45 @@ }, { "type": "MatchCase", - "start": 92, - "end": 118, + "start": 69, + "end": 100, "loc": { "start": { - "line": 5, + "line": 4, "column": 2 }, "end": { - "line": 5, - "column": 28 + "line": 4, + "column": 33 } }, "binding": { "type": "ArrayPattern", - "start": 94, - "end": 105, + "start": 76, + "end": 87, "loc": { "start": { - "line": 5, - "column": 4 + "line": 4, + "column": 9 }, "end": { - "line": 5, - "column": 15 + "line": 4, + "column": 20 } }, "elements": [ { "type": "Identifier", - "start": 96, - "end": 97, + "start": 78, + "end": 79, "loc": { "start": { - "line": 5, - "column": 6 + "line": 4, + "column": 11 }, "end": { - "line": 5, - "column": 7 + "line": 4, + "column": 12 }, "identifierName": "a" }, @@ -463,30 +441,30 @@ }, { "type": "RestElement", - "start": 99, - "end": 103, + "start": 81, + "end": 85, "loc": { "start": { - "line": 5, - "column": 9 + "line": 4, + "column": 14 }, "end": { - "line": 5, - "column": 13 + "line": 4, + "column": 18 } }, "argument": { "type": "Identifier", - "start": 102, - "end": 103, + "start": 84, + "end": 85, "loc": { "start": { - "line": 5, - "column": 12 + "line": 4, + "column": 17 }, "end": { - "line": 5, - "column": 13 + "line": 4, + "column": 18 }, "identifierName": "b" }, @@ -495,61 +473,60 @@ } ] }, - "test": null, "consequent": { "type": "ExpressionStatement", - "start": 107, - "end": 118, + "start": 89, + "end": 100, "loc": { "start": { - "line": 5, - "column": 17 + "line": 4, + "column": 22 }, "end": { - "line": 5, - "column": 28 + "line": 4, + "column": 33 } }, "expression": { "type": "CallExpression", - "start": 107, - "end": 118, + "start": 89, + "end": 100, "loc": { "start": { - "line": 5, - "column": 17 + "line": 4, + "column": 22 }, "end": { - "line": 5, - "column": 28 + "line": 4, + "column": 33 } }, "callee": { "type": "MemberExpression", - "start": 107, - "end": 115, + "start": 89, + "end": 97, "loc": { "start": { - "line": 5, - "column": 17 + "line": 4, + "column": 22 }, "end": { - "line": 5, - "column": 25 + "line": 4, + "column": 30 } }, "object": { "type": "Identifier", - "start": 107, - "end": 108, + "start": 89, + "end": 90, "loc": { "start": { - "line": 5, - "column": 17 + "line": 4, + "column": 22 }, "end": { - "line": 5, - "column": 18 + "line": 4, + "column": 23 }, "identifierName": "b" }, @@ -557,16 +534,16 @@ }, "property": { "type": "Identifier", - "start": 109, - "end": 115, + "start": 91, + "end": 97, "loc": { "start": { - "line": 5, - "column": 19 + "line": 4, + "column": 24 }, "end": { - "line": 5, - "column": 25 + "line": 4, + "column": 30 }, "identifierName": "concat" }, @@ -577,16 +554,16 @@ "arguments": [ { "type": "Identifier", - "start": 116, - "end": 117, + "start": 98, + "end": 99, "loc": { "start": { - "line": 5, - "column": 26 + "line": 4, + "column": 31 }, "end": { - "line": 5, - "column": 27 + "line": 4, + "column": 32 }, "identifierName": "a" }, @@ -598,59 +575,59 @@ }, { "type": "MatchCase", - "start": 121, - "end": 228, + "start": 103, + "end": 215, "loc": { "start": { - "line": 6, + "line": 5, "column": 2 }, "end": { - "line": 14, + "line": 13, "column": 28 } }, "binding": { "type": "ArrayPattern", - "start": 123, - "end": 198, + "start": 110, + "end": 185, "loc": { "start": { - "line": 6, - "column": 4 + "line": 5, + "column": 9 }, "end": { - "line": 13, + "line": 12, "column": 3 } }, "elements": [ { "type": "ArrayPattern", - "start": 131, - "end": 166, + "start": 118, + "end": 153, "loc": { "start": { - "line": 7, + "line": 6, "column": 6 }, "end": { - "line": 10, + "line": 9, "column": 7 } }, "elements": [ { "type": "Identifier", - "start": 141, - "end": 142, + "start": 128, + "end": 129, "loc": { "start": { - "line": 8, + "line": 7, "column": 8 }, "end": { - "line": 8, + "line": 7, "column": 9 }, "identifierName": "b" @@ -659,29 +636,29 @@ }, { "type": "AssignmentPattern", - "start": 151, - "end": 158, + "start": 138, + "end": 145, "loc": { "start": { - "line": 9, + "line": 8, "column": 8 }, "end": { - "line": 9, + "line": 8, "column": 15 } }, "left": { "type": "Identifier", - "start": 151, - "end": 152, + "start": 138, + "end": 139, "loc": { "start": { - "line": 9, + "line": 8, "column": 8 }, "end": { - "line": 9, + "line": 8, "column": 9 }, "identifierName": "d" @@ -690,15 +667,15 @@ }, "right": { "type": "StringLiteral", - "start": 155, - "end": 158, + "start": 142, + "end": 145, "loc": { "start": { - "line": 9, + "line": 8, "column": 12 }, "end": { - "line": 9, + "line": 8, "column": 15 } }, @@ -707,37 +684,36 @@ "raw": "'e'" }, "value": "e" - }, - "isNowAssign": false + } } ] }, { "type": "ArrayPattern", - "start": 173, - "end": 183, + "start": 160, + "end": 170, "loc": { "start": { - "line": 11, + "line": 10, "column": 6 }, "end": { - "line": 11, + "line": 10, "column": 16 } }, "elements": [ { "type": "Identifier", - "start": 175, - "end": 176, + "start": 162, + "end": 163, "loc": { "start": { - "line": 11, + "line": 10, "column": 8 }, "end": { - "line": 11, + "line": 10, "column": 9 }, "identifierName": "g" @@ -747,15 +723,15 @@ null, { "type": "Identifier", - "start": 180, - "end": 181, + "start": 167, + "end": 168, "loc": { "start": { - "line": 11, + "line": 10, "column": 13 }, "end": { - "line": 11, + "line": 10, "column": 14 }, "identifierName": "h" @@ -766,29 +742,29 @@ }, { "type": "RestElement", - "start": 190, - "end": 194, + "start": 177, + "end": 181, "loc": { "start": { - "line": 12, + "line": 11, "column": 6 }, "end": { - "line": 12, + "line": 11, "column": 10 } }, "argument": { "type": "Identifier", - "start": 193, - "end": 194, + "start": 180, + "end": 181, "loc": { "start": { - "line": 12, + "line": 11, "column": 9 }, "end": { - "line": 12, + "line": 11, "column": 10 }, "identifierName": "j" @@ -798,90 +774,89 @@ } ] }, - "test": null, "consequent": { "type": "BlockStatement", - "start": 198, - "end": 228, + "start": 185, + "end": 215, "loc": { "start": { - "line": 13, + "line": 12, "column": 3 }, "end": { - "line": 14, + "line": 13, "column": 28 } }, "body": [ { "type": "ExpressionStatement", - "start": 204, - "end": 228, + "start": 191, + "end": 215, "loc": { "start": { - "line": 14, + "line": 13, "column": 4 }, "end": { - "line": 14, + "line": 13, "column": 28 } }, "expression": { "type": "CallExpression", - "start": 204, - "end": 228, + "start": 191, + "end": 215, "loc": { "start": { - "line": 14, + "line": 13, "column": 4 }, "end": { - "line": 14, + "line": 13, "column": 28 } }, "callee": { "type": "MemberExpression", - "start": 204, - "end": 224, + "start": 191, + "end": 211, "loc": { "start": { - "line": 14, + "line": 13, "column": 4 }, "end": { - "line": 14, + "line": 13, "column": 24 } }, "object": { "type": "ArrayExpression", - "start": 204, - "end": 219, + "start": 191, + "end": 206, "loc": { "start": { - "line": 14, + "line": 13, "column": 4 }, "end": { - "line": 14, + "line": 13, "column": 19 } }, "elements": [ { "type": "Identifier", - "start": 205, - "end": 206, + "start": 192, + "end": 193, "loc": { "start": { - "line": 14, + "line": 13, "column": 5 }, "end": { - "line": 14, + "line": 13, "column": 6 }, "identifierName": "b" @@ -890,15 +865,15 @@ }, { "type": "Identifier", - "start": 208, - "end": 209, + "start": 195, + "end": 196, "loc": { "start": { - "line": 14, + "line": 13, "column": 8 }, "end": { - "line": 14, + "line": 13, "column": 9 }, "identifierName": "d" @@ -907,15 +882,15 @@ }, { "type": "Identifier", - "start": 211, - "end": 212, + "start": 198, + "end": 199, "loc": { "start": { - "line": 14, + "line": 13, "column": 11 }, "end": { - "line": 14, + "line": 13, "column": 12 }, "identifierName": "g" @@ -924,29 +899,29 @@ }, { "type": "SpreadElement", - "start": 214, - "end": 218, + "start": 201, + "end": 205, "loc": { "start": { - "line": 14, + "line": 13, "column": 14 }, "end": { - "line": 14, + "line": 13, "column": 18 } }, "argument": { "type": "Identifier", - "start": 217, - "end": 218, + "start": 204, + "end": 205, "loc": { "start": { - "line": 14, + "line": 13, "column": 17 }, "end": { - "line": 14, + "line": 13, "column": 18 }, "identifierName": "j" @@ -958,15 +933,15 @@ }, "property": { "type": "Identifier", - "start": 220, - "end": 224, + "start": 207, + "end": 211, "loc": { "start": { - "line": 14, + "line": 13, "column": 20 }, "end": { - "line": 14, + "line": 13, "column": 24 }, "identifierName": "join" @@ -978,15 +953,15 @@ "arguments": [ { "type": "StringLiteral", - "start": 225, - "end": 227, + "start": 212, + "end": 214, "loc": { "start": { - "line": 14, + "line": 13, "column": 25 }, "end": { - "line": 14, + "line": 13, "column": 27 } }, @@ -1005,28 +980,999 @@ "curly": false } } - } - ] - } - ], - "directives": [] - }, - "comments": [ - { - "type": "CommentLine", - "value": " | [ a, b ] and a > 1: a + b", - "start": 11, - "end": 41, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 32 - } - } - } - ] + }, + { + "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 index 6ad3c916fc..83fc1aec6e 100644 --- a/test/fixtures/lightscript/match/destructuring-obj-arr-mixed/actual.js +++ b/test/fixtures/lightscript/match/destructuring-obj-arr-mixed/actual.js @@ -1,5 +1,5 @@ match x: - | { + | with { a: [ b { diff --git a/test/fixtures/lightscript/match/destructuring-obj-arr-mixed/expected.json b/test/fixtures/lightscript/match/destructuring-obj-arr-mixed/expected.json index 34f7a8aca8..8cff8e545d 100644 --- a/test/fixtures/lightscript/match/destructuring-obj-arr-mixed/expected.json +++ b/test/fixtures/lightscript/match/destructuring-obj-arr-mixed/expected.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 159, + "end": 164, "loc": { "start": { "line": 1, @@ -15,7 +15,7 @@ "program": { "type": "Program", "start": 0, - "end": 159, + "end": 164, "loc": { "start": { "line": 1, @@ -31,7 +31,7 @@ { "type": "MatchStatement", "start": 0, - "end": 159, + "end": 164, "loc": { "start": { "line": 1, @@ -63,7 +63,7 @@ { "type": "MatchCase", "start": 11, - "end": 159, + "end": 164, "loc": { "start": { "line": 2, @@ -76,12 +76,12 @@ }, "binding": { "type": "ObjectPattern", - "start": 13, - "end": 123, + "start": 18, + "end": 128, "loc": { "start": { "line": 2, - "column": 4 + "column": 9 }, "end": { "line": 14, @@ -91,8 +91,8 @@ "properties": [ { "type": "ObjectProperty", - "start": 19, - "end": 98, + "start": 24, + "end": 103, "loc": { "start": { "line": 3, @@ -108,8 +108,8 @@ "computed": false, "key": { "type": "Identifier", - "start": 19, - "end": 20, + "start": 24, + "end": 25, "loc": { "start": { "line": 3, @@ -125,8 +125,8 @@ }, "value": { "type": "ArrayPattern", - "start": 22, - "end": 98, + "start": 27, + "end": 103, "loc": { "start": { "line": 3, @@ -140,8 +140,8 @@ "elements": [ { "type": "Identifier", - "start": 30, - "end": 31, + "start": 35, + "end": 36, "loc": { "start": { "line": 4, @@ -157,8 +157,8 @@ }, { "type": "ObjectPattern", - "start": 38, - "end": 84, + "start": 43, + "end": 89, "loc": { "start": { "line": 5, @@ -172,8 +172,8 @@ "properties": [ { "type": "ObjectProperty", - "start": 48, - "end": 49, + "start": 53, + "end": 54, "loc": { "start": { "line": 6, @@ -189,8 +189,8 @@ "computed": false, "key": { "type": "Identifier", - "start": 48, - "end": 49, + "start": 53, + "end": 54, "loc": { "start": { "line": 6, @@ -206,8 +206,8 @@ }, "value": { "type": "Identifier", - "start": 48, - "end": 49, + "start": 53, + "end": 54, "loc": { "start": { "line": 6, @@ -227,8 +227,8 @@ }, { "type": "ObjectProperty", - "start": 58, - "end": 63, + "start": 63, + "end": 68, "loc": { "start": { "line": 7, @@ -244,8 +244,8 @@ "computed": false, "key": { "type": "Identifier", - "start": 58, - "end": 59, + "start": 63, + "end": 64, "loc": { "start": { "line": 7, @@ -261,8 +261,8 @@ }, "value": { "type": "AssignmentPattern", - "start": 58, - "end": 63, + "start": 63, + "end": 68, "loc": { "start": { "line": 7, @@ -275,8 +275,8 @@ }, "left": { "type": "Identifier", - "start": 58, - "end": 59, + "start": 63, + "end": 64, "loc": { "start": { "line": 7, @@ -292,8 +292,8 @@ }, "right": { "type": "NumericLiteral", - "start": 62, - "end": 63, + "start": 67, + "end": 68, "loc": { "start": { "line": 7, @@ -317,8 +317,8 @@ }, { "type": "RestProperty", - "start": 72, - "end": 76, + "start": 77, + "end": 81, "loc": { "start": { "line": 8, @@ -331,8 +331,8 @@ }, "argument": { "type": "Identifier", - "start": 75, - "end": 76, + "start": 80, + "end": 81, "loc": { "start": { "line": 8, @@ -351,8 +351,8 @@ }, { "type": "Identifier", - "start": 91, - "end": 92, + "start": 96, + "end": 97, "loc": { "start": { "line": 10, @@ -371,8 +371,8 @@ }, { "type": "ObjectProperty", - "start": 103, - "end": 110, + "start": 108, + "end": 115, "loc": { "start": { "line": 12, @@ -388,8 +388,8 @@ "computed": false, "key": { "type": "Identifier", - "start": 103, - "end": 104, + "start": 108, + "end": 109, "loc": { "start": { "line": 12, @@ -405,8 +405,8 @@ }, "value": { "type": "AssignmentPattern", - "start": 103, - "end": 110, + "start": 108, + "end": 115, "loc": { "start": { "line": 12, @@ -419,8 +419,8 @@ }, "left": { "type": "Identifier", - "start": 103, - "end": 104, + "start": 108, + "end": 109, "loc": { "start": { "line": 12, @@ -436,8 +436,8 @@ }, "right": { "type": "StringLiteral", - "start": 107, - "end": 110, + "start": 112, + "end": 115, "loc": { "start": { "line": 12, @@ -461,8 +461,8 @@ }, { "type": "RestProperty", - "start": 115, - "end": 119, + "start": 120, + "end": 124, "loc": { "start": { "line": 13, @@ -475,8 +475,8 @@ }, "argument": { "type": "Identifier", - "start": 118, - "end": 119, + "start": 123, + "end": 124, "loc": { "start": { "line": 13, @@ -493,11 +493,10 @@ } ] }, - "test": null, "consequent": { "type": "BlockStatement", - "start": 123, - "end": 159, + "start": 128, + "end": 164, "loc": { "start": { "line": 14, @@ -511,8 +510,8 @@ "body": [ { "type": "ExpressionStatement", - "start": 129, - "end": 159, + "start": 134, + "end": 164, "loc": { "start": { "line": 15, @@ -525,8 +524,8 @@ }, "expression": { "type": "CallExpression", - "start": 129, - "end": 159, + "start": 134, + "end": 164, "loc": { "start": { "line": 15, @@ -539,8 +538,8 @@ }, "callee": { "type": "MemberExpression", - "start": 129, - "end": 155, + "start": 134, + "end": 160, "loc": { "start": { "line": 15, @@ -553,8 +552,8 @@ }, "object": { "type": "ArrayExpression", - "start": 129, - "end": 150, + "start": 134, + "end": 155, "loc": { "start": { "line": 15, @@ -568,8 +567,8 @@ "elements": [ { "type": "Identifier", - "start": 130, - "end": 131, + "start": 135, + "end": 136, "loc": { "start": { "line": 15, @@ -585,8 +584,8 @@ }, { "type": "Identifier", - "start": 133, - "end": 134, + "start": 138, + "end": 139, "loc": { "start": { "line": 15, @@ -602,8 +601,8 @@ }, { "type": "SpreadElement", - "start": 136, - "end": 140, + "start": 141, + "end": 145, "loc": { "start": { "line": 15, @@ -616,8 +615,8 @@ }, "argument": { "type": "Identifier", - "start": 139, - "end": 140, + "start": 144, + "end": 145, "loc": { "start": { "line": 15, @@ -634,8 +633,8 @@ }, { "type": "Identifier", - "start": 142, - "end": 143, + "start": 147, + "end": 148, "loc": { "start": { "line": 15, @@ -651,8 +650,8 @@ }, { "type": "Identifier", - "start": 145, - "end": 146, + "start": 150, + "end": 151, "loc": { "start": { "line": 15, @@ -668,8 +667,8 @@ }, { "type": "Identifier", - "start": 148, - "end": 149, + "start": 153, + "end": 154, "loc": { "start": { "line": 15, @@ -687,8 +686,8 @@ }, "property": { "type": "Identifier", - "start": 151, - "end": 155, + "start": 156, + "end": 160, "loc": { "start": { "line": 15, @@ -707,8 +706,8 @@ "arguments": [ { "type": "StringLiteral", - "start": 156, - "end": 158, + "start": 161, + "end": 163, "loc": { "start": { "line": 15, diff --git a/test/fixtures/lightscript/match/destructuring-obj-basic/actual.js b/test/fixtures/lightscript/match/destructuring-obj-basic/actual.js index d104c9c720..c6b4045abc 100644 --- a/test/fixtures/lightscript/match/destructuring-obj-basic/actual.js +++ b/test/fixtures/lightscript/match/destructuring-obj-basic/actual.js @@ -1,2 +1,2 @@ match x: - | { a, b }: a - b + | 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 index 077c99b19f..f9dac0c614 100644 --- a/test/fixtures/lightscript/match/destructuring-obj-basic/expected.json +++ b/test/fixtures/lightscript/match/destructuring-obj-basic/expected.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 28, + "end": 33, "loc": { "start": { "line": 1, @@ -9,13 +9,13 @@ }, "end": { "line": 2, - "column": 19 + "column": 24 } }, "program": { "type": "Program", "start": 0, - "end": 28, + "end": 33, "loc": { "start": { "line": 1, @@ -23,7 +23,7 @@ }, "end": { "line": 2, - "column": 19 + "column": 24 } }, "sourceType": "script", @@ -31,7 +31,7 @@ { "type": "MatchStatement", "start": 0, - "end": 28, + "end": 33, "loc": { "start": { "line": 1, @@ -39,7 +39,7 @@ }, "end": { "line": 2, - "column": 19 + "column": 24 } }, "discriminant": { @@ -63,7 +63,7 @@ { "type": "MatchCase", "start": 11, - "end": 28, + "end": 33, "loc": { "start": { "line": 2, @@ -71,36 +71,36 @@ }, "end": { "line": 2, - "column": 19 + "column": 24 } }, "binding": { "type": "ObjectPattern", - "start": 13, - "end": 21, + "start": 18, + "end": 26, "loc": { "start": { "line": 2, - "column": 4 + "column": 9 }, "end": { "line": 2, - "column": 12 + "column": 17 } }, "properties": [ { "type": "ObjectProperty", - "start": 15, - "end": 16, + "start": 20, + "end": 21, "loc": { "start": { "line": 2, - "column": 6 + "column": 11 }, "end": { "line": 2, - "column": 7 + "column": 12 } }, "method": false, @@ -108,16 +108,16 @@ "computed": false, "key": { "type": "Identifier", - "start": 15, - "end": 16, + "start": 20, + "end": 21, "loc": { "start": { "line": 2, - "column": 6 + "column": 11 }, "end": { "line": 2, - "column": 7 + "column": 12 }, "identifierName": "a" }, @@ -125,16 +125,16 @@ }, "value": { "type": "Identifier", - "start": 15, - "end": 16, + "start": 20, + "end": 21, "loc": { "start": { "line": 2, - "column": 6 + "column": 11 }, "end": { "line": 2, - "column": 7 + "column": 12 }, "identifierName": "a" }, @@ -146,16 +146,16 @@ }, { "type": "ObjectProperty", - "start": 18, - "end": 19, + "start": 23, + "end": 24, "loc": { "start": { "line": 2, - "column": 9 + "column": 14 }, "end": { "line": 2, - "column": 10 + "column": 15 } }, "method": false, @@ -163,16 +163,16 @@ "computed": false, "key": { "type": "Identifier", - "start": 18, - "end": 19, + "start": 23, + "end": 24, "loc": { "start": { "line": 2, - "column": 9 + "column": 14 }, "end": { "line": 2, - "column": 10 + "column": 15 }, "identifierName": "b" }, @@ -180,16 +180,16 @@ }, "value": { "type": "Identifier", - "start": 18, - "end": 19, + "start": 23, + "end": 24, "loc": { "start": { "line": 2, - "column": 9 + "column": 14 }, "end": { "line": 2, - "column": 10 + "column": 15 }, "identifierName": "b" }, @@ -201,47 +201,46 @@ } ] }, - "test": null, "consequent": { "type": "ExpressionStatement", - "start": 23, - "end": 28, + "start": 28, + "end": 33, "loc": { "start": { "line": 2, - "column": 14 + "column": 19 }, "end": { "line": 2, - "column": 19 + "column": 24 } }, "expression": { "type": "BinaryExpression", - "start": 23, - "end": 28, + "start": 28, + "end": 33, "loc": { "start": { "line": 2, - "column": 14 + "column": 19 }, "end": { "line": 2, - "column": 19 + "column": 24 } }, "left": { "type": "Identifier", - "start": 23, - "end": 24, + "start": 28, + "end": 29, "loc": { "start": { "line": 2, - "column": 14 + "column": 19 }, "end": { "line": 2, - "column": 15 + "column": 20 }, "identifierName": "a" }, @@ -250,16 +249,16 @@ "operator": "-", "right": { "type": "Identifier", - "start": 27, - "end": 28, + "start": 32, + "end": 33, "loc": { "start": { "line": 2, - "column": 18 + "column": 23 }, "end": { "line": 2, - "column": 19 + "column": 24 }, "identifierName": "b" }, diff --git a/test/fixtures/lightscript/match/destructuring-obj-default/actual.js b/test/fixtures/lightscript/match/destructuring-obj-default/actual.js index 827ab53733..e616f09a14 100644 --- a/test/fixtures/lightscript/match/destructuring-obj-default/actual.js +++ b/test/fixtures/lightscript/match/destructuring-obj-default/actual.js @@ -1,2 +1,2 @@ match x: - | { a, b = 1 }: a - b + | 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 index 1a4f3fa73d..e4cc9026a8 100644 --- a/test/fixtures/lightscript/match/destructuring-obj-default/expected.json +++ b/test/fixtures/lightscript/match/destructuring-obj-default/expected.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 32, + "end": 37, "loc": { "start": { "line": 1, @@ -9,13 +9,13 @@ }, "end": { "line": 2, - "column": 23 + "column": 28 } }, "program": { "type": "Program", "start": 0, - "end": 32, + "end": 37, "loc": { "start": { "line": 1, @@ -23,7 +23,7 @@ }, "end": { "line": 2, - "column": 23 + "column": 28 } }, "sourceType": "script", @@ -31,7 +31,7 @@ { "type": "MatchStatement", "start": 0, - "end": 32, + "end": 37, "loc": { "start": { "line": 1, @@ -39,7 +39,7 @@ }, "end": { "line": 2, - "column": 23 + "column": 28 } }, "discriminant": { @@ -63,7 +63,7 @@ { "type": "MatchCase", "start": 11, - "end": 32, + "end": 37, "loc": { "start": { "line": 2, @@ -71,36 +71,36 @@ }, "end": { "line": 2, - "column": 23 + "column": 28 } }, "binding": { "type": "ObjectPattern", - "start": 13, - "end": 25, + "start": 18, + "end": 30, "loc": { "start": { "line": 2, - "column": 4 + "column": 9 }, "end": { "line": 2, - "column": 16 + "column": 21 } }, "properties": [ { "type": "ObjectProperty", - "start": 15, - "end": 16, + "start": 20, + "end": 21, "loc": { "start": { "line": 2, - "column": 6 + "column": 11 }, "end": { "line": 2, - "column": 7 + "column": 12 } }, "method": false, @@ -108,16 +108,16 @@ "computed": false, "key": { "type": "Identifier", - "start": 15, - "end": 16, + "start": 20, + "end": 21, "loc": { "start": { "line": 2, - "column": 6 + "column": 11 }, "end": { "line": 2, - "column": 7 + "column": 12 }, "identifierName": "a" }, @@ -125,16 +125,16 @@ }, "value": { "type": "Identifier", - "start": 15, - "end": 16, + "start": 20, + "end": 21, "loc": { "start": { "line": 2, - "column": 6 + "column": 11 }, "end": { "line": 2, - "column": 7 + "column": 12 }, "identifierName": "a" }, @@ -146,16 +146,16 @@ }, { "type": "ObjectProperty", - "start": 18, - "end": 23, + "start": 23, + "end": 28, "loc": { "start": { "line": 2, - "column": 9 + "column": 14 }, "end": { "line": 2, - "column": 14 + "column": 19 } }, "method": false, @@ -163,16 +163,16 @@ "computed": false, "key": { "type": "Identifier", - "start": 18, - "end": 19, + "start": 23, + "end": 24, "loc": { "start": { "line": 2, - "column": 9 + "column": 14 }, "end": { "line": 2, - "column": 10 + "column": 15 }, "identifierName": "b" }, @@ -180,30 +180,30 @@ }, "value": { "type": "AssignmentPattern", - "start": 18, - "end": 23, + "start": 23, + "end": 28, "loc": { "start": { "line": 2, - "column": 9 + "column": 14 }, "end": { "line": 2, - "column": 14 + "column": 19 } }, "left": { "type": "Identifier", - "start": 18, - "end": 19, + "start": 23, + "end": 24, "loc": { "start": { "line": 2, - "column": 9 + "column": 14 }, "end": { "line": 2, - "column": 10 + "column": 15 }, "identifierName": "b" }, @@ -211,16 +211,16 @@ }, "right": { "type": "NumericLiteral", - "start": 22, - "end": 23, + "start": 27, + "end": 28, "loc": { "start": { "line": 2, - "column": 13 + "column": 18 }, "end": { "line": 2, - "column": 14 + "column": 19 } }, "extra": { @@ -236,47 +236,46 @@ } ] }, - "test": null, "consequent": { "type": "ExpressionStatement", - "start": 27, - "end": 32, + "start": 32, + "end": 37, "loc": { "start": { "line": 2, - "column": 18 + "column": 23 }, "end": { "line": 2, - "column": 23 + "column": 28 } }, "expression": { "type": "BinaryExpression", - "start": 27, - "end": 32, + "start": 32, + "end": 37, "loc": { "start": { "line": 2, - "column": 18 + "column": 23 }, "end": { "line": 2, - "column": 23 + "column": 28 } }, "left": { "type": "Identifier", - "start": 27, - "end": 28, + "start": 32, + "end": 33, "loc": { "start": { "line": 2, - "column": 18 + "column": 23 }, "end": { "line": 2, - "column": 19 + "column": 24 }, "identifierName": "a" }, @@ -285,16 +284,16 @@ "operator": "-", "right": { "type": "Identifier", - "start": 31, - "end": 32, + "start": 36, + "end": 37, "loc": { "start": { "line": 2, - "column": 22 + "column": 27 }, "end": { "line": 2, - "column": 23 + "column": 28 }, "identifierName": "b" }, diff --git a/test/fixtures/lightscript/match/destructuring-obj/actual.js b/test/fixtures/lightscript/match/destructuring-obj/actual.js index e11f36d8bb..c629316e56 100644 --- a/test/fixtures/lightscript/match/destructuring-obj/actual.js +++ b/test/fixtures/lightscript/match/destructuring-obj/actual.js @@ -1,8 +1,8 @@ match x: - | foo with { a, b }: a + b - | { a, b }: a - b - | { a, b = 2 }: a + b - 2 - | { + | with { a, b }: a - b + | with { a, b = 2 }: a + b - 2 + | with { a, ...c }: [a, b, c].join('') + | with { a: { b d = 'e' @@ -10,4 +10,8 @@ match x: f: { ...g } }: [b, d, g].join('') - | { a, ...c }: [a, b, c].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 index fb229a4341..021ab4f148 100644 --- a/test/fixtures/lightscript/match/destructuring-obj/expected.json +++ b/test/fixtures/lightscript/match/destructuring-obj/expected.json @@ -1,29 +1,29 @@ { "type": "File", "start": 0, - "end": 208, + "end": 374, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 13, - "column": 35 + "line": 17, + "column": 22 } }, "program": { "type": "Program", "start": 0, - "end": 208, + "end": 374, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 13, - "column": 35 + "line": 17, + "column": 22 } }, "sourceType": "script", @@ -31,15 +31,15 @@ { "type": "MatchStatement", "start": 0, - "end": 208, + "end": 374, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 13, - "column": 35 + "line": 17, + "column": 22 } }, "discriminant": { @@ -63,7 +63,7 @@ { "type": "MatchCase", "start": 11, - "end": 37, + "end": 33, "loc": { "start": { "line": 2, @@ -71,53 +71,36 @@ }, "end": { "line": 2, - "column": 28 + "column": 24 } }, - "test": { - "type": "Identifier", - "start": 13, - "end": 16, - "loc": { - "start": { - "line": 2, - "column": 4 - }, - "end": { - "line": 2, - "column": 7 - }, - "identifierName": "foo" - }, - "name": "foo" - }, "binding": { "type": "ObjectPattern", - "start": 22, - "end": 30, + "start": 18, + "end": 26, "loc": { "start": { "line": 2, - "column": 13 + "column": 9 }, "end": { "line": 2, - "column": 21 + "column": 17 } }, "properties": [ { "type": "ObjectProperty", - "start": 24, - "end": 25, + "start": 20, + "end": 21, "loc": { "start": { "line": 2, - "column": 15 + "column": 11 }, "end": { "line": 2, - "column": 16 + "column": 12 } }, "method": false, @@ -125,16 +108,16 @@ "computed": false, "key": { "type": "Identifier", - "start": 24, - "end": 25, + "start": 20, + "end": 21, "loc": { "start": { "line": 2, - "column": 15 + "column": 11 }, "end": { "line": 2, - "column": 16 + "column": 12 }, "identifierName": "a" }, @@ -142,16 +125,16 @@ }, "value": { "type": "Identifier", - "start": 24, - "end": 25, + "start": 20, + "end": 21, "loc": { "start": { "line": 2, - "column": 15 + "column": 11 }, "end": { "line": 2, - "column": 16 + "column": 12 }, "identifierName": "a" }, @@ -163,16 +146,16 @@ }, { "type": "ObjectProperty", - "start": 27, - "end": 28, + "start": 23, + "end": 24, "loc": { "start": { "line": 2, - "column": 18 + "column": 14 }, "end": { "line": 2, - "column": 19 + "column": 15 } }, "method": false, @@ -180,16 +163,16 @@ "computed": false, "key": { "type": "Identifier", - "start": 27, - "end": 28, + "start": 23, + "end": 24, "loc": { "start": { "line": 2, - "column": 18 + "column": 14 }, "end": { "line": 2, - "column": 19 + "column": 15 }, "identifierName": "b" }, @@ -197,16 +180,16 @@ }, "value": { "type": "Identifier", - "start": 27, - "end": 28, + "start": 23, + "end": 24, "loc": { "start": { "line": 2, - "column": 18 + "column": 14 }, "end": { "line": 2, - "column": 19 + "column": 15 }, "identifierName": "b" }, @@ -220,62 +203,62 @@ }, "consequent": { "type": "ExpressionStatement", - "start": 32, - "end": 37, + "start": 28, + "end": 33, "loc": { "start": { "line": 2, - "column": 23 + "column": 19 }, "end": { "line": 2, - "column": 28 + "column": 24 } }, "expression": { "type": "BinaryExpression", - "start": 32, - "end": 37, + "start": 28, + "end": 33, "loc": { "start": { "line": 2, - "column": 23 + "column": 19 }, "end": { "line": 2, - "column": 28 + "column": 24 } }, "left": { "type": "Identifier", - "start": 32, - "end": 33, + "start": 28, + "end": 29, "loc": { "start": { "line": 2, - "column": 23 + "column": 19 }, "end": { "line": 2, - "column": 24 + "column": 20 }, "identifierName": "a" }, "name": "a" }, - "operator": "+", + "operator": "-", "right": { "type": "Identifier", - "start": 36, - "end": 37, + "start": 32, + "end": 33, "loc": { "start": { "line": 2, - "column": 27 + "column": 23 }, "end": { "line": 2, - "column": 28 + "column": 24 }, "identifierName": "b" }, @@ -286,8 +269,8 @@ }, { "type": "MatchCase", - "start": 40, - "end": 57, + "start": 36, + "end": 66, "loc": { "start": { "line": 3, @@ -295,36 +278,36 @@ }, "end": { "line": 3, - "column": 19 + "column": 32 } }, "binding": { "type": "ObjectPattern", - "start": 42, - "end": 50, + "start": 43, + "end": 55, "loc": { "start": { "line": 3, - "column": 4 + "column": 9 }, "end": { "line": 3, - "column": 12 + "column": 21 } }, "properties": [ { "type": "ObjectProperty", - "start": 44, - "end": 45, + "start": 45, + "end": 46, "loc": { "start": { "line": 3, - "column": 6 + "column": 11 }, "end": { "line": 3, - "column": 7 + "column": 12 } }, "method": false, @@ -332,16 +315,16 @@ "computed": false, "key": { "type": "Identifier", - "start": 44, - "end": 45, + "start": 45, + "end": 46, "loc": { "start": { "line": 3, - "column": 6 + "column": 11 }, "end": { "line": 3, - "column": 7 + "column": 12 }, "identifierName": "a" }, @@ -349,16 +332,16 @@ }, "value": { "type": "Identifier", - "start": 44, - "end": 45, + "start": 45, + "end": 46, "loc": { "start": { "line": 3, - "column": 6 + "column": 11 }, "end": { "line": 3, - "column": 7 + "column": 12 }, "identifierName": "a" }, @@ -370,16 +353,16 @@ }, { "type": "ObjectProperty", - "start": 47, - "end": 48, + "start": 48, + "end": 53, "loc": { "start": { "line": 3, - "column": 9 + "column": 14 }, "end": { "line": 3, - "column": 10 + "column": 19 } }, "method": false, @@ -387,37 +370,72 @@ "computed": false, "key": { "type": "Identifier", - "start": 47, - "end": 48, + "start": 48, + "end": 49, "loc": { "start": { "line": 3, - "column": 9 + "column": 14 }, "end": { "line": 3, - "column": 10 + "column": 15 }, "identifierName": "b" }, "name": "b" }, "value": { - "type": "Identifier", - "start": 47, - "end": 48, + "type": "AssignmentPattern", + "start": 48, + "end": 53, "loc": { "start": { "line": 3, - "column": 9 + "column": 14 }, "end": { "line": 3, - "column": 10 + "column": 19 + } + }, + "left": { + "type": "Identifier", + "start": 48, + "end": 49, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + }, + "identifierName": "b" }, - "identifierName": "b" + "name": "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 @@ -425,77 +443,112 @@ } ] }, - "test": null, "consequent": { "type": "ExpressionStatement", - "start": 52, - "end": 57, + "start": 57, + "end": 66, "loc": { "start": { "line": 3, - "column": 14 + "column": 23 }, "end": { "line": 3, - "column": 19 + "column": 32 } }, "expression": { "type": "BinaryExpression", - "start": 52, - "end": 57, + "start": 57, + "end": 66, "loc": { "start": { "line": 3, - "column": 14 + "column": 23 }, "end": { "line": 3, - "column": 19 + "column": 32 } }, "left": { - "type": "Identifier", - "start": 52, - "end": 53, + "type": "BinaryExpression", + "start": 57, + "end": 62, "loc": { "start": { "line": 3, - "column": 14 + "column": 23 }, "end": { "line": 3, - "column": 15 + "column": 28 + } + }, + "left": { + "type": "Identifier", + "start": 57, + "end": 58, + "loc": { + "start": { + "line": 3, + "column": 23 + }, + "end": { + "line": 3, + "column": 24 + }, + "identifierName": "a" }, - "identifierName": "a" + "name": "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": "Identifier", - "start": 56, - "end": 57, + "type": "NumericLiteral", + "start": 65, + "end": 66, "loc": { "start": { "line": 3, - "column": 18 + "column": 31 }, "end": { "line": 3, - "column": 19 - }, - "identifierName": "b" + "column": 32 + } }, - "name": "b" + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 } } } }, { "type": "MatchCase", - "start": 60, - "end": 85, + "start": 69, + "end": 107, "loc": { "start": { "line": 4, @@ -503,36 +556,36 @@ }, "end": { "line": 4, - "column": 27 + "column": 40 } }, "binding": { "type": "ObjectPattern", - "start": 62, - "end": 74, + "start": 76, + "end": 87, "loc": { "start": { "line": 4, - "column": 4 + "column": 9 }, "end": { "line": 4, - "column": 16 + "column": 20 } }, "properties": [ { "type": "ObjectProperty", - "start": 64, - "end": 65, + "start": 78, + "end": 79, "loc": { "start": { "line": 4, - "column": 6 + "column": 11 }, "end": { "line": 4, - "column": 7 + "column": 12 } }, "method": false, @@ -540,16 +593,16 @@ "computed": false, "key": { "type": "Identifier", - "start": 64, - "end": 65, + "start": 78, + "end": 79, "loc": { "start": { "line": 4, - "column": 6 + "column": 11 }, "end": { "line": 4, - "column": 7 + "column": 12 }, "identifierName": "a" }, @@ -557,16 +610,16 @@ }, "value": { "type": "Identifier", - "start": 64, - "end": 65, + "start": 78, + "end": 79, "loc": { "start": { "line": 4, - "column": 6 + "column": 11 }, "end": { "line": 4, - "column": 7 + "column": 12 }, "identifierName": "a" }, @@ -577,162 +630,85 @@ } }, { - "type": "ObjectProperty", - "start": 67, - "end": 72, + "type": "RestProperty", + "start": 81, + "end": 85, "loc": { "start": { "line": 4, - "column": 9 + "column": 14 }, "end": { "line": 4, - "column": 14 + "column": 18 } }, - "method": false, - "shorthand": true, - "computed": false, - "key": { + "argument": { "type": "Identifier", - "start": 67, - "end": 68, - "loc": { - "start": { - "line": 4, - "column": 9 - }, - "end": { - "line": 4, - "column": 10 - }, - "identifierName": "b" - }, - "name": "b" - }, - "value": { - "type": "AssignmentPattern", - "start": 67, - "end": 72, + "start": 84, + "end": 85, "loc": { "start": { "line": 4, - "column": 9 + "column": 17 }, "end": { "line": 4, - "column": 14 - } - }, - "left": { - "type": "Identifier", - "start": 67, - "end": 68, - "loc": { - "start": { - "line": 4, - "column": 9 - }, - "end": { - "line": 4, - "column": 10 - }, - "identifierName": "b" + "column": 18 }, - "name": "b" + "identifierName": "c" }, - "right": { - "type": "NumericLiteral", - "start": 71, - "end": 72, - "loc": { - "start": { - "line": 4, - "column": 13 - }, - "end": { - "line": 4, - "column": 14 - } - }, - "extra": { - "rawValue": 2, - "raw": "2" - }, - "value": 2 - } - }, - "extra": { - "shorthand": true + "name": "c" } } ] }, - "test": null, "consequent": { "type": "ExpressionStatement", - "start": 76, - "end": 85, + "start": 89, + "end": 107, "loc": { "start": { "line": 4, - "column": 18 + "column": 22 }, "end": { "line": 4, - "column": 27 + "column": 40 } }, "expression": { - "type": "BinaryExpression", - "start": 76, - "end": 85, + "type": "CallExpression", + "start": 89, + "end": 107, "loc": { "start": { "line": 4, - "column": 18 + "column": 22 }, "end": { "line": 4, - "column": 27 + "column": 40 } }, - "left": { - "type": "BinaryExpression", - "start": 76, - "end": 81, + "callee": { + "type": "MemberExpression", + "start": 89, + "end": 103, "loc": { "start": { "line": 4, - "column": 18 + "column": 22 }, "end": { "line": 4, - "column": 23 + "column": 36 } }, - "left": { - "type": "Identifier", - "start": 76, - "end": 77, - "loc": { - "start": { - "line": 4, - "column": 18 - }, - "end": { - "line": 4, - "column": 19 - }, - "identifierName": "a" - }, - "name": "a" - }, - "operator": "+", - "right": { - "type": "Identifier", - "start": 80, - "end": 81, + "object": { + "type": "ArrayExpression", + "start": 89, + "end": 98, "loc": { "start": { "line": 4, @@ -740,41 +716,111 @@ }, "end": { "line": 4, - "column": 23 + "column": 31 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 90, + "end": 91, + "loc": { + "start": { + "line": 4, + "column": 23 + }, + "end": { + "line": 4, + "column": 24 + }, + "identifierName": "a" + }, + "name": "a" }, - "identifierName": "b" + { + "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": "b" - } + "name": "join" + }, + "computed": false }, - "operator": "-", - "right": { - "type": "NumericLiteral", - "start": 84, - "end": 85, - "loc": { - "start": { - "line": 4, - "column": 26 + "arguments": [ + { + "type": "StringLiteral", + "start": 104, + "end": 106, + "loc": { + "start": { + "line": 4, + "column": 37 + }, + "end": { + "line": 4, + "column": 39 + } }, - "end": { - "line": 4, - "column": 27 - } - }, - "extra": { - "rawValue": 2, - "raw": "2" - }, - "value": 2 - } + "extra": { + "rawValue": "", + "raw": "''" + }, + "value": "" + } + ] } } }, { "type": "MatchCase", - "start": 88, - "end": 172, + "start": 110, + "end": 199, "loc": { "start": { "line": 5, @@ -787,12 +833,12 @@ }, "binding": { "type": "ObjectPattern", - "start": 90, - "end": 148, + "start": 117, + "end": 175, "loc": { "start": { "line": 5, - "column": 4 + "column": 9 }, "end": { "line": 11, @@ -802,8 +848,8 @@ "properties": [ { "type": "ObjectProperty", - "start": 96, - "end": 128, + "start": 123, + "end": 155, "loc": { "start": { "line": 6, @@ -819,8 +865,8 @@ "computed": false, "key": { "type": "Identifier", - "start": 96, - "end": 97, + "start": 123, + "end": 124, "loc": { "start": { "line": 6, @@ -836,8 +882,8 @@ }, "value": { "type": "ObjectPattern", - "start": 99, - "end": 128, + "start": 126, + "end": 155, "loc": { "start": { "line": 6, @@ -851,8 +897,8 @@ "properties": [ { "type": "ObjectProperty", - "start": 107, - "end": 108, + "start": 134, + "end": 135, "loc": { "start": { "line": 7, @@ -868,8 +914,8 @@ "computed": false, "key": { "type": "Identifier", - "start": 107, - "end": 108, + "start": 134, + "end": 135, "loc": { "start": { "line": 7, @@ -885,8 +931,8 @@ }, "value": { "type": "Identifier", - "start": 107, - "end": 108, + "start": 134, + "end": 135, "loc": { "start": { "line": 7, @@ -906,8 +952,8 @@ }, { "type": "ObjectProperty", - "start": 115, - "end": 122, + "start": 142, + "end": 149, "loc": { "start": { "line": 8, @@ -923,8 +969,8 @@ "computed": false, "key": { "type": "Identifier", - "start": 115, - "end": 116, + "start": 142, + "end": 143, "loc": { "start": { "line": 8, @@ -940,8 +986,8 @@ }, "value": { "type": "AssignmentPattern", - "start": 115, - "end": 122, + "start": 142, + "end": 149, "loc": { "start": { "line": 8, @@ -954,8 +1000,8 @@ }, "left": { "type": "Identifier", - "start": 115, - "end": 116, + "start": 142, + "end": 143, "loc": { "start": { "line": 8, @@ -971,8 +1017,8 @@ }, "right": { "type": "StringLiteral", - "start": 119, - "end": 122, + "start": 146, + "end": 149, "loc": { "start": { "line": 8, @@ -999,8 +1045,8 @@ }, { "type": "ObjectProperty", - "start": 133, - "end": 144, + "start": 160, + "end": 171, "loc": { "start": { "line": 10, @@ -1016,8 +1062,8 @@ "computed": false, "key": { "type": "Identifier", - "start": 133, - "end": 134, + "start": 160, + "end": 161, "loc": { "start": { "line": 10, @@ -1033,8 +1079,8 @@ }, "value": { "type": "ObjectPattern", - "start": 136, - "end": 144, + "start": 163, + "end": 171, "loc": { "start": { "line": 10, @@ -1048,8 +1094,8 @@ "properties": [ { "type": "RestProperty", - "start": 138, - "end": 142, + "start": 165, + "end": 169, "loc": { "start": { "line": 10, @@ -1062,8 +1108,8 @@ }, "argument": { "type": "Identifier", - "start": 141, - "end": 142, + "start": 168, + "end": 169, "loc": { "start": { "line": 10, @@ -1083,11 +1129,10 @@ } ] }, - "test": null, "consequent": { "type": "BlockStatement", - "start": 148, - "end": 172, + "start": 175, + "end": 199, "loc": { "start": { "line": 11, @@ -1101,8 +1146,8 @@ "body": [ { "type": "ExpressionStatement", - "start": 154, - "end": 172, + "start": 181, + "end": 199, "loc": { "start": { "line": 12, @@ -1115,8 +1160,8 @@ }, "expression": { "type": "CallExpression", - "start": 154, - "end": 172, + "start": 181, + "end": 199, "loc": { "start": { "line": 12, @@ -1129,8 +1174,8 @@ }, "callee": { "type": "MemberExpression", - "start": 154, - "end": 168, + "start": 181, + "end": 195, "loc": { "start": { "line": 12, @@ -1143,8 +1188,8 @@ }, "object": { "type": "ArrayExpression", - "start": 154, - "end": 163, + "start": 181, + "end": 190, "loc": { "start": { "line": 12, @@ -1158,8 +1203,8 @@ "elements": [ { "type": "Identifier", - "start": 155, - "end": 156, + "start": 182, + "end": 183, "loc": { "start": { "line": 12, @@ -1175,8 +1220,8 @@ }, { "type": "Identifier", - "start": 158, - "end": 159, + "start": 185, + "end": 186, "loc": { "start": { "line": 12, @@ -1192,8 +1237,8 @@ }, { "type": "Identifier", - "start": 161, - "end": 162, + "start": 188, + "end": 189, "loc": { "start": { "line": 12, @@ -1211,8 +1256,8 @@ }, "property": { "type": "Identifier", - "start": 164, - "end": 168, + "start": 191, + "end": 195, "loc": { "start": { "line": 12, @@ -1231,8 +1276,8 @@ "arguments": [ { "type": "StringLiteral", - "start": 169, - "end": 171, + "start": 196, + "end": 198, "loc": { "start": { "line": 12, @@ -1261,8 +1306,8 @@ }, { "type": "MatchCase", - "start": 175, - "end": 208, + "start": 202, + "end": 228, "loc": { "start": { "line": 13, @@ -1270,36 +1315,53 @@ }, "end": { "line": 13, - "column": 35 + "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": 177, - "end": 188, + "start": 213, + "end": 221, "loc": { "start": { "line": 13, - "column": 4 + "column": 13 }, "end": { "line": 13, - "column": 15 + "column": 21 } }, "properties": [ { "type": "ObjectProperty", - "start": 179, - "end": 180, + "start": 215, + "end": 216, "loc": { "start": { "line": 13, - "column": 6 + "column": 15 }, "end": { "line": 13, - "column": 7 + "column": 16 } }, "method": false, @@ -1307,16 +1369,16 @@ "computed": false, "key": { "type": "Identifier", - "start": 179, - "end": 180, + "start": 215, + "end": 216, "loc": { "start": { "line": 13, - "column": 6 + "column": 15 }, "end": { "line": 13, - "column": 7 + "column": 16 }, "identifierName": "a" }, @@ -1324,16 +1386,16 @@ }, "value": { "type": "Identifier", - "start": 179, - "end": 180, + "start": 215, + "end": 216, "loc": { "start": { "line": 13, - "column": 6 + "column": 15 }, "end": { "line": 13, - "column": 7 + "column": 16 }, "identifierName": "a" }, @@ -1344,191 +1406,1213 @@ } }, { - "type": "RestProperty", - "start": 182, - "end": 186, + "type": "ObjectProperty", + "start": 218, + "end": 219, "loc": { "start": { "line": 13, - "column": 9 + "column": 18 }, "end": { "line": 13, - "column": 13 + "column": 19 } }, - "argument": { + "method": false, + "shorthand": true, + "computed": false, + "key": { "type": "Identifier", - "start": 185, - "end": 186, + "start": 218, + "end": 219, "loc": { "start": { "line": 13, - "column": 12 + "column": 18 }, "end": { "line": 13, - "column": 13 + "column": 19 }, - "identifierName": "c" + "identifierName": "b" }, - "name": "c" + "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 } } ] }, - "test": null, "consequent": { "type": "ExpressionStatement", - "start": 190, - "end": 208, + "start": 223, + "end": 228, "loc": { "start": { "line": 13, - "column": 17 + "column": 23 }, "end": { "line": 13, - "column": 35 + "column": 28 } }, "expression": { - "type": "CallExpression", - "start": 190, - "end": 208, + "type": "BinaryExpression", + "start": 223, + "end": 228, "loc": { "start": { "line": 13, - "column": 17 + "column": 23 }, "end": { "line": 13, - "column": 35 + "column": 28 } }, - "callee": { - "type": "MemberExpression", - "start": 190, - "end": 204, + "left": { + "type": "Identifier", + "start": 223, + "end": 224, "loc": { "start": { "line": 13, - "column": 17 + "column": 23 }, "end": { "line": 13, - "column": 31 + "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 } }, - "object": { - "type": "ArrayExpression", - "start": 190, - "end": 199, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 244, + "end": 245, "loc": { "start": { - "line": 13, - "column": 17 + "line": 14, + "column": 15 }, "end": { - "line": 13, - "column": 26 - } + "line": 14, + "column": 16 + }, + "identifierName": "a" }, - "elements": [ + "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": 191, - "end": 192, + "start": 293, + "end": 294, "loc": { "start": { - "line": 13, - "column": 18 + "line": 15, + "column": 27 }, "end": { - "line": 13, - "column": 19 + "line": 15, + "column": 28 }, "identifierName": "a" }, "name": "a" }, { - "type": "Identifier", - "start": 194, - "end": 195, + "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": 13, - "column": 21 + "line": 16, + "column": 19 }, "end": { - "line": 13, - "column": 22 + "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" }, - "identifierName": "b" + "name": "d" }, - "name": "b" - }, - { - "type": "Identifier", - "start": 197, - "end": 198, - "loc": { - "start": { - "line": 13, - "column": 24 + "value": { + "type": "AssignmentPattern", + "start": 330, + "end": 337, + "loc": { + "start": { + "line": 16, + "column": 19 + }, + "end": { + "line": 16, + "column": 26 + } }, - "end": { - "line": 13, - "column": 25 + "left": { + "type": "Identifier", + "start": 330, + "end": 331, + "loc": { + "start": { + "line": 16, + "column": 19 + }, + "end": { + "line": 16, + "column": 20 + }, + "identifierName": "d" + }, + "name": "d" }, - "identifierName": "c" + "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" + } }, - "name": "c" + "extra": { + "shorthand": true + } } ] + } + }, + { + "type": "ObjectProperty", + "start": 339, + "end": 349, + "loc": { + "start": { + "line": 16, + "column": 28 + }, + "end": { + "line": 16, + "column": 38 + } }, - "property": { + "method": false, + "shorthand": false, + "computed": false, + "key": { "type": "Identifier", - "start": 200, - "end": 204, + "start": 339, + "end": 340, "loc": { "start": { - "line": 13, - "column": 27 + "line": 16, + "column": 28 }, "end": { - "line": 13, - "column": 31 + "line": 16, + "column": 29 }, - "identifierName": "join" + "identifierName": "f" }, - "name": "join" + "name": "f" }, - "computed": false + "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 }, - "arguments": [ - { - "type": "StringLiteral", - "start": 205, - "end": 207, + "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": 13, - "column": 32 + "line": 17, + "column": 4 }, "end": { - "line": 13, - "column": 34 + "line": 17, + "column": 22 } }, - "extra": { - "rawValue": "", - "raw": "''" + "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 }, - "value": "" + "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 } } } diff --git a/test/fixtures/lightscript/match/illegal-destructure-and-with/actual.js b/test/fixtures/lightscript/match/illegal-destructure-and-with/actual.js index bf0b0e528d..5a536fa493 100644 --- a/test/fixtures/lightscript/match/illegal-destructure-and-with/actual.js +++ b/test/fixtures/lightscript/match/illegal-destructure-and-with/actual.js @@ -1,2 +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-destructure-and-with/options.json b/test/fixtures/lightscript/match/illegal-destructure-and-with/options.json deleted file mode 100644 index eb311191fb..0000000000 --- a/test/fixtures/lightscript/match/illegal-destructure-and-with/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Cannot destructure twice. (2:10)" -}