From 53951930236b6248da388f5ca95af51d93a78e37 Mon Sep 17 00:00:00 2001 From: Alex Rattray Date: Fri, 9 Jun 2017 12:46:33 -0700 Subject: [PATCH] Replace PlaceholderExpression with it --- src/index.js | 32 +++++++++++-------- test/fixtures/match/arr-pattern/actual.js | 10 +++--- test/fixtures/match/arr-pattern/exec.js | 26 +++++++-------- .../match/as-call-expression/actual.js | 7 ++++ .../match/as-call-expression/expected.js | 15 +++++++++ .../match/as-call-statement/actual.js | 7 ++++ .../match/as-call-statement/expected.js | 15 +++++++++ .../match/as-identifier-expression/actual.js | 7 ++++ .../as-identifier-expression/expected.js | 15 +++++++++ .../actual.js | 3 ++ .../expected.js | 7 ++++ .../actual.js | 3 ++ .../expected.js | 5 +++ .../match/as-identifier-statement/actual.js | 7 ++++ .../match/as-identifier-statement/expected.js | 15 +++++++++ .../match/as-it-call-expression/actual.js | 7 ++++ .../match/as-it-call-expression/expected.js | 15 +++++++++ .../match/as-it-call-statement/actual.js | 7 ++++ .../match/as-it-call-statement/expected.js | 15 +++++++++ .../as-it-identifier-expression/actual.js | 7 ++++ .../as-it-identifier-expression/expected.js | 15 +++++++++ .../as-it-identifier-statement/actual.js | 7 ++++ .../as-it-identifier-statement/expected.js | 15 +++++++++ .../match/basic-placeholder/actual.js | 7 ---- .../match/basic-placeholder/expected.js | 13 -------- .../match/basic-statement-call/actual.js | 7 ++++ .../match/basic-statement-call/expected.js | 9 ++++++ .../match/basic-value-checks/expected.js | 20 ++++++------ test/fixtures/match/basic/expected.js | 6 ++-- test/fixtures/match/not/actual.js | 2 +- test/fixtures/match/not/expected.js | 6 ++-- test/fixtures/match/obj-pattern/actual.js | 12 +++---- test/fixtures/match/obj-pattern/exec.js | 12 +++---- test/fixtures/match/obj-pattern/expected.js | 2 +- .../match/single-else-expr/expected.js | 2 +- 35 files changed, 279 insertions(+), 81 deletions(-) create mode 100644 test/fixtures/match/as-call-expression/actual.js create mode 100644 test/fixtures/match/as-call-expression/expected.js create mode 100644 test/fixtures/match/as-call-statement/actual.js create mode 100644 test/fixtures/match/as-call-statement/expected.js create mode 100644 test/fixtures/match/as-identifier-expression/actual.js create mode 100644 test/fixtures/match/as-identifier-expression/expected.js create mode 100644 test/fixtures/match/as-identifier-statement-body-reference/actual.js create mode 100644 test/fixtures/match/as-identifier-statement-body-reference/expected.js create mode 100644 test/fixtures/match/as-identifier-statement-not-referenced/actual.js create mode 100644 test/fixtures/match/as-identifier-statement-not-referenced/expected.js create mode 100644 test/fixtures/match/as-identifier-statement/actual.js create mode 100644 test/fixtures/match/as-identifier-statement/expected.js create mode 100644 test/fixtures/match/as-it-call-expression/actual.js create mode 100644 test/fixtures/match/as-it-call-expression/expected.js create mode 100644 test/fixtures/match/as-it-call-statement/actual.js create mode 100644 test/fixtures/match/as-it-call-statement/expected.js create mode 100644 test/fixtures/match/as-it-identifier-expression/actual.js create mode 100644 test/fixtures/match/as-it-identifier-expression/expected.js create mode 100644 test/fixtures/match/as-it-identifier-statement/actual.js create mode 100644 test/fixtures/match/as-it-identifier-statement/expected.js delete mode 100644 test/fixtures/match/basic-placeholder/actual.js delete mode 100644 test/fixtures/match/basic-placeholder/expected.js create mode 100644 test/fixtures/match/basic-statement-call/actual.js create mode 100644 test/fixtures/match/basic-statement-call/expected.js diff --git a/src/index.js b/src/index.js index c225454..dffb331 100644 --- a/src/index.js +++ b/src/index.js @@ -950,16 +950,22 @@ export default function (babel) { return test; } + function containsAliasReference(path, alias) { + let containsAlias = false; + path.traverse({ + ReferencedIdentifier(refPath) { + if (refPath.node.name === alias.name) { + containsAlias = true; + refPath.stop(); + } + } + }); + return containsAlias; + } + function transformMatchCases(argRef, cases) { return cases.reduce((rootIf, path) => { - // fill in placeholders - path.get("test").traverse({ - PlaceholderExpression(placeholderPath) { - placeholderPath.replaceWith(argRef); - } - }); - // add in ===, etc transformMatchCaseTest(path.get("test"), argRef); @@ -1243,9 +1249,6 @@ export default function (babel) { // only allowed in MatchCase, so don't alias to Expression }); - definePluginType("PlaceholderExpression", { - aliases: ["Expression"] - }); // traverse as top-level item so as to run before other babel plugins // (and avoid traversing any of their output) @@ -1547,9 +1550,9 @@ export default function (babel) { }, MatchExpression(path) { - const { discriminant } = path.node; + const { discriminant, alias = null } = path.node; - const argRef = path.scope.generateUidIdentifier("it"); + const argRef = alias || t.identifier("it"); const matchBody = transformMatchCases(argRef, path.get("cases")); const iife = t.callExpression( @@ -1561,12 +1564,13 @@ export default function (babel) { MatchStatement(path) { const { discriminant } = path.node; + const alias = path.node.alias || t.identifier("it"); let argRef; - if (t.isIdentifier(discriminant)) { + if (t.isIdentifier(discriminant) && !containsAliasReference(path, alias)) { argRef = discriminant; } else { - argRef = path.scope.generateUidIdentifier("it"); + argRef = alias; path.insertBefore(t.variableDeclaration("const", [ t.variableDeclarator(argRef, discriminant) ])); diff --git a/test/fixtures/match/arr-pattern/actual.js b/test/fixtures/match/arr-pattern/actual.js index 8a4c92d..86e8508 100644 --- a/test/fixtures/match/arr-pattern/actual.js +++ b/test/fixtures/match/arr-pattern/actual.js @@ -1,13 +1,13 @@ match x: - | []: + | with []: "empty" - | [ a, b ]: + | with [ a, b ]: a - b - | [ a, b = 2 ]: + | with [ a, b = 2 ]: a + b - 2 - | [ a, ...b ]: + | with [ a, ...b ]: b.concat(a) - | [ + | with [ [ b d = 'e' diff --git a/test/fixtures/match/arr-pattern/exec.js b/test/fixtures/match/arr-pattern/exec.js index db39428..685bb45 100644 --- a/test/fixtures/match/arr-pattern/exec.js +++ b/test/fixtures/match/arr-pattern/exec.js @@ -1,73 +1,73 @@ assert.equal( "empty", match []: - | []: + | with []: "empty" ) assert.equal( "empty", match []: - | []: + | with []: "empty" ) assert.equal( undefined, match []: - | [a]: + | with [a]: a + 1 ) assert.equal( undefined, match [1]: - | [a, b]: + | with [a, b]: a + b ) assert.equal( 5, match [1]: - | [a, b = 4]: + | with [a, b = 4]: a + b ) assert.equal( 3, match [1, 2]: - | [a, b]: + | with [a, b]: a + b ) assert.equal( 4, match [1, 2, 3]: - | [a,, b]: + | with [a,, b]: a + b ) assert.equal( undefined, match [1, 2]: - | [a,, b]: + | with [a,, b]: a + b ) assert.deepEqual( [2, 3, 1], match [1, 2, 3]: - | [a, ...b]: + | with [a, ...b]: b.concat(a) ) assert.deepEqual( [1, 4], match [4]: - | [a, b = 1, ...c]: + | with [a, b = 1, ...c]: c.concat([b, a]) ) assert.deepEqual( [6, 7, 5, 4], match [4, 5, 6, 7]: - | [a, b = 1, ...c]: + | with [a, b = 1, ...c]: c.concat([b, a]) ) assert.deepEqual( [1, 2, 4, 6, 7, 8], match [[1], [4, 5, 6], 7, 8]: - | [ + | with [ [ b d = 2 @@ -80,7 +80,7 @@ assert.deepEqual( assert.deepEqual( undefined, match [[1], [4, 5], 7, 8]: - | [ + | with [ [ b d = 2 diff --git a/test/fixtures/match/as-call-expression/actual.js b/test/fixtures/match/as-call-expression/actual.js new file mode 100644 index 0000000..3022db5 --- /dev/null +++ b/test/fixtures/match/as-call-expression/actual.js @@ -0,0 +1,7 @@ +z = match foo.bar() as y: + | y < 1: "lt one" + | y + 1 == 1: "eq zero" + | y == 2: "eq two" + | y~f(): "f(x) truthy" + | y.prop: "has prop" + | y.0: "has first child" diff --git a/test/fixtures/match/as-call-expression/expected.js b/test/fixtures/match/as-call-expression/expected.js new file mode 100644 index 0000000..9c3eb0f --- /dev/null +++ b/test/fixtures/match/as-call-expression/expected.js @@ -0,0 +1,15 @@ +const z = (y => { + if (y < 1) { + return "lt one"; + } else if (y + 1 === 1) { + return "eq zero"; + } else if (y === 2) { + return "eq two"; + } else if (f(y)) { + return "f(x) truthy"; + } else if (y.prop) { + return "has prop"; + } else if (y[0]) { + return "has first child"; + } +})(foo.bar()); diff --git a/test/fixtures/match/as-call-statement/actual.js b/test/fixtures/match/as-call-statement/actual.js new file mode 100644 index 0000000..fa39259 --- /dev/null +++ b/test/fixtures/match/as-call-statement/actual.js @@ -0,0 +1,7 @@ +match foo() as y: + | y < 1: "lt one" + | y + 1 == 1: "eq zero" + | y == 2: "eq two" + | y~f(): "f(y) truthy" + | y.prop: "has prop" + | y.0: "has first child" diff --git a/test/fixtures/match/as-call-statement/expected.js b/test/fixtures/match/as-call-statement/expected.js new file mode 100644 index 0000000..2495206 --- /dev/null +++ b/test/fixtures/match/as-call-statement/expected.js @@ -0,0 +1,15 @@ +const y = foo(); + +if (y < 1) { + "lt one"; + } else if (y + 1 === 1) { + "eq zero"; + } else if (y === 2) { + "eq two"; + } else if (f(y)) { + "f(y) truthy"; + } else if (y.prop) { + "has prop"; + } else if (y[0]) { + "has first child"; + } diff --git a/test/fixtures/match/as-identifier-expression/actual.js b/test/fixtures/match/as-identifier-expression/actual.js new file mode 100644 index 0000000..b0a69e6 --- /dev/null +++ b/test/fixtures/match/as-identifier-expression/actual.js @@ -0,0 +1,7 @@ +z = match x as y: + | y < 1: "lt one" + | y + 1 == 1: "eq zero" + | y == 2: "eq two" + | y~f(): "f(x) truthy" + | y.prop: "has prop" + | y.0: "has first child" diff --git a/test/fixtures/match/as-identifier-expression/expected.js b/test/fixtures/match/as-identifier-expression/expected.js new file mode 100644 index 0000000..7ad5dd7 --- /dev/null +++ b/test/fixtures/match/as-identifier-expression/expected.js @@ -0,0 +1,15 @@ +const z = (y => { + if (y < 1) { + return "lt one"; + } else if (y + 1 === 1) { + return "eq zero"; + } else if (y === 2) { + return "eq two"; + } else if (f(y)) { + return "f(x) truthy"; + } else if (y.prop) { + return "has prop"; + } else if (y[0]) { + return "has first child"; + } +})(x); diff --git a/test/fixtures/match/as-identifier-statement-body-reference/actual.js b/test/fixtures/match/as-identifier-statement-body-reference/actual.js new file mode 100644 index 0000000..51b13d9 --- /dev/null +++ b/test/fixtures/match/as-identifier-statement-body-reference/actual.js @@ -0,0 +1,3 @@ +match x: + | 1: "foo" + | "1": it diff --git a/test/fixtures/match/as-identifier-statement-body-reference/expected.js b/test/fixtures/match/as-identifier-statement-body-reference/expected.js new file mode 100644 index 0000000..0d3448c --- /dev/null +++ b/test/fixtures/match/as-identifier-statement-body-reference/expected.js @@ -0,0 +1,7 @@ +const it = x; + +if (it === 1) { + "foo"; + } else if (it === "1") { + it; + } diff --git a/test/fixtures/match/as-identifier-statement-not-referenced/actual.js b/test/fixtures/match/as-identifier-statement-not-referenced/actual.js new file mode 100644 index 0000000..de807c5 --- /dev/null +++ b/test/fixtures/match/as-identifier-statement-not-referenced/actual.js @@ -0,0 +1,3 @@ +match x: + | 1: "foo" + | "1": "bar" diff --git a/test/fixtures/match/as-identifier-statement-not-referenced/expected.js b/test/fixtures/match/as-identifier-statement-not-referenced/expected.js new file mode 100644 index 0000000..eb590d2 --- /dev/null +++ b/test/fixtures/match/as-identifier-statement-not-referenced/expected.js @@ -0,0 +1,5 @@ +if (x === 1) { + "foo"; + } else if (x === "1") { + "bar"; + } diff --git a/test/fixtures/match/as-identifier-statement/actual.js b/test/fixtures/match/as-identifier-statement/actual.js new file mode 100644 index 0000000..c9c7d02 --- /dev/null +++ b/test/fixtures/match/as-identifier-statement/actual.js @@ -0,0 +1,7 @@ +match x as y: + | y < 1: "lt one" + | y + 1 == 1: "eq zero" + | y == 2: "eq two" + | y~f(): "f(x) truthy" + | y.prop: "has prop" + | y.0: "has first child" diff --git a/test/fixtures/match/as-identifier-statement/expected.js b/test/fixtures/match/as-identifier-statement/expected.js new file mode 100644 index 0000000..ab33968 --- /dev/null +++ b/test/fixtures/match/as-identifier-statement/expected.js @@ -0,0 +1,15 @@ +const y = x; + +if (y < 1) { + "lt one"; + } else if (y + 1 === 1) { + "eq zero"; + } else if (y === 2) { + "eq two"; + } else if (f(y)) { + "f(x) truthy"; + } else if (y.prop) { + "has prop"; + } else if (y[0]) { + "has first child"; + } diff --git a/test/fixtures/match/as-it-call-expression/actual.js b/test/fixtures/match/as-it-call-expression/actual.js new file mode 100644 index 0000000..6b68dac --- /dev/null +++ b/test/fixtures/match/as-it-call-expression/actual.js @@ -0,0 +1,7 @@ +z = match foo.bar(): + | it < 1: "lt one" + | it + 1 == 1: "eq zero" + | it == 2: "eq two" + | it~f(): "f(x) truthy" + | it.prop: "has prop" + | it.0: "has first child" diff --git a/test/fixtures/match/as-it-call-expression/expected.js b/test/fixtures/match/as-it-call-expression/expected.js new file mode 100644 index 0000000..0b417c8 --- /dev/null +++ b/test/fixtures/match/as-it-call-expression/expected.js @@ -0,0 +1,15 @@ +const z = (it => { + if (it < 1) { + return "lt one"; + } else if (it + 1 === 1) { + return "eq zero"; + } else if (it === 2) { + return "eq two"; + } else if (f(it)) { + return "f(x) truthy"; + } else if (it.prop) { + return "has prop"; + } else if (it[0]) { + return "has first child"; + } +})(foo.bar()); diff --git a/test/fixtures/match/as-it-call-statement/actual.js b/test/fixtures/match/as-it-call-statement/actual.js new file mode 100644 index 0000000..0097bbb --- /dev/null +++ b/test/fixtures/match/as-it-call-statement/actual.js @@ -0,0 +1,7 @@ +match foo(): + | it < 1: "lt one" + | it + 1 == 1: "eq zero" + | it == 2: "eq two" + | it~f(): "f(x) truthy" + | it.prop: "has prop" + | it.0: "has first child" diff --git a/test/fixtures/match/as-it-call-statement/expected.js b/test/fixtures/match/as-it-call-statement/expected.js new file mode 100644 index 0000000..9215777 --- /dev/null +++ b/test/fixtures/match/as-it-call-statement/expected.js @@ -0,0 +1,15 @@ +const it = foo(); + +if (it < 1) { + "lt one"; + } else if (it + 1 === 1) { + "eq zero"; + } else if (it === 2) { + "eq two"; + } else if (f(it)) { + "f(x) truthy"; + } else if (it.prop) { + "has prop"; + } else if (it[0]) { + "has first child"; + } diff --git a/test/fixtures/match/as-it-identifier-expression/actual.js b/test/fixtures/match/as-it-identifier-expression/actual.js new file mode 100644 index 0000000..c7779e8 --- /dev/null +++ b/test/fixtures/match/as-it-identifier-expression/actual.js @@ -0,0 +1,7 @@ +z = match x: + | it < 1: "lt one" + | it + 1 == 1: "eq zero" + | it == 2: "eq two" + | it~f(): "f(x) truthy" + | it.prop: "has prop" + | it.0: "has first child" diff --git a/test/fixtures/match/as-it-identifier-expression/expected.js b/test/fixtures/match/as-it-identifier-expression/expected.js new file mode 100644 index 0000000..2382825 --- /dev/null +++ b/test/fixtures/match/as-it-identifier-expression/expected.js @@ -0,0 +1,15 @@ +const z = (it => { + if (it < 1) { + return "lt one"; + } else if (it + 1 === 1) { + return "eq zero"; + } else if (it === 2) { + return "eq two"; + } else if (f(it)) { + return "f(x) truthy"; + } else if (it.prop) { + return "has prop"; + } else if (it[0]) { + return "has first child"; + } +})(x); diff --git a/test/fixtures/match/as-it-identifier-statement/actual.js b/test/fixtures/match/as-it-identifier-statement/actual.js new file mode 100644 index 0000000..b778a3f --- /dev/null +++ b/test/fixtures/match/as-it-identifier-statement/actual.js @@ -0,0 +1,7 @@ +match x: + | it < 1: "lt one" + | it + 1 == 1: "eq zero" + | it == 2: "eq two" + | it~f(): "f(x) truthy" + | it.prop: "has prop" + | it.0: "has first child" diff --git a/test/fixtures/match/as-it-identifier-statement/expected.js b/test/fixtures/match/as-it-identifier-statement/expected.js new file mode 100644 index 0000000..2187c8c --- /dev/null +++ b/test/fixtures/match/as-it-identifier-statement/expected.js @@ -0,0 +1,15 @@ +const it = x; + +if (it < 1) { + "lt one"; + } else if (it + 1 === 1) { + "eq zero"; + } else if (it === 2) { + "eq two"; + } else if (f(it)) { + "f(x) truthy"; + } else if (it.prop) { + "has prop"; + } else if (it[0]) { + "has first child"; + } diff --git a/test/fixtures/match/basic-placeholder/actual.js b/test/fixtures/match/basic-placeholder/actual.js deleted file mode 100644 index 61c0908..0000000 --- a/test/fixtures/match/basic-placeholder/actual.js +++ /dev/null @@ -1,7 +0,0 @@ -match x: - | < 1: "lt one" - | + 1 == 1: "eq zero" - | == 2: "eq two" - | ~f(): "f(x) truthy" - | .prop: "has prop" - | .0: "has first child" diff --git a/test/fixtures/match/basic-placeholder/expected.js b/test/fixtures/match/basic-placeholder/expected.js deleted file mode 100644 index d0d1511..0000000 --- a/test/fixtures/match/basic-placeholder/expected.js +++ /dev/null @@ -1,13 +0,0 @@ -if (x < 1) { - "lt one"; - } else if (x + 1 === 1) { - "eq zero"; - } else if (x === 2) { - "eq two"; - } else if (f(x)) { - "f(x) truthy"; - } else if (x.prop) { - "has prop"; - } else if (x[0]) { - "has first child"; - } diff --git a/test/fixtures/match/basic-statement-call/actual.js b/test/fixtures/match/basic-statement-call/actual.js new file mode 100644 index 0000000..5de670d --- /dev/null +++ b/test/fixtures/match/basic-statement-call/actual.js @@ -0,0 +1,7 @@ +match foo(): + | 1: + "one" + | 2: + "two" + | else: + "idk" diff --git a/test/fixtures/match/basic-statement-call/expected.js b/test/fixtures/match/basic-statement-call/expected.js new file mode 100644 index 0000000..de54b42 --- /dev/null +++ b/test/fixtures/match/basic-statement-call/expected.js @@ -0,0 +1,9 @@ +const it = foo(); + +if (it === 1) { + "one"; +} else if (it === 2) { + "two"; +} else { + "idk"; +} diff --git a/test/fixtures/match/basic-value-checks/expected.js b/test/fixtures/match/basic-value-checks/expected.js index 6dec644..4dae010 100644 --- a/test/fixtures/match/basic-value-checks/expected.js +++ b/test/fixtures/match/basic-value-checks/expected.js @@ -1,19 +1,21 @@ -if (x === 1 || x === 0.1 || x === 0x11 || x === +1 || x === -1) { +const it = x; + +if (it === 1 || it === 0.1 || it === 0x11 || it === +1 || it === -1) { it; -} else if (x === "hi") { +} else if (it === "hi") { it; -} else if (x === `there ${ 1 + 1 }`) { +} else if (it === `there ${ 1 + 1 }`) { it; -} else if (/\s+/.test(x)) { +} else if (/\s+/.test(it)) { it; -} else if (typeof x === "number" || typeof x === "boolean" || typeof x === "string") { +} else if (typeof it === "number" || typeof it === "boolean" || typeof it === "string") { it; -} else if (x instanceof Array || x instanceof Object || x instanceof Map || x instanceof Foo) { +} else if (it instanceof Array || it instanceof Object || it instanceof Map || it instanceof Foo) { it; -} else if (x === null || x === undefined) { +} else if (it === null || it === undefined) { it; } else if (x || +x) { it; -} else if (!(x === 1) || !x) { +} else if (!(it === 1) || !x) { it; -} +} \ No newline at end of file diff --git a/test/fixtures/match/basic/expected.js b/test/fixtures/match/basic/expected.js index d1f0004..6c0a0db 100644 --- a/test/fixtures/match/basic/expected.js +++ b/test/fixtures/match/basic/expected.js @@ -1,7 +1,7 @@ -const z = (_it => { - if (_it === 1) { +const z = (it => { + if (it === 1) { return "one"; - } else if (_it === 2) { + } else if (it === 2) { return "two"; } else { return "idk"; diff --git a/test/fixtures/match/not/actual.js b/test/fixtures/match/not/actual.js index 6148821..91a9037 100644 --- a/test/fixtures/match/not/actual.js +++ b/test/fixtures/match/not/actual.js @@ -1,5 +1,5 @@ match x: | not 1 or not Number or not "hi": it - | not x or not 1 + 1 or not foo(bar): + | not it or not 1 + 1 or not foo(bar): it diff --git a/test/fixtures/match/not/expected.js b/test/fixtures/match/not/expected.js index 8cb3a7c..ed7793b 100644 --- a/test/fixtures/match/not/expected.js +++ b/test/fixtures/match/not/expected.js @@ -1,5 +1,7 @@ -if (!(x === 1) || !(typeof x === "number") || !(x === "hi")) { +const it = x; + +if (!(it === 1) || !(typeof it === "number") || !(it === "hi")) { it; -} else if (!x || !1 + 1 || !foo(bar)) { +} else if (!it || !1 + 1 || !foo(bar)) { it; } \ No newline at end of file diff --git a/test/fixtures/match/obj-pattern/actual.js b/test/fixtures/match/obj-pattern/actual.js index 5ca3636..8ec8e06 100644 --- a/test/fixtures/match/obj-pattern/actual.js +++ b/test/fixtures/match/obj-pattern/actual.js @@ -1,14 +1,14 @@ match x: - | { a }: + | with { a }: a - | { a, b }: + | with { a, b }: a + b - | { a, b = 1 }: + | with { a, b = 1 }: a + b - | { a, b: { ba, bb = 1 }, c: { ca, cb: { cba } } }: + | with { a, b: { ba, bb = 1 }, c: { ca, cb: { cba } } }: a + ba + bb + ca + cba | 1 or 2 with { a, b: { c } }: a + c - | { a: { b: { c } } = otherObj }: + | with { a: { b: { c } } = otherObj }: c - //TODO: | { a, ...b }: b + //TODO: test `| { a, ...b }: b` diff --git a/test/fixtures/match/obj-pattern/exec.js b/test/fixtures/match/obj-pattern/exec.js index 65fbdb6..a3b272b 100644 --- a/test/fixtures/match/obj-pattern/exec.js +++ b/test/fixtures/match/obj-pattern/exec.js @@ -1,36 +1,36 @@ assert.equal( 1, match { a: 1 }: - | { a }: + | with { a }: a ) assert.equal( undefined, match { b: 1 }: - | { a }: + | with { a }: a ) assert.equal( 3, match { a: 1 }: - | { a, b = 2 }: + | with { a, b = 2 }: a + b ) assert.equal( undefined, match { b: 1 }: - | { a, b = 2 }: + | with { a, b = 2 }: a + b ) assert.equal( 3, match { a: 1, b: { c: 2 } }: - | { a, b: { c } }: + | with { a, b: { c } }: a + c ) assert.equal( undefined, match { a: 1 }: - | { a, b: { c } }: + | with { a, b: { c } }: a + c ) diff --git a/test/fixtures/match/obj-pattern/expected.js b/test/fixtures/match/obj-pattern/expected.js index 2302b8c..f9a9691 100644 --- a/test/fixtures/match/obj-pattern/expected.js +++ b/test/fixtures/match/obj-pattern/expected.js @@ -28,4 +28,4 @@ if (_hasProps(x, ["a"])) { const { a: { b: { c } } = otherObj } = x; c; -} //TODO: | { a, ...b }: b +} //TODO: test `| { a, ...b }: b` diff --git a/test/fixtures/match/single-else-expr/expected.js b/test/fixtures/match/single-else-expr/expected.js index 0c81fe4..80f4483 100644 --- a/test/fixtures/match/single-else-expr/expected.js +++ b/test/fixtures/match/single-else-expr/expected.js @@ -1,4 +1,4 @@ -const z = (_it => { +const z = (it => { { try {} finally {} return "idk";