From 1ad360cf3dff719130fc2a3eff390ff2e0104ec8 Mon Sep 17 00:00:00 2001 From: Boshen Date: Tue, 19 Nov 2024 23:13:21 +0800 Subject: [PATCH] update --- .../assignment/output.js | 8 ++ .../cast-to-boolean/output.js | 85 +++++++++++++++++++ .../in-function-params/output.js | 19 +++++ .../memoize/output.js | 18 ++++ .../optional-eval-call/output.js | 10 +++ .../super-method-call/output.js | 12 +++ .../function-call/output.js | 11 +++ .../assumption-pureGetters/memoize/output.js | 18 ++++ .../super-method-call/output.js | 12 +++ .../fixtures/general/assignment/output.js | 8 ++ .../general/cast-to-boolean/output.js | 85 +++++++++++++++++++ .../fixtures/general/containers/output.js | 6 ++ .../delete-in-function-params/output.js | 4 + .../test/fixtures/general/delete/output.js | 7 ++ .../general/function-call-loose/output.js | 5 ++ .../general/function-call-spread/output.js | 5 ++ .../fixtures/general/function-call/output.js | 11 +++ .../in-function-params-loose/output.js | 19 +++++ .../general/in-function-params/output.js | 19 +++++ .../general/in-method-key-loose/output.js | 3 + .../fixtures/general/in-method-key/output.js | 3 + .../general/in-var-destructuring/output.js | 2 + .../fixtures/general/member-access/output.js | 11 +++ .../fixtures/general/memoize-loose/output.js | 18 ++++ .../test/fixtures/general/memoize/output.js | 13 +++ .../optional-eval-call-loose/output.js | 10 +++ .../general/optional-eval-call/output.js | 10 +++ .../output.js | 6 ++ .../parenthesized-member-call-loose/output.js | 31 +++++++ .../parenthesized-member-call/output.js | 31 +++++++ .../general/super-method-call-loose/output.js | 12 +++ .../general/super-method-call/output.js | 12 +++ .../test/fixtures/general/unary/output.js | 7 ++ .../fixtures/loose/cast-to-boolean/output.js | 85 +++++++++++++++++++ .../output.js | 9 ++ .../output.js | 9 ++ .../regression/10959-transform-ts/output.js | 8 ++ .../test/fixtures/regression/15887/output.js | 3 + .../test/fixtures/regression/7642/output.js | 7 ++ .../ts-as-call-context-in-if/output.js | 4 + .../ts-as-call-context/output.js | 2 + .../ts-as-function-call-loose/output.js | 2 + .../ts-as-in-conditional/output.js | 4 + .../ts-as-member-expression/output.js | 2 + .../output.js | 2 + tasks/transform_conformance/src/test_case.rs | 4 +- 46 files changed, 671 insertions(+), 1 deletion(-) create mode 100644 tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/assumption-noDocumentAll/assignment/output.js create mode 100644 tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/assumption-noDocumentAll/cast-to-boolean/output.js create mode 100644 tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/assumption-noDocumentAll/in-function-params/output.js create mode 100644 tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/assumption-noDocumentAll/memoize/output.js create mode 100644 tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/assumption-noDocumentAll/optional-eval-call/output.js create mode 100644 tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/assumption-noDocumentAll/super-method-call/output.js create mode 100644 tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/assumption-pureGetters/function-call/output.js create mode 100644 tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/assumption-pureGetters/memoize/output.js create mode 100644 tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/assumption-pureGetters/super-method-call/output.js create mode 100644 tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/assignment/output.js create mode 100644 tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/cast-to-boolean/output.js create mode 100644 tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/containers/output.js create mode 100644 tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/delete-in-function-params/output.js create mode 100644 tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/delete/output.js create mode 100644 tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/function-call-loose/output.js create mode 100644 tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/function-call-spread/output.js create mode 100644 tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/function-call/output.js create mode 100644 tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/in-function-params-loose/output.js create mode 100644 tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/in-function-params/output.js create mode 100644 tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/in-method-key-loose/output.js create mode 100644 tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/in-method-key/output.js create mode 100644 tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/in-var-destructuring/output.js create mode 100644 tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/member-access/output.js create mode 100644 tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/memoize-loose/output.js create mode 100644 tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/memoize/output.js create mode 100644 tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/optional-eval-call-loose/output.js create mode 100644 tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/optional-eval-call/output.js create mode 100644 tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/parenthesized-expression-containers/output.js create mode 100644 tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/parenthesized-member-call-loose/output.js create mode 100644 tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/parenthesized-member-call/output.js create mode 100644 tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/super-method-call-loose/output.js create mode 100644 tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/super-method-call/output.js create mode 100644 tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/unary/output.js create mode 100644 tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/loose/cast-to-boolean/output.js create mode 100644 tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/regression/10959-transform-optional-chaining/output.js create mode 100644 tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/regression/10959-transform-ts-and-optional-chaining/output.js create mode 100644 tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/regression/10959-transform-ts/output.js create mode 100644 tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/regression/15887/output.js create mode 100644 tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/regression/7642/output.js create mode 100644 tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/transparent-expr-wrappers/ts-as-call-context-in-if/output.js create mode 100644 tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/transparent-expr-wrappers/ts-as-call-context/output.js create mode 100644 tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/transparent-expr-wrappers/ts-as-function-call-loose/output.js create mode 100644 tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/transparent-expr-wrappers/ts-as-in-conditional/output.js create mode 100644 tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/transparent-expr-wrappers/ts-as-member-expression/output.js create mode 100644 tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/transparent-expr-wrappers/ts-parenthesized-expression-member-call/output.js diff --git a/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/assumption-noDocumentAll/assignment/output.js b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/assumption-noDocumentAll/assignment/output.js new file mode 100644 index 00000000000000..5b53552b3dcdba --- /dev/null +++ b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/assumption-noDocumentAll/assignment/output.js @@ -0,0 +1,8 @@ +"use strict"; +var _obj$a, _obj$b, _obj$a2; +const obj = { a: { b: { c: { d: 2 } } } }; +const a = obj === null || obj === void 0 ? void 0 : obj.a; +const b = obj === null || obj === void 0 || (_obj$a = obj.a) === null || _obj$a === void 0 ? void 0 : _obj$a.b; +const bad = obj === null || obj === void 0 || (_obj$b = obj.b) === null || _obj$b === void 0 ? void 0 : _obj$b.b; +let val; +val = obj === null || obj === void 0 || (_obj$a2 = obj.a) === null || _obj$a2 === void 0 ? void 0 : _obj$a2.b; diff --git a/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/assumption-noDocumentAll/cast-to-boolean/output.js b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/assumption-noDocumentAll/cast-to-boolean/output.js new file mode 100644 index 00000000000000..07ff93c77a22fb --- /dev/null +++ b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/assumption-noDocumentAll/cast-to-boolean/output.js @@ -0,0 +1,85 @@ +class C { + static testIf(o) { + if (o !== null && o !== void 0 && o.a.b.c.d) { + return true; + } + return false; + } + static testConditional(o) { + var _o$a$b; + return o !== null && o !== void 0 && (_o$a$b = o.a.b) !== null && _o$a$b !== void 0 && _o$a$b.c.d ? true : false; + } + static testLoop(o) { + while (o !== null && o !== void 0 && o.a.b.c.d) { + var _o$a$b$c; + for (; o !== null && o !== void 0 && (_o$a$b$c = o.a.b.c) !== null && _o$a$b$c !== void 0 && _o$a$b$c.d;) { + var _o$a$b2; + let i = 0; + do { + i++; + if (i === 2) { + return true; + } + } while (o !== null && o !== void 0 && (_o$a$b2 = o.a.b) !== null && _o$a$b2 !== void 0 && _o$a$b2.c.d); + } + } + return false; + } + static testNegate(o) { + var _o$a$b3; + return !!(o !== null && o !== void 0 && (_o$a$b3 = o.a.b) !== null && _o$a$b3 !== void 0 && _o$a$b3.c.d); + } + static testIfDeep(o) { + var _o$obj; + if ((_o$obj = o.obj) !== null && _o$obj !== void 0 && (_o$obj = _o$obj.a.b) !== null && _o$obj !== void 0 && _o$obj.c.d) { + return true; + } + return false; + } + static testConditionalDeep(o) { + var _o$obj2; + return (_o$obj2 = o.obj) !== null && _o$obj2 !== void 0 && (_o$obj2 = _o$obj2.a.b) !== null && _o$obj2 !== void 0 && _o$obj2.c.d ? true : false; + } + static testLoopDeep(o) { + var _o$obj3; + while ((_o$obj3 = o.obj) !== null && _o$obj3 !== void 0 && _o$obj3.a.b.c.d) { + var _o$obj4; + for (; (_o$obj4 = o.obj) !== null && _o$obj4 !== void 0 && (_o$obj4 = _o$obj4.a.b.c) !== null && _o$obj4 !== void 0 && _o$obj4.d;) { + var _o$obj5; + let i = 0; + do { + i++; + if (i === 2) { + return true; + } + } while ((_o$obj5 = o.obj) !== null && _o$obj5 !== void 0 && (_o$obj5 = _o$obj5.a.b) !== null && _o$obj5 !== void 0 && _o$obj5.c.d); + } + } + return false; + } + static testNegateDeep(o) { + var _o$obj6; + return !!((_o$obj6 = o.obj) !== null && _o$obj6 !== void 0 && (_o$obj6 = _o$obj6.a.b) !== null && _o$obj6 !== void 0 && _o$obj6.c.d); + } + static testLogicalInIf(o) { + var _o$a$b4, _o$a; + if (o !== null && o !== void 0 && (_o$a$b4 = o.a.b) !== null && _o$a$b4 !== void 0 && _o$a$b4.c.d && o !== null && o !== void 0 && (_o$a = o.a) !== null && _o$a !== void 0 && _o$a.b.c.d) { + return true; + } + return false; + } + static testLogicalInReturn(o) { + var _o$a$b5, _o$a2; + return (o === null || o === void 0 || (_o$a$b5 = o.a.b) === null || _o$a$b5 === void 0 ? void 0 : _o$a$b5.c.d) && (o === null || o === void 0 || (_o$a2 = o.a) === null || _o$a2 === void 0 ? void 0 : _o$a2.b.c.d); + } + static testNullishCoalescing(o) { + var _o$a$b$c$non_existent, _o$a$b6, _o$a$b7, _o$a$b$c$non_existent3, _o$a$b10; + if ((_o$a$b$c$non_existent = o === null || o === void 0 || (_o$a$b6 = o.a.b) === null || _o$a$b6 === void 0 ? void 0 : _o$a$b6.c.non_existent) !== null && _o$a$b$c$non_existent !== void 0 ? _o$a$b$c$non_existent : o === null || o === void 0 || (_o$a$b7 = o.a.b) === null || _o$a$b7 === void 0 ? void 0 : _o$a$b7.c.d) { + var _o$a$b$c$non_existent2, _o$a$b8, _o$a$b9; + return (_o$a$b$c$non_existent2 = o === null || o === void 0 || (_o$a$b8 = o.a.b) === null || _o$a$b8 === void 0 ? void 0 : _o$a$b8.c.non_existent) !== null && _o$a$b$c$non_existent2 !== void 0 ? _o$a$b$c$non_existent2 : o === null || o === void 0 || (_o$a$b9 = o.a.b) === null || _o$a$b9 === void 0 ? void 0 : _o$a$b9.c.d; + } + return (_o$a$b$c$non_existent3 = o === null || o === void 0 || (_o$a$b10 = o.a.b) === null || _o$a$b10 === void 0 ? void 0 : _o$a$b10.c.non_existent) !== null && _o$a$b$c$non_existent3 !== void 0 ? _o$a$b$c$non_existent3 : o; + } +} +C.test(); +C.testNullish(); diff --git a/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/assumption-noDocumentAll/in-function-params/output.js b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/assumption-noDocumentAll/in-function-params/output.js new file mode 100644 index 00000000000000..0679618bed97d9 --- /dev/null +++ b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/assumption-noDocumentAll/in-function-params/output.js @@ -0,0 +1,19 @@ +function f(a = (() => { + var _x; + return (_x = x) === null || _x === void 0 ? void 0 : _x.y; +})()) {} +function g({ a, b = (() => { + return a === null || a === void 0 ? void 0 : a.c; +})() }) {} +function h(a, { b = (() => { + var _a$b; + return (_a$b = a.b) === null || _a$b === void 0 || (_a$b = _a$b.c) === null || _a$b === void 0 ? void 0 : _a$b.d.e; +})() }) {} +function i(a, { b = (() => { + var _a$b2; + return (_a$b2 = a.b) === null || _a$b2 === void 0 || (_a$b2 = _a$b2.c) === null || _a$b2 === void 0 ? void 0 : _a$b2.d; +})().e }) {} +function j(a, { b = (() => { + var _a$b3; + return a === null || a === void 0 || (_a$b3 = a.b) === null || _a$b3 === void 0 ? void 0 : _a$b3.c().d.e; +})() }) {} diff --git a/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/assumption-noDocumentAll/memoize/output.js b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/assumption-noDocumentAll/memoize/output.js new file mode 100644 index 00000000000000..a4a6939178abc7 --- /dev/null +++ b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/assumption-noDocumentAll/memoize/output.js @@ -0,0 +1,18 @@ +function test(foo) { + var _foo$bar, _foo$get, _foo$bar2, _foo$bar3, _foo$bar$baz, _foo$bar$baz2, _foo$bar4, _foo$bar5, _foo$bar6, _foo$bar7, _foo$bar8, _foo$bar8$baz, _foo$bar9, _foo$bar9$baz; + foo === null || foo === void 0 || foo.bar; + foo === null || foo === void 0 || (_foo$bar = foo.bar) === null || _foo$bar === void 0 || _foo$bar.baz; + foo === null || foo === void 0 || foo(foo); + foo === null || foo === void 0 || foo.bar(); + (_foo$get = foo.get(bar)) === null || _foo$get === void 0 || _foo$get(); + (_foo$bar2 = foo.bar()) === null || _foo$bar2 === void 0 || _foo$bar2(); + (_foo$bar3 = foo[bar]()) === null || _foo$bar3 === void 0 || _foo$bar3(); + (_foo$bar$baz = foo.bar().baz) === null || _foo$bar$baz === void 0 || _foo$bar$baz(); + (_foo$bar$baz2 = foo[bar]().baz) === null || _foo$bar$baz2 === void 0 || _foo$bar$baz2(); + (_foo$bar4 = foo.bar) === null || _foo$bar4 === void 0 || _foo$bar4.call(foo, foo.bar, false); + foo === null || foo === void 0 || (_foo$bar5 = foo.bar) === null || _foo$bar5 === void 0 || _foo$bar5.call(foo, foo.bar, true); + (_foo$bar6 = foo.bar) === null || _foo$bar6 === void 0 || _foo$bar6.baz(foo.bar, false); + foo === null || foo === void 0 || (_foo$bar7 = foo.bar) === null || _foo$bar7 === void 0 || _foo$bar7.baz(foo.bar, true); + (_foo$bar8 = foo.bar) === null || _foo$bar8 === void 0 || (_foo$bar8$baz = _foo$bar8.baz) === null || _foo$bar8$baz === void 0 || _foo$bar8$baz.call(_foo$bar8, foo.bar, false); + foo === null || foo === void 0 || (_foo$bar9 = foo.bar) === null || _foo$bar9 === void 0 || (_foo$bar9$baz = _foo$bar9.baz) === null || _foo$bar9$baz === void 0 || _foo$bar9$baz.call(_foo$bar9, foo.bar, true); +} diff --git a/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/assumption-noDocumentAll/optional-eval-call/output.js b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/assumption-noDocumentAll/optional-eval-call/output.js new file mode 100644 index 00000000000000..8ccdc51087fa53 --- /dev/null +++ b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/assumption-noDocumentAll/optional-eval-call/output.js @@ -0,0 +1,10 @@ +var _eval, _eval2, _foo$eval, _eval$foo; +var foo; +eval === null || eval === void 0 || (0, eval)(foo); +eval === null || eval === void 0 || (0, eval)(foo); +eval === null || eval === void 0 || (0, eval)()(); +eval === null || eval === void 0 || (0, eval)().foo; +(_eval = eval()) === null || _eval === void 0 || _eval(); +(_eval2 = eval()) === null || _eval2 === void 0 || _eval2.foo; +(_foo$eval = foo.eval) === null || _foo$eval === void 0 || _foo$eval.call(foo, foo); +(_eval$foo = eval.foo) === null || _eval$foo === void 0 || _eval$foo.call(eval, foo); diff --git a/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/assumption-noDocumentAll/super-method-call/output.js b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/assumption-noDocumentAll/super-method-call/output.js new file mode 100644 index 00000000000000..5d425d69fb1014 --- /dev/null +++ b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/assumption-noDocumentAll/super-method-call/output.js @@ -0,0 +1,12 @@ +"use strict"; +class Base { + method() { + return "Hello!"; + } +} +class Derived extends Base { + method() { + var _super$method; + return (_super$method = super.method) === null || _super$method === void 0 ? void 0 : _super$method.call(this); + } +} diff --git a/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/assumption-pureGetters/function-call/output.js b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/assumption-pureGetters/function-call/output.js new file mode 100644 index 00000000000000..363ae668984f83 --- /dev/null +++ b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/assumption-pureGetters/function-call/output.js @@ -0,0 +1,11 @@ +var _foo, _foo2, _foo$bar, _foo3, _foo4, _foo4$bar, _foo5, _foo6, _foo$bar2, _foo7, _foo$bar3, _foo8, _foo9, _foo9$bar, _foo10, _foo10$bar; +(_foo = foo) === null || _foo === void 0 || _foo(foo); +(_foo2 = foo) === null || _foo2 === void 0 || _foo2.bar(); +(_foo$bar = (_foo3 = foo).bar) === null || _foo$bar === void 0 || _foo$bar.call(_foo3, foo.bar, false); +(_foo4 = foo) === null || _foo4 === void 0 || (_foo4$bar = _foo4.bar) === null || _foo4$bar === void 0 || _foo4$bar.call(_foo4, foo.bar, true); +(_foo5 = foo) === null || _foo5 === void 0 || _foo5().bar; +(_foo6 = foo) === null || _foo6 === void 0 || (_foo6 = _foo6()) === null || _foo6 === void 0 || _foo6.bar; +(_foo$bar2 = (_foo7 = foo).bar) === null || _foo$bar2 === void 0 || _foo$bar2.call(_foo7).baz; +(_foo$bar3 = (_foo8 = foo).bar) === null || _foo$bar3 === void 0 || (_foo$bar3 = _foo$bar3.call(_foo8)) === null || _foo$bar3 === void 0 || _foo$bar3.baz; +(_foo9 = foo) === null || _foo9 === void 0 || (_foo9$bar = _foo9.bar) === null || _foo9$bar === void 0 || _foo9$bar.call(_foo9).baz; +(_foo10 = foo) === null || _foo10 === void 0 || (_foo10$bar = _foo10.bar) === null || _foo10$bar === void 0 || (_foo10$bar = _foo10$bar.call(_foo10)) === null || _foo10$bar === void 0 || _foo10$bar.baz; diff --git a/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/assumption-pureGetters/memoize/output.js b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/assumption-pureGetters/memoize/output.js new file mode 100644 index 00000000000000..a4a6939178abc7 --- /dev/null +++ b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/assumption-pureGetters/memoize/output.js @@ -0,0 +1,18 @@ +function test(foo) { + var _foo$bar, _foo$get, _foo$bar2, _foo$bar3, _foo$bar$baz, _foo$bar$baz2, _foo$bar4, _foo$bar5, _foo$bar6, _foo$bar7, _foo$bar8, _foo$bar8$baz, _foo$bar9, _foo$bar9$baz; + foo === null || foo === void 0 || foo.bar; + foo === null || foo === void 0 || (_foo$bar = foo.bar) === null || _foo$bar === void 0 || _foo$bar.baz; + foo === null || foo === void 0 || foo(foo); + foo === null || foo === void 0 || foo.bar(); + (_foo$get = foo.get(bar)) === null || _foo$get === void 0 || _foo$get(); + (_foo$bar2 = foo.bar()) === null || _foo$bar2 === void 0 || _foo$bar2(); + (_foo$bar3 = foo[bar]()) === null || _foo$bar3 === void 0 || _foo$bar3(); + (_foo$bar$baz = foo.bar().baz) === null || _foo$bar$baz === void 0 || _foo$bar$baz(); + (_foo$bar$baz2 = foo[bar]().baz) === null || _foo$bar$baz2 === void 0 || _foo$bar$baz2(); + (_foo$bar4 = foo.bar) === null || _foo$bar4 === void 0 || _foo$bar4.call(foo, foo.bar, false); + foo === null || foo === void 0 || (_foo$bar5 = foo.bar) === null || _foo$bar5 === void 0 || _foo$bar5.call(foo, foo.bar, true); + (_foo$bar6 = foo.bar) === null || _foo$bar6 === void 0 || _foo$bar6.baz(foo.bar, false); + foo === null || foo === void 0 || (_foo$bar7 = foo.bar) === null || _foo$bar7 === void 0 || _foo$bar7.baz(foo.bar, true); + (_foo$bar8 = foo.bar) === null || _foo$bar8 === void 0 || (_foo$bar8$baz = _foo$bar8.baz) === null || _foo$bar8$baz === void 0 || _foo$bar8$baz.call(_foo$bar8, foo.bar, false); + foo === null || foo === void 0 || (_foo$bar9 = foo.bar) === null || _foo$bar9 === void 0 || (_foo$bar9$baz = _foo$bar9.baz) === null || _foo$bar9$baz === void 0 || _foo$bar9$baz.call(_foo$bar9, foo.bar, true); +} diff --git a/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/assumption-pureGetters/super-method-call/output.js b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/assumption-pureGetters/super-method-call/output.js new file mode 100644 index 00000000000000..5d425d69fb1014 --- /dev/null +++ b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/assumption-pureGetters/super-method-call/output.js @@ -0,0 +1,12 @@ +"use strict"; +class Base { + method() { + return "Hello!"; + } +} +class Derived extends Base { + method() { + var _super$method; + return (_super$method = super.method) === null || _super$method === void 0 ? void 0 : _super$method.call(this); + } +} diff --git a/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/assignment/output.js b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/assignment/output.js new file mode 100644 index 00000000000000..5b53552b3dcdba --- /dev/null +++ b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/assignment/output.js @@ -0,0 +1,8 @@ +"use strict"; +var _obj$a, _obj$b, _obj$a2; +const obj = { a: { b: { c: { d: 2 } } } }; +const a = obj === null || obj === void 0 ? void 0 : obj.a; +const b = obj === null || obj === void 0 || (_obj$a = obj.a) === null || _obj$a === void 0 ? void 0 : _obj$a.b; +const bad = obj === null || obj === void 0 || (_obj$b = obj.b) === null || _obj$b === void 0 ? void 0 : _obj$b.b; +let val; +val = obj === null || obj === void 0 || (_obj$a2 = obj.a) === null || _obj$a2 === void 0 ? void 0 : _obj$a2.b; diff --git a/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/cast-to-boolean/output.js b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/cast-to-boolean/output.js new file mode 100644 index 00000000000000..07ff93c77a22fb --- /dev/null +++ b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/cast-to-boolean/output.js @@ -0,0 +1,85 @@ +class C { + static testIf(o) { + if (o !== null && o !== void 0 && o.a.b.c.d) { + return true; + } + return false; + } + static testConditional(o) { + var _o$a$b; + return o !== null && o !== void 0 && (_o$a$b = o.a.b) !== null && _o$a$b !== void 0 && _o$a$b.c.d ? true : false; + } + static testLoop(o) { + while (o !== null && o !== void 0 && o.a.b.c.d) { + var _o$a$b$c; + for (; o !== null && o !== void 0 && (_o$a$b$c = o.a.b.c) !== null && _o$a$b$c !== void 0 && _o$a$b$c.d;) { + var _o$a$b2; + let i = 0; + do { + i++; + if (i === 2) { + return true; + } + } while (o !== null && o !== void 0 && (_o$a$b2 = o.a.b) !== null && _o$a$b2 !== void 0 && _o$a$b2.c.d); + } + } + return false; + } + static testNegate(o) { + var _o$a$b3; + return !!(o !== null && o !== void 0 && (_o$a$b3 = o.a.b) !== null && _o$a$b3 !== void 0 && _o$a$b3.c.d); + } + static testIfDeep(o) { + var _o$obj; + if ((_o$obj = o.obj) !== null && _o$obj !== void 0 && (_o$obj = _o$obj.a.b) !== null && _o$obj !== void 0 && _o$obj.c.d) { + return true; + } + return false; + } + static testConditionalDeep(o) { + var _o$obj2; + return (_o$obj2 = o.obj) !== null && _o$obj2 !== void 0 && (_o$obj2 = _o$obj2.a.b) !== null && _o$obj2 !== void 0 && _o$obj2.c.d ? true : false; + } + static testLoopDeep(o) { + var _o$obj3; + while ((_o$obj3 = o.obj) !== null && _o$obj3 !== void 0 && _o$obj3.a.b.c.d) { + var _o$obj4; + for (; (_o$obj4 = o.obj) !== null && _o$obj4 !== void 0 && (_o$obj4 = _o$obj4.a.b.c) !== null && _o$obj4 !== void 0 && _o$obj4.d;) { + var _o$obj5; + let i = 0; + do { + i++; + if (i === 2) { + return true; + } + } while ((_o$obj5 = o.obj) !== null && _o$obj5 !== void 0 && (_o$obj5 = _o$obj5.a.b) !== null && _o$obj5 !== void 0 && _o$obj5.c.d); + } + } + return false; + } + static testNegateDeep(o) { + var _o$obj6; + return !!((_o$obj6 = o.obj) !== null && _o$obj6 !== void 0 && (_o$obj6 = _o$obj6.a.b) !== null && _o$obj6 !== void 0 && _o$obj6.c.d); + } + static testLogicalInIf(o) { + var _o$a$b4, _o$a; + if (o !== null && o !== void 0 && (_o$a$b4 = o.a.b) !== null && _o$a$b4 !== void 0 && _o$a$b4.c.d && o !== null && o !== void 0 && (_o$a = o.a) !== null && _o$a !== void 0 && _o$a.b.c.d) { + return true; + } + return false; + } + static testLogicalInReturn(o) { + var _o$a$b5, _o$a2; + return (o === null || o === void 0 || (_o$a$b5 = o.a.b) === null || _o$a$b5 === void 0 ? void 0 : _o$a$b5.c.d) && (o === null || o === void 0 || (_o$a2 = o.a) === null || _o$a2 === void 0 ? void 0 : _o$a2.b.c.d); + } + static testNullishCoalescing(o) { + var _o$a$b$c$non_existent, _o$a$b6, _o$a$b7, _o$a$b$c$non_existent3, _o$a$b10; + if ((_o$a$b$c$non_existent = o === null || o === void 0 || (_o$a$b6 = o.a.b) === null || _o$a$b6 === void 0 ? void 0 : _o$a$b6.c.non_existent) !== null && _o$a$b$c$non_existent !== void 0 ? _o$a$b$c$non_existent : o === null || o === void 0 || (_o$a$b7 = o.a.b) === null || _o$a$b7 === void 0 ? void 0 : _o$a$b7.c.d) { + var _o$a$b$c$non_existent2, _o$a$b8, _o$a$b9; + return (_o$a$b$c$non_existent2 = o === null || o === void 0 || (_o$a$b8 = o.a.b) === null || _o$a$b8 === void 0 ? void 0 : _o$a$b8.c.non_existent) !== null && _o$a$b$c$non_existent2 !== void 0 ? _o$a$b$c$non_existent2 : o === null || o === void 0 || (_o$a$b9 = o.a.b) === null || _o$a$b9 === void 0 ? void 0 : _o$a$b9.c.d; + } + return (_o$a$b$c$non_existent3 = o === null || o === void 0 || (_o$a$b10 = o.a.b) === null || _o$a$b10 === void 0 ? void 0 : _o$a$b10.c.non_existent) !== null && _o$a$b$c$non_existent3 !== void 0 ? _o$a$b$c$non_existent3 : o; + } +} +C.test(); +C.testNullish(); diff --git a/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/containers/output.js b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/containers/output.js new file mode 100644 index 00000000000000..d832b5f890d940 --- /dev/null +++ b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/containers/output.js @@ -0,0 +1,6 @@ +var _user$address, _user$address2, _a, _a2, _a3; +var street = (_user$address = user.address) === null || _user$address === void 0 ? void 0 : _user$address.street; +street = (_user$address2 = user.address) === null || _user$address2 === void 0 ? void 0 : _user$address2.street; +test((_a = a) === null || _a === void 0 ? void 0 : _a.b, 1); +test((_a2 = a) === null || _a2 === void 0 ? void 0 : _a2.b, 1); +1, (_a3 = a) !== null && _a3 !== void 0 && _a3.b, 2; diff --git a/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/delete-in-function-params/output.js b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/delete-in-function-params/output.js new file mode 100644 index 00000000000000..3a7cce38fc5b8b --- /dev/null +++ b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/delete-in-function-params/output.js @@ -0,0 +1,4 @@ +function f(x = (() => { + var _a; + return (_a = a()) === null || _a === void 0 || delete _a.b; +})()) {} diff --git a/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/delete/output.js b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/delete/output.js new file mode 100644 index 00000000000000..21fd3f5d94e823 --- /dev/null +++ b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/delete/output.js @@ -0,0 +1,7 @@ +"use strict"; +var _obj$a, _obj$b; +const obj = { a: { b: 0 } }; +let test = obj === null || obj === void 0 || (_obj$a = obj.a) === null || _obj$a === void 0 || delete _obj$a.b; +test = obj === null || obj === void 0 || delete obj.a.b; +test = obj === null || obj === void 0 || (_obj$b = obj.b) === null || _obj$b === void 0 || delete _obj$b.b; +obj === null || obj === void 0 || delete obj.a; diff --git a/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/function-call-loose/output.js b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/function-call-loose/output.js new file mode 100644 index 00000000000000..77a7bf101d214f --- /dev/null +++ b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/function-call-loose/output.js @@ -0,0 +1,5 @@ +var _foo, _foo2, _foo$bar, _foo3, _foo4, _foo4$bar; +(_foo = foo) === null || _foo === void 0 || _foo(foo); +(_foo2 = foo) === null || _foo2 === void 0 || _foo2.bar(); +(_foo$bar = (_foo3 = foo).bar) === null || _foo$bar === void 0 || _foo$bar.call(_foo3, foo.bar, false); +(_foo4 = foo) === null || _foo4 === void 0 || (_foo4$bar = _foo4.bar) === null || _foo4$bar === void 0 || _foo4$bar.call(_foo4, foo.bar, true); diff --git a/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/function-call-spread/output.js b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/function-call-spread/output.js new file mode 100644 index 00000000000000..1966f0a31ea613 --- /dev/null +++ b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/function-call-spread/output.js @@ -0,0 +1,5 @@ +var _a, _a2, _a3, _a4; +(_a = a) === null || _a === void 0 || _a(...args); +(_a2 = a) === null || _a2 === void 0 || _a2.b(...args); +(_a3 = a) === null || _a3 === void 0 || _a3.b(...args).c; +(_a4 = a) === null || _a4 === void 0 || _a4.b(...args).c(...args); diff --git a/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/function-call/output.js b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/function-call/output.js new file mode 100644 index 00000000000000..363ae668984f83 --- /dev/null +++ b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/function-call/output.js @@ -0,0 +1,11 @@ +var _foo, _foo2, _foo$bar, _foo3, _foo4, _foo4$bar, _foo5, _foo6, _foo$bar2, _foo7, _foo$bar3, _foo8, _foo9, _foo9$bar, _foo10, _foo10$bar; +(_foo = foo) === null || _foo === void 0 || _foo(foo); +(_foo2 = foo) === null || _foo2 === void 0 || _foo2.bar(); +(_foo$bar = (_foo3 = foo).bar) === null || _foo$bar === void 0 || _foo$bar.call(_foo3, foo.bar, false); +(_foo4 = foo) === null || _foo4 === void 0 || (_foo4$bar = _foo4.bar) === null || _foo4$bar === void 0 || _foo4$bar.call(_foo4, foo.bar, true); +(_foo5 = foo) === null || _foo5 === void 0 || _foo5().bar; +(_foo6 = foo) === null || _foo6 === void 0 || (_foo6 = _foo6()) === null || _foo6 === void 0 || _foo6.bar; +(_foo$bar2 = (_foo7 = foo).bar) === null || _foo$bar2 === void 0 || _foo$bar2.call(_foo7).baz; +(_foo$bar3 = (_foo8 = foo).bar) === null || _foo$bar3 === void 0 || (_foo$bar3 = _foo$bar3.call(_foo8)) === null || _foo$bar3 === void 0 || _foo$bar3.baz; +(_foo9 = foo) === null || _foo9 === void 0 || (_foo9$bar = _foo9.bar) === null || _foo9$bar === void 0 || _foo9$bar.call(_foo9).baz; +(_foo10 = foo) === null || _foo10 === void 0 || (_foo10$bar = _foo10.bar) === null || _foo10$bar === void 0 || (_foo10$bar = _foo10$bar.call(_foo10)) === null || _foo10$bar === void 0 || _foo10$bar.baz; diff --git a/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/in-function-params-loose/output.js b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/in-function-params-loose/output.js new file mode 100644 index 00000000000000..0679618bed97d9 --- /dev/null +++ b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/in-function-params-loose/output.js @@ -0,0 +1,19 @@ +function f(a = (() => { + var _x; + return (_x = x) === null || _x === void 0 ? void 0 : _x.y; +})()) {} +function g({ a, b = (() => { + return a === null || a === void 0 ? void 0 : a.c; +})() }) {} +function h(a, { b = (() => { + var _a$b; + return (_a$b = a.b) === null || _a$b === void 0 || (_a$b = _a$b.c) === null || _a$b === void 0 ? void 0 : _a$b.d.e; +})() }) {} +function i(a, { b = (() => { + var _a$b2; + return (_a$b2 = a.b) === null || _a$b2 === void 0 || (_a$b2 = _a$b2.c) === null || _a$b2 === void 0 ? void 0 : _a$b2.d; +})().e }) {} +function j(a, { b = (() => { + var _a$b3; + return a === null || a === void 0 || (_a$b3 = a.b) === null || _a$b3 === void 0 ? void 0 : _a$b3.c().d.e; +})() }) {} diff --git a/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/in-function-params/output.js b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/in-function-params/output.js new file mode 100644 index 00000000000000..0679618bed97d9 --- /dev/null +++ b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/in-function-params/output.js @@ -0,0 +1,19 @@ +function f(a = (() => { + var _x; + return (_x = x) === null || _x === void 0 ? void 0 : _x.y; +})()) {} +function g({ a, b = (() => { + return a === null || a === void 0 ? void 0 : a.c; +})() }) {} +function h(a, { b = (() => { + var _a$b; + return (_a$b = a.b) === null || _a$b === void 0 || (_a$b = _a$b.c) === null || _a$b === void 0 ? void 0 : _a$b.d.e; +})() }) {} +function i(a, { b = (() => { + var _a$b2; + return (_a$b2 = a.b) === null || _a$b2 === void 0 || (_a$b2 = _a$b2.c) === null || _a$b2 === void 0 ? void 0 : _a$b2.d; +})().e }) {} +function j(a, { b = (() => { + var _a$b3; + return a === null || a === void 0 || (_a$b3 = a.b) === null || _a$b3 === void 0 ? void 0 : _a$b3.c().d.e; +})() }) {} diff --git a/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/in-method-key-loose/output.js b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/in-method-key-loose/output.js new file mode 100644 index 00000000000000..2eb95b8bcb6a69 --- /dev/null +++ b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/in-method-key-loose/output.js @@ -0,0 +1,3 @@ +var _x$y; +let x; +const a = { [(_x$y = x.y) === null || _x$y === void 0 ? void 0 : _x$y.z]() {} }; diff --git a/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/in-method-key/output.js b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/in-method-key/output.js new file mode 100644 index 00000000000000..2eb95b8bcb6a69 --- /dev/null +++ b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/in-method-key/output.js @@ -0,0 +1,3 @@ +var _x$y; +let x; +const a = { [(_x$y = x.y) === null || _x$y === void 0 ? void 0 : _x$y.z]() {} }; diff --git a/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/in-var-destructuring/output.js b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/in-var-destructuring/output.js new file mode 100644 index 00000000000000..e1156527c36727 --- /dev/null +++ b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/in-var-destructuring/output.js @@ -0,0 +1,2 @@ +var _x; +var { a = (_x = x) === null || _x === void 0 ? void 0 : _x.y } = {}; diff --git a/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/member-access/output.js b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/member-access/output.js new file mode 100644 index 00000000000000..cd09ee25e321f1 --- /dev/null +++ b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/member-access/output.js @@ -0,0 +1,11 @@ +var _foo, _a, _a$b, _a$b$c, _orders, _orders2, _client, _orders$client$key, _a2, _c, _a3; +(_foo = foo) === null || _foo === void 0 || _foo.bar; +(_a = a) === null || _a === void 0 || (_a = _a.b.c) === null || _a === void 0 || _a.d.e; +(_a$b = a.b) === null || _a$b === void 0 || (_a$b = _a$b.c.d) === null || _a$b === void 0 || _a$b.e; +(_a$b$c = a.b.c) === null || _a$b$c === void 0 || (_a$b$c = _a$b$c.d) === null || _a$b$c === void 0 || _a$b$c.e; +(_orders = orders) === null || _orders === void 0 || _orders[0].price; +(_orders2 = orders) === null || _orders2 === void 0 || (_orders2 = _orders2[0]) === null || _orders2 === void 0 || _orders2.price; +orders[(_client = client) === null || _client === void 0 ? void 0 : _client.key].price; +(_orders$client$key = orders[client.key]) === null || _orders$client$key === void 0 || _orders$client$key.price; +(0, (_a2 = a) !== null && _a2 !== void 0 && _a2.b).c; +(0, (_c = (0, (_a3 = a) !== null && _a3 !== void 0 && _a3.b).c) !== null && _c !== void 0 && _c.d).e; diff --git a/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/memoize-loose/output.js b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/memoize-loose/output.js new file mode 100644 index 00000000000000..a4a6939178abc7 --- /dev/null +++ b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/memoize-loose/output.js @@ -0,0 +1,18 @@ +function test(foo) { + var _foo$bar, _foo$get, _foo$bar2, _foo$bar3, _foo$bar$baz, _foo$bar$baz2, _foo$bar4, _foo$bar5, _foo$bar6, _foo$bar7, _foo$bar8, _foo$bar8$baz, _foo$bar9, _foo$bar9$baz; + foo === null || foo === void 0 || foo.bar; + foo === null || foo === void 0 || (_foo$bar = foo.bar) === null || _foo$bar === void 0 || _foo$bar.baz; + foo === null || foo === void 0 || foo(foo); + foo === null || foo === void 0 || foo.bar(); + (_foo$get = foo.get(bar)) === null || _foo$get === void 0 || _foo$get(); + (_foo$bar2 = foo.bar()) === null || _foo$bar2 === void 0 || _foo$bar2(); + (_foo$bar3 = foo[bar]()) === null || _foo$bar3 === void 0 || _foo$bar3(); + (_foo$bar$baz = foo.bar().baz) === null || _foo$bar$baz === void 0 || _foo$bar$baz(); + (_foo$bar$baz2 = foo[bar]().baz) === null || _foo$bar$baz2 === void 0 || _foo$bar$baz2(); + (_foo$bar4 = foo.bar) === null || _foo$bar4 === void 0 || _foo$bar4.call(foo, foo.bar, false); + foo === null || foo === void 0 || (_foo$bar5 = foo.bar) === null || _foo$bar5 === void 0 || _foo$bar5.call(foo, foo.bar, true); + (_foo$bar6 = foo.bar) === null || _foo$bar6 === void 0 || _foo$bar6.baz(foo.bar, false); + foo === null || foo === void 0 || (_foo$bar7 = foo.bar) === null || _foo$bar7 === void 0 || _foo$bar7.baz(foo.bar, true); + (_foo$bar8 = foo.bar) === null || _foo$bar8 === void 0 || (_foo$bar8$baz = _foo$bar8.baz) === null || _foo$bar8$baz === void 0 || _foo$bar8$baz.call(_foo$bar8, foo.bar, false); + foo === null || foo === void 0 || (_foo$bar9 = foo.bar) === null || _foo$bar9 === void 0 || (_foo$bar9$baz = _foo$bar9.baz) === null || _foo$bar9$baz === void 0 || _foo$bar9$baz.call(_foo$bar9, foo.bar, true); +} diff --git a/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/memoize/output.js b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/memoize/output.js new file mode 100644 index 00000000000000..354906c3f97b84 --- /dev/null +++ b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/memoize/output.js @@ -0,0 +1,13 @@ +function test(foo) { + var _foo$bar, _foo$bar2, _foo$bar3, _foo$bar4, _foo$bar5, _foo$bar6, _foo$bar6$baz, _foo$bar7, _foo$bar7$baz; + foo === null || foo === void 0 || foo.bar; + foo === null || foo === void 0 || (_foo$bar = foo.bar) === null || _foo$bar === void 0 || _foo$bar.baz; + foo === null || foo === void 0 || foo(foo); + foo === null || foo === void 0 || foo.bar(); + (_foo$bar2 = foo.bar) === null || _foo$bar2 === void 0 || _foo$bar2.call(foo, foo.bar, false); + foo === null || foo === void 0 || (_foo$bar3 = foo.bar) === null || _foo$bar3 === void 0 || _foo$bar3.call(foo, foo.bar, true); + (_foo$bar4 = foo.bar) === null || _foo$bar4 === void 0 || _foo$bar4.baz(foo.bar, false); + foo === null || foo === void 0 || (_foo$bar5 = foo.bar) === null || _foo$bar5 === void 0 || _foo$bar5.baz(foo.bar, true); + (_foo$bar6 = foo.bar) === null || _foo$bar6 === void 0 || (_foo$bar6$baz = _foo$bar6.baz) === null || _foo$bar6$baz === void 0 || _foo$bar6$baz.call(_foo$bar6, foo.bar, false); + foo === null || foo === void 0 || (_foo$bar7 = foo.bar) === null || _foo$bar7 === void 0 || (_foo$bar7$baz = _foo$bar7.baz) === null || _foo$bar7$baz === void 0 || _foo$bar7$baz.call(_foo$bar7, foo.bar, true); +} diff --git a/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/optional-eval-call-loose/output.js b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/optional-eval-call-loose/output.js new file mode 100644 index 00000000000000..8ccdc51087fa53 --- /dev/null +++ b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/optional-eval-call-loose/output.js @@ -0,0 +1,10 @@ +var _eval, _eval2, _foo$eval, _eval$foo; +var foo; +eval === null || eval === void 0 || (0, eval)(foo); +eval === null || eval === void 0 || (0, eval)(foo); +eval === null || eval === void 0 || (0, eval)()(); +eval === null || eval === void 0 || (0, eval)().foo; +(_eval = eval()) === null || _eval === void 0 || _eval(); +(_eval2 = eval()) === null || _eval2 === void 0 || _eval2.foo; +(_foo$eval = foo.eval) === null || _foo$eval === void 0 || _foo$eval.call(foo, foo); +(_eval$foo = eval.foo) === null || _eval$foo === void 0 || _eval$foo.call(eval, foo); diff --git a/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/optional-eval-call/output.js b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/optional-eval-call/output.js new file mode 100644 index 00000000000000..8ccdc51087fa53 --- /dev/null +++ b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/optional-eval-call/output.js @@ -0,0 +1,10 @@ +var _eval, _eval2, _foo$eval, _eval$foo; +var foo; +eval === null || eval === void 0 || (0, eval)(foo); +eval === null || eval === void 0 || (0, eval)(foo); +eval === null || eval === void 0 || (0, eval)()(); +eval === null || eval === void 0 || (0, eval)().foo; +(_eval = eval()) === null || _eval === void 0 || _eval(); +(_eval2 = eval()) === null || _eval2 === void 0 || _eval2.foo; +(_foo$eval = foo.eval) === null || _foo$eval === void 0 || _foo$eval.call(foo, foo); +(_eval$foo = eval.foo) === null || _eval$foo === void 0 || _eval$foo.call(eval, foo); diff --git a/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/parenthesized-expression-containers/output.js b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/parenthesized-expression-containers/output.js new file mode 100644 index 00000000000000..d832b5f890d940 --- /dev/null +++ b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/parenthesized-expression-containers/output.js @@ -0,0 +1,6 @@ +var _user$address, _user$address2, _a, _a2, _a3; +var street = (_user$address = user.address) === null || _user$address === void 0 ? void 0 : _user$address.street; +street = (_user$address2 = user.address) === null || _user$address2 === void 0 ? void 0 : _user$address2.street; +test((_a = a) === null || _a === void 0 ? void 0 : _a.b, 1); +test((_a2 = a) === null || _a2 === void 0 ? void 0 : _a2.b, 1); +1, (_a3 = a) !== null && _a3 !== void 0 && _a3.b, 2; diff --git a/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/parenthesized-member-call-loose/output.js b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/parenthesized-member-call-loose/output.js new file mode 100644 index 00000000000000..99e98cc63a9d98 --- /dev/null +++ b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/parenthesized-member-call-loose/output.js @@ -0,0 +1,31 @@ +class Foo { + constructor() { + this.x = 1; + this.self = this; + } + m() { + return this.x; + } + getSelf() { + return this; + } + test() { + var _o$Foo, _o$Foo2, _o$Foo3, _o$Foo4, _o$Foo$self, _fn, _fn$Foo$self; + const Foo = this; + const o = { Foo }; + const fn = function() { + return o; + }; + (Foo === null || Foo === void 0 ? void 0 : Foo["m"].bind(Foo))(); + (Foo === null || Foo === void 0 ? void 0 : Foo["m"].bind(Foo))().toString; + (Foo === null || Foo === void 0 ? void 0 : Foo["m"].bind(Foo))().toString(); + (o === null || o === void 0 ? void 0 : (_o$Foo = o.Foo).m.bind(_o$Foo))(); + (o === null || o === void 0 ? void 0 : (_o$Foo2 = o.Foo).m.bind(_o$Foo2))().toString; + (o === null || o === void 0 ? void 0 : (_o$Foo3 = o.Foo).m.bind(_o$Foo3))().toString(); + ((_o$Foo4 = o.Foo) === null || _o$Foo4 === void 0 || (_o$Foo4 = _o$Foo4.self.getSelf()) === null || _o$Foo4 === void 0 ? void 0 : _o$Foo4.m.bind(_o$Foo4))(); + ((_o$Foo$self = o.Foo.self) === null || _o$Foo$self === void 0 || (_o$Foo$self = _o$Foo$self.getSelf()) === null || _o$Foo$self === void 0 ? void 0 : _o$Foo$self.m.bind(_o$Foo$self))(); + ((_fn = fn()) === null || _fn === void 0 || (_fn = _fn.Foo) === null || _fn === void 0 || (_fn = _fn.self.getSelf()) === null || _fn === void 0 ? void 0 : _fn.m.bind(_fn))(); + (fn === null || fn === void 0 || (_fn$Foo$self = fn().Foo.self) === null || _fn$Foo$self === void 0 || (_fn$Foo$self = _fn$Foo$self.getSelf()) === null || _fn$Foo$self === void 0 ? void 0 : _fn$Foo$self.m.bind(_fn$Foo$self))(); + } +} +new Foo().test(); diff --git a/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/parenthesized-member-call/output.js b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/parenthesized-member-call/output.js new file mode 100644 index 00000000000000..99e98cc63a9d98 --- /dev/null +++ b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/parenthesized-member-call/output.js @@ -0,0 +1,31 @@ +class Foo { + constructor() { + this.x = 1; + this.self = this; + } + m() { + return this.x; + } + getSelf() { + return this; + } + test() { + var _o$Foo, _o$Foo2, _o$Foo3, _o$Foo4, _o$Foo$self, _fn, _fn$Foo$self; + const Foo = this; + const o = { Foo }; + const fn = function() { + return o; + }; + (Foo === null || Foo === void 0 ? void 0 : Foo["m"].bind(Foo))(); + (Foo === null || Foo === void 0 ? void 0 : Foo["m"].bind(Foo))().toString; + (Foo === null || Foo === void 0 ? void 0 : Foo["m"].bind(Foo))().toString(); + (o === null || o === void 0 ? void 0 : (_o$Foo = o.Foo).m.bind(_o$Foo))(); + (o === null || o === void 0 ? void 0 : (_o$Foo2 = o.Foo).m.bind(_o$Foo2))().toString; + (o === null || o === void 0 ? void 0 : (_o$Foo3 = o.Foo).m.bind(_o$Foo3))().toString(); + ((_o$Foo4 = o.Foo) === null || _o$Foo4 === void 0 || (_o$Foo4 = _o$Foo4.self.getSelf()) === null || _o$Foo4 === void 0 ? void 0 : _o$Foo4.m.bind(_o$Foo4))(); + ((_o$Foo$self = o.Foo.self) === null || _o$Foo$self === void 0 || (_o$Foo$self = _o$Foo$self.getSelf()) === null || _o$Foo$self === void 0 ? void 0 : _o$Foo$self.m.bind(_o$Foo$self))(); + ((_fn = fn()) === null || _fn === void 0 || (_fn = _fn.Foo) === null || _fn === void 0 || (_fn = _fn.self.getSelf()) === null || _fn === void 0 ? void 0 : _fn.m.bind(_fn))(); + (fn === null || fn === void 0 || (_fn$Foo$self = fn().Foo.self) === null || _fn$Foo$self === void 0 || (_fn$Foo$self = _fn$Foo$self.getSelf()) === null || _fn$Foo$self === void 0 ? void 0 : _fn$Foo$self.m.bind(_fn$Foo$self))(); + } +} +new Foo().test(); diff --git a/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/super-method-call-loose/output.js b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/super-method-call-loose/output.js new file mode 100644 index 00000000000000..5d425d69fb1014 --- /dev/null +++ b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/super-method-call-loose/output.js @@ -0,0 +1,12 @@ +"use strict"; +class Base { + method() { + return "Hello!"; + } +} +class Derived extends Base { + method() { + var _super$method; + return (_super$method = super.method) === null || _super$method === void 0 ? void 0 : _super$method.call(this); + } +} diff --git a/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/super-method-call/output.js b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/super-method-call/output.js new file mode 100644 index 00000000000000..5d425d69fb1014 --- /dev/null +++ b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/super-method-call/output.js @@ -0,0 +1,12 @@ +"use strict"; +class Base { + method() { + return "Hello!"; + } +} +class Derived extends Base { + method() { + var _super$method; + return (_super$method = super.method) === null || _super$method === void 0 ? void 0 : _super$method.call(this); + } +} diff --git a/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/unary/output.js b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/unary/output.js new file mode 100644 index 00000000000000..ea6001e7a1aaa8 --- /dev/null +++ b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/general/unary/output.js @@ -0,0 +1,7 @@ +"use strict"; +var _obj$a, _obj$b, _obj$b2; +const obj = { a: { b: 0 } }; +let test = +(obj === null || obj === void 0 || (_obj$a = obj.a) === null || _obj$a === void 0 ? void 0 : _obj$a.b); +test = +(obj === null || obj === void 0 ? void 0 : obj.a.b); +test = +(obj === null || obj === void 0 || (_obj$b = obj.b) === null || _obj$b === void 0 ? void 0 : _obj$b.b); +test = +(obj === null || obj === void 0 || (_obj$b2 = obj.b) === null || _obj$b2 === void 0 ? void 0 : _obj$b2.b); diff --git a/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/loose/cast-to-boolean/output.js b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/loose/cast-to-boolean/output.js new file mode 100644 index 00000000000000..07ff93c77a22fb --- /dev/null +++ b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/loose/cast-to-boolean/output.js @@ -0,0 +1,85 @@ +class C { + static testIf(o) { + if (o !== null && o !== void 0 && o.a.b.c.d) { + return true; + } + return false; + } + static testConditional(o) { + var _o$a$b; + return o !== null && o !== void 0 && (_o$a$b = o.a.b) !== null && _o$a$b !== void 0 && _o$a$b.c.d ? true : false; + } + static testLoop(o) { + while (o !== null && o !== void 0 && o.a.b.c.d) { + var _o$a$b$c; + for (; o !== null && o !== void 0 && (_o$a$b$c = o.a.b.c) !== null && _o$a$b$c !== void 0 && _o$a$b$c.d;) { + var _o$a$b2; + let i = 0; + do { + i++; + if (i === 2) { + return true; + } + } while (o !== null && o !== void 0 && (_o$a$b2 = o.a.b) !== null && _o$a$b2 !== void 0 && _o$a$b2.c.d); + } + } + return false; + } + static testNegate(o) { + var _o$a$b3; + return !!(o !== null && o !== void 0 && (_o$a$b3 = o.a.b) !== null && _o$a$b3 !== void 0 && _o$a$b3.c.d); + } + static testIfDeep(o) { + var _o$obj; + if ((_o$obj = o.obj) !== null && _o$obj !== void 0 && (_o$obj = _o$obj.a.b) !== null && _o$obj !== void 0 && _o$obj.c.d) { + return true; + } + return false; + } + static testConditionalDeep(o) { + var _o$obj2; + return (_o$obj2 = o.obj) !== null && _o$obj2 !== void 0 && (_o$obj2 = _o$obj2.a.b) !== null && _o$obj2 !== void 0 && _o$obj2.c.d ? true : false; + } + static testLoopDeep(o) { + var _o$obj3; + while ((_o$obj3 = o.obj) !== null && _o$obj3 !== void 0 && _o$obj3.a.b.c.d) { + var _o$obj4; + for (; (_o$obj4 = o.obj) !== null && _o$obj4 !== void 0 && (_o$obj4 = _o$obj4.a.b.c) !== null && _o$obj4 !== void 0 && _o$obj4.d;) { + var _o$obj5; + let i = 0; + do { + i++; + if (i === 2) { + return true; + } + } while ((_o$obj5 = o.obj) !== null && _o$obj5 !== void 0 && (_o$obj5 = _o$obj5.a.b) !== null && _o$obj5 !== void 0 && _o$obj5.c.d); + } + } + return false; + } + static testNegateDeep(o) { + var _o$obj6; + return !!((_o$obj6 = o.obj) !== null && _o$obj6 !== void 0 && (_o$obj6 = _o$obj6.a.b) !== null && _o$obj6 !== void 0 && _o$obj6.c.d); + } + static testLogicalInIf(o) { + var _o$a$b4, _o$a; + if (o !== null && o !== void 0 && (_o$a$b4 = o.a.b) !== null && _o$a$b4 !== void 0 && _o$a$b4.c.d && o !== null && o !== void 0 && (_o$a = o.a) !== null && _o$a !== void 0 && _o$a.b.c.d) { + return true; + } + return false; + } + static testLogicalInReturn(o) { + var _o$a$b5, _o$a2; + return (o === null || o === void 0 || (_o$a$b5 = o.a.b) === null || _o$a$b5 === void 0 ? void 0 : _o$a$b5.c.d) && (o === null || o === void 0 || (_o$a2 = o.a) === null || _o$a2 === void 0 ? void 0 : _o$a2.b.c.d); + } + static testNullishCoalescing(o) { + var _o$a$b$c$non_existent, _o$a$b6, _o$a$b7, _o$a$b$c$non_existent3, _o$a$b10; + if ((_o$a$b$c$non_existent = o === null || o === void 0 || (_o$a$b6 = o.a.b) === null || _o$a$b6 === void 0 ? void 0 : _o$a$b6.c.non_existent) !== null && _o$a$b$c$non_existent !== void 0 ? _o$a$b$c$non_existent : o === null || o === void 0 || (_o$a$b7 = o.a.b) === null || _o$a$b7 === void 0 ? void 0 : _o$a$b7.c.d) { + var _o$a$b$c$non_existent2, _o$a$b8, _o$a$b9; + return (_o$a$b$c$non_existent2 = o === null || o === void 0 || (_o$a$b8 = o.a.b) === null || _o$a$b8 === void 0 ? void 0 : _o$a$b8.c.non_existent) !== null && _o$a$b$c$non_existent2 !== void 0 ? _o$a$b$c$non_existent2 : o === null || o === void 0 || (_o$a$b9 = o.a.b) === null || _o$a$b9 === void 0 ? void 0 : _o$a$b9.c.d; + } + return (_o$a$b$c$non_existent3 = o === null || o === void 0 || (_o$a$b10 = o.a.b) === null || _o$a$b10 === void 0 ? void 0 : _o$a$b10.c.non_existent) !== null && _o$a$b$c$non_existent3 !== void 0 ? _o$a$b$c$non_existent3 : o; + } +} +C.test(); +C.testNullish(); diff --git a/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/regression/10959-transform-optional-chaining/output.js b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/regression/10959-transform-optional-chaining/output.js new file mode 100644 index 00000000000000..638821ab7d2179 --- /dev/null +++ b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/regression/10959-transform-optional-chaining/output.js @@ -0,0 +1,9 @@ +var _a, _a2, _a3, _b, _a4, _a5, _a6; +(_a = a) === null || _a === void 0 || _a.b.c; +(_a2 = a) === null || _a2 === void 0 || _a2.b.c.d; +(_a3 = a) === null || _a3 === void 0 || _a3.b.c.d; +(_b = a.b) === null || _b === void 0 || _b.c; +(_a4 = a) === null || _a4 === void 0 || (_a4 = _a4.b) === null || _a4 === void 0 || _a4.c; +(_a5 = a) === null || _a5 === void 0 || (_a5 = _a5.b.c) === null || _a5 === void 0 || _a5.c; +a?.b.c; +((_a6 = a) === null || _a6 === void 0 ? void 0 : _a6.b).c; diff --git a/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/regression/10959-transform-ts-and-optional-chaining/output.js b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/regression/10959-transform-ts-and-optional-chaining/output.js new file mode 100644 index 00000000000000..638821ab7d2179 --- /dev/null +++ b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/regression/10959-transform-ts-and-optional-chaining/output.js @@ -0,0 +1,9 @@ +var _a, _a2, _a3, _b, _a4, _a5, _a6; +(_a = a) === null || _a === void 0 || _a.b.c; +(_a2 = a) === null || _a2 === void 0 || _a2.b.c.d; +(_a3 = a) === null || _a3 === void 0 || _a3.b.c.d; +(_b = a.b) === null || _b === void 0 || _b.c; +(_a4 = a) === null || _a4 === void 0 || (_a4 = _a4.b) === null || _a4 === void 0 || _a4.c; +(_a5 = a) === null || _a5 === void 0 || (_a5 = _a5.b.c) === null || _a5 === void 0 || _a5.c; +a?.b.c; +((_a6 = a) === null || _a6 === void 0 ? void 0 : _a6.b).c; diff --git a/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/regression/10959-transform-ts/output.js b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/regression/10959-transform-ts/output.js new file mode 100644 index 00000000000000..2a250c1de1224b --- /dev/null +++ b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/regression/10959-transform-ts/output.js @@ -0,0 +1,8 @@ +a?.b.c; +a?.b.c.d; +a?.b.c.d; +a.b?.c; +a?.b?.c; +a?.b.c?.c; +a?.b.c; +(a?.b).c; diff --git a/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/regression/15887/output.js b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/regression/15887/output.js new file mode 100644 index 00000000000000..34610243aa655a --- /dev/null +++ b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/regression/15887/output.js @@ -0,0 +1,3 @@ +var _ref, _ref2; +let a = ((_ref = null) !== null && _ref !== void 0 && _ref.prop1, (_ref2 = null) !== null && _ref2 !== void 0 && _ref2.prop2); +expect(a).toBe(undefined); diff --git a/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/regression/7642/output.js b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/regression/7642/output.js new file mode 100644 index 00000000000000..32833270a97f28 --- /dev/null +++ b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/regression/7642/output.js @@ -0,0 +1,7 @@ +{ + const foo = 1; +} +{ + var _ref; + const foo = (_ref = {}) === null || _ref === void 0 ? void 0 : _ref.foo; +} diff --git a/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/transparent-expr-wrappers/ts-as-call-context-in-if/output.js b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/transparent-expr-wrappers/ts-as-call-context-in-if/output.js new file mode 100644 index 00000000000000..5235deaa876966 --- /dev/null +++ b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/transparent-expr-wrappers/ts-as-call-context-in-if/output.js @@ -0,0 +1,4 @@ +(a) => { + var _a$b; + if ((_a$b = a.b) !== null && _a$b !== void 0 && _a$b.call(a)) {} +}; diff --git a/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/transparent-expr-wrappers/ts-as-call-context/output.js b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/transparent-expr-wrappers/ts-as-call-context/output.js new file mode 100644 index 00000000000000..ffc9f0eb2aa1b3 --- /dev/null +++ b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/transparent-expr-wrappers/ts-as-call-context/output.js @@ -0,0 +1,2 @@ +var _a$b, _a; +(_a$b = (_a = a).b) === null || _a$b === void 0 || _a$b.call(_a); diff --git a/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/transparent-expr-wrappers/ts-as-function-call-loose/output.js b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/transparent-expr-wrappers/ts-as-function-call-loose/output.js new file mode 100644 index 00000000000000..ea7b3d99effb35 --- /dev/null +++ b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/transparent-expr-wrappers/ts-as-function-call-loose/output.js @@ -0,0 +1,2 @@ +var _bar; +(_bar = foo.bar) === null || _bar === void 0 || _bar(foo.bar, false); diff --git a/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/transparent-expr-wrappers/ts-as-in-conditional/output.js b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/transparent-expr-wrappers/ts-as-in-conditional/output.js new file mode 100644 index 00000000000000..4e87c3ebfa54f4 --- /dev/null +++ b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/transparent-expr-wrappers/ts-as-in-conditional/output.js @@ -0,0 +1,4 @@ +(a) => { + var _a$c; + (a === null || a === void 0 ? void 0 : a.b) && ((_a$c = a.c) === null || _a$c === void 0 ? void 0 : _a$c.d) ? 0 : 1; +}; diff --git a/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/transparent-expr-wrappers/ts-as-member-expression/output.js b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/transparent-expr-wrappers/ts-as-member-expression/output.js new file mode 100644 index 00000000000000..cacf0d0a8abeff --- /dev/null +++ b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/transparent-expr-wrappers/ts-as-member-expression/output.js @@ -0,0 +1,2 @@ +var _a; +(_a = a) === null || _a === void 0 || (_a = _a.b) === null || _a === void 0 || _a.c; diff --git a/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/transparent-expr-wrappers/ts-parenthesized-expression-member-call/output.js b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/transparent-expr-wrappers/ts-parenthesized-expression-member-call/output.js new file mode 100644 index 00000000000000..1bcaf9e41078ce --- /dev/null +++ b/tasks/transform_conformance/snapshots/babel-plugin-transform-optional-chaining/test/fixtures/transparent-expr-wrappers/ts-parenthesized-expression-member-call/output.js @@ -0,0 +1,2 @@ +var _o, _o$Foo; +((_o = o) === null || _o === void 0 ? void 0 : (_o$Foo = _o.Foo).m.bind(_o$Foo))(); diff --git a/tasks/transform_conformance/src/test_case.rs b/tasks/transform_conformance/src/test_case.rs index bac60cc023ebcc..7e2d582aca296d 100644 --- a/tasks/transform_conformance/src/test_case.rs +++ b/tasks/transform_conformance/src/test_case.rs @@ -383,7 +383,9 @@ test("exec", () => {{ Ok(code) => code, Err(error) => error, }; - let path = snap_root().join(self.path.strip_prefix(packages_root()).unwrap()); + let mut path = snap_root().join(self.path.strip_prefix(packages_root()).unwrap()); + path.set_file_name("output"); + path.set_extension(&self.path.extension().unwrap().to_string_lossy().replace("t", "j")); if filtered { println!("Input path: {:?}", &self.path); println!("Output path: {path:?}");