diff --git a/crates/swc/src/builder.rs b/crates/swc/src/builder.rs index 45fbaa764b7..86a3f3cd70a 100644 --- a/crates/swc/src/builder.rs +++ b/crates/swc/src/builder.rs @@ -233,15 +233,18 @@ impl<'a, 'b, P: swc_ecma_visit::Fold> PassBuilder<'a, 'b, P> { should_enable(self.target, EsVersion::Es2021) ), Optional::new( - compat::es2020::es2020(compat::es2020::Config { - nullish_coalescing: compat::es2020::nullish_coalescing::Config { - no_document_all: assumptions.no_document_all + compat::es2020::es2020( + compat::es2020::Config { + nullish_coalescing: compat::es2020::nullish_coalescing::Config { + no_document_all: assumptions.no_document_all + }, + optional_chaining: compat::es2020::optional_chaining::Config { + no_document_all: assumptions.no_document_all, + pure_getter: assumptions.pure_getters + } }, - optional_chaining: compat::es2020::optional_chaining::Config { - no_document_all: assumptions.no_document_all, - pure_getter: assumptions.pure_getters - } - }), + self.unresolved_mark + ), should_enable(self.target, EsVersion::Es2020) ), Optional::new( diff --git a/crates/swc/tests/fixture/issues-3xxx/3381/1/output/index.ts b/crates/swc/tests/fixture/issues-3xxx/3381/1/output/index.ts index 2dc6af8e048..c5ba4901d20 100644 --- a/crates/swc/tests/fixture/issues-3xxx/3381/1/output/index.ts +++ b/crates/swc/tests/fixture/issues-3xxx/3381/1/output/index.ts @@ -5,15 +5,13 @@ var dummyTsFunction = function() { 2 ]; var func1 = function(array) { - var // Mapping array - _array; - return (_array = array) === null || _array === void 0 ? void 0 : _array.map(function(i) { + return(// Mapping array + array === null || array === void 0 ? void 0 : array.map(function(i) { return i; - }); + })); }; var func2 = function(array) { - var _array; - return (_array = array) === null || _array === void 0 ? void 0 : _array.map(function(i) { + return array === null || array === void 0 ? void 0 : array.map(function(i) { return i; }); }; diff --git a/crates/swc/tests/fixture/issues-4xxx/4108/1/output/index.ts b/crates/swc/tests/fixture/issues-4xxx/4108/1/output/index.ts index 661f66b41eb..7e8937e27b1 100644 --- a/crates/swc/tests/fixture/issues-4xxx/4108/1/output/index.ts +++ b/crates/swc/tests/fixture/issues-4xxx/4108/1/output/index.ts @@ -8,7 +8,7 @@ import { Transaction } from "@solana/web3.js"; import { WalletNotConnectedError } from "@solana/wallet-adapter-base"; export var getErrorForTransaction = function() { var _ref = _async_to_generator(function(connection, txid) { - var _tx, tx, errors; + var tx, errors; return _ts_generator(this, function(_state) { switch(_state.label){ case 0: @@ -26,7 +26,7 @@ export var getErrorForTransaction = function() { case 2: tx = _state.sent(); errors = []; - if (((_tx = tx) === null || _tx === void 0 ? void 0 : _tx.meta) && tx.meta.logMessages) { + if ((tx === null || tx === void 0 ? void 0 : tx.meta) && tx.meta.logMessages) { tx.meta.logMessages.forEach(function(log) { var regex = /Error: (.*)/gm; var m; @@ -366,7 +366,7 @@ export var sendTransactions = function() { }(); export var sendTransaction = function() { var _ref = _async_to_generator(function(connection, wallet, instructions, signers) { - var awaitConfirmation, commitment, includesFeePayer, block, transaction, _tmp, _transaction, _transaction1, _transaction2, rawTransaction, options, txid, slot, _confirmation, _confirmation1, confirmation, errors; + var awaitConfirmation, commitment, includesFeePayer, block, transaction, _tmp, _transaction, _transaction1, _transaction2, rawTransaction, options, txid, slot, confirmation, errors; var _arguments = arguments; return _ts_generator(this, function(_state) { switch(_state.label){ @@ -454,8 +454,8 @@ export var sendTransaction = function() { case 7: confirmation = _state.sent(); if (!confirmation) throw new Error("Timed out awaiting confirmation on transaction"); - slot = ((_confirmation = confirmation) === null || _confirmation === void 0 ? void 0 : _confirmation.slot) || 0; - if (!((_confirmation1 = confirmation) === null || _confirmation1 === void 0 ? void 0 : _confirmation1.err)) return [ + slot = (confirmation === null || confirmation === void 0 ? void 0 : confirmation.slot) || 0; + if (!(confirmation === null || confirmation === void 0 ? void 0 : confirmation.err)) return [ 3, 9 ]; @@ -574,7 +574,7 @@ export function sendSignedTransaction(_) { } function _sendSignedTransaction() { _sendSignedTransaction = _async_to_generator(function(param) { - var signedTransaction, connection, _param_timeout, timeout, rawTransaction, startTime, slot, txid, done, _confirmation, confirmation, err, simulateResult, e, i, line; + var signedTransaction, connection, _param_timeout, timeout, rawTransaction, startTime, slot, txid, done, confirmation, err, simulateResult, e, i, line; return _ts_generator(this, function(_state) { switch(_state.label){ case 0: @@ -639,7 +639,7 @@ function _sendSignedTransaction() { console.error(confirmation.err); throw new Error("Transaction failed: Custom instruction error"); } - slot = ((_confirmation = confirmation) === null || _confirmation === void 0 ? void 0 : _confirmation.slot) || 0; + slot = (confirmation === null || confirmation === void 0 ? void 0 : confirmation.slot) || 0; return [ 3, 10 diff --git a/crates/swc/tests/fixture/issues-7xxx/7547/output/1.js b/crates/swc/tests/fixture/issues-7xxx/7547/output/1.js index 947f2dd60c2..867924ecae6 100644 --- a/crates/swc/tests/fixture/issues-7xxx/7547/output/1.js +++ b/crates/swc/tests/fixture/issues-7xxx/7547/output/1.js @@ -1,32 +1,24 @@ // code below dont work -var _a; var a = {}; new Promise(function(r) { - var _a; - r((_a = a) === null || _a === void 0 ? void 0 : _a.b); + r(a === null || a === void 0 ? void 0 : a.b); }).then(function(a) { - var _a; - return (_a = a) === null || _a === void 0 ? void 0 : _a.b; + return a === null || a === void 0 ? void 0 : a.b; }); var anony = function() { - var _a; - return (_a = a) === null || _a === void 0 ? void 0 : _a.b; + return a === null || a === void 0 ? void 0 : a.b; }; // code below works -var b = (_a = a) === null || _a === void 0 ? void 0 : _a.b; +var b = a === null || a === void 0 ? void 0 : a.b; function fn() { - var _a; - return (_a = a) === null || _a === void 0 ? void 0 : _a.b; + return a === null || a === void 0 ? void 0 : a.b; } setTimeout(function() { - var _a; - return (_a = a) === null || _a === void 0 ? void 0 : _a.b; + return a === null || a === void 0 ? void 0 : a.b; }, 0); var anony2 = function anony2() { - var _a; - return (_a = a) === null || _a === void 0 ? void 0 : _a.b; + return a === null || a === void 0 ? void 0 : a.b; }; (function() { - var _a; - return (_a = a) === null || _a === void 0 ? void 0 : _a.b; + return a === null || a === void 0 ? void 0 : a.b; })(); diff --git a/crates/swc/tests/fixture/issues-7xxx/7659/1/output/1.ts b/crates/swc/tests/fixture/issues-7xxx/7659/1/output/1.ts index 81f509133de..ef3129574e5 100644 --- a/crates/swc/tests/fixture/issues-7xxx/7659/1/output/1.ts +++ b/crates/swc/tests/fixture/issues-7xxx/7659/1/output/1.ts @@ -1 +1 @@ -"use strict";var _a;var a=undefined;(_a=a)===null||_a===void 0?void 0:_a.b.c; +"use strict";var a=undefined;a===null||a===void 0?void 0:a.b.c; diff --git a/crates/swc/tests/fixture/issues-7xxx/7659/2/output/1.ts b/crates/swc/tests/fixture/issues-7xxx/7659/2/output/1.ts index 81f509133de..ef3129574e5 100644 --- a/crates/swc/tests/fixture/issues-7xxx/7659/2/output/1.ts +++ b/crates/swc/tests/fixture/issues-7xxx/7659/2/output/1.ts @@ -1 +1 @@ -"use strict";var _a;var a=undefined;(_a=a)===null||_a===void 0?void 0:_a.b.c; +"use strict";var a=undefined;a===null||a===void 0?void 0:a.b.c; diff --git a/crates/swc/tests/fixture/next.js/shared/lib/router/1/output/index.ts b/crates/swc/tests/fixture/next.js/shared/lib/router/1/output/index.ts index 819839704a6..293ffaeb47c 100644 --- a/crates/swc/tests/fixture/next.js/shared/lib/router/1/output/index.ts +++ b/crates/swc/tests/fixture/next.js/shared/lib/router/1/output/index.ts @@ -13,7 +13,7 @@ var Router = /*#__PURE__*/ function() { value: function change(method, url, as, options, forcedScroll) { var _this = this; return _async_to_generator(function() { - var shouldResolveHref, prevLocale, parsedAs, localePathResult, didNavigate, _this_locales, detectedDomain, asNoBasePath, _options_shallow, shallow, routeProps, cleanedAs, localeChange, parsed, pathname, query, pages, rewrites, ref, err, resolvedAs, rewritesResult, route, parsedAs1, asPathname, routeRegex, routeMatch, shouldInterpolate, interpolatedAs, missingParams, _self___NEXT_DATA___props_pageProps, _self___NEXT_DATA___props, _props, routeInfo, error, props, __N_SSG, __N_SSP, destination, parsedHref, _prepareUrlAs, newUrl, newAs, notFoundRoute, _, isValidShallowRoute, _options_scroll, shouldScroll, resetScroll, err1; + var shouldResolveHref, prevLocale, parsedAs, localePathResult, didNavigate, _this_locales, detectedDomain, asNoBasePath, _options_shallow, shallow, routeProps, cleanedAs, localeChange, parsed, pathname, query, pages, rewrites, ref, err, resolvedAs, rewritesResult, route, parsedAs1, asPathname, routeRegex, routeMatch, shouldInterpolate, interpolatedAs, missingParams, _self___NEXT_DATA___props_pageProps, _self___NEXT_DATA___props, routeInfo, error, props, __N_SSG, __N_SSP, destination, parsedHref, _prepareUrlAs, newUrl, newAs, notFoundRoute, _, isValidShallowRoute, _options_scroll, shouldScroll, resetScroll, err1; return _ts_generator(this, function(_state) { switch(_state.label){ case 0: @@ -312,7 +312,7 @@ var Router = /*#__PURE__*/ function() { case 13: Router.events.emit("beforeHistoryChange", as, routeProps); _this.changeState(method, url, as, options); - if (options._h && pathname === "/_error" && ((_self___NEXT_DATA___props = self.__NEXT_DATA__.props) === null || _self___NEXT_DATA___props === void 0 ? void 0 : (_self___NEXT_DATA___props_pageProps = _self___NEXT_DATA___props.pageProps) === null || _self___NEXT_DATA___props_pageProps === void 0 ? void 0 : _self___NEXT_DATA___props_pageProps.statusCode) === 500 && ((_props = props) === null || _props === void 0 ? void 0 : _props.pageProps)) { + if (options._h && pathname === "/_error" && ((_self___NEXT_DATA___props = self.__NEXT_DATA__.props) === null || _self___NEXT_DATA___props === void 0 ? void 0 : (_self___NEXT_DATA___props_pageProps = _self___NEXT_DATA___props.pageProps) === null || _self___NEXT_DATA___props_pageProps === void 0 ? void 0 : _self___NEXT_DATA___props_pageProps.statusCode) === 500 && (props === null || props === void 0 ? void 0 : props.pageProps)) { // ensure statusCode is still correct for static 500 page // when updating query information props.pageProps.statusCode = 500; diff --git a/crates/swc/tests/tsc-references/callChain.1.normal.js b/crates/swc/tests/tsc-references/callChain.1.normal.js index b2af47b385b..4de61c93230 100644 --- a/crates/swc/tests/tsc-references/callChain.1.normal.js +++ b/crates/swc/tests/tsc-references/callChain.1.normal.js @@ -1,86 +1,86 @@ //// [callChain.ts] var _o2, _o21, _o22, _o23, _o3_b, _o3_b1, _o3_b2, _o3_b3, _o3_b4, _o3_b5; -var _o1, _o11, _o12, _o13, _o24, _o25, _o26, _o27, _o28, _o29, _o210, _o211, _o3_b6, _o3, _o3_b7, _o31, _o3_b8, _o32, _o3_b9, _o33, _o3_b10, _o34, _o3_b11, _o35, _o3_b12, _o36, _o3_b13, _o37, _o3_b14, _o38, _o3_b15, _o39, _o3_b16, _o310, _o3_b17, _o311, _o4, _o5, // GH#36031 -_o212, _o213; -(_o1 = o1) === null || _o1 === void 0 ? void 0 : _o1(); -(_o11 = o1) === null || _o11 === void 0 ? void 0 : _o11(1); -(_o12 = o1) === null || _o12 === void 0 ? void 0 : _o12.apply(void 0, [ +var _o3_b6, _o3_b7, _o3_b8, _o3_b9, _o3_b10, _o3_b11, _o3_b12, _o3_b13, _o3_b14, _o3_b15, _o3_b16, _o3_b17, _o5; +o1 === null || o1 === void 0 ? void 0 : o1(); +o1 === null || o1 === void 0 ? void 0 : o1(1); +o1 === null || o1 === void 0 ? void 0 : o1.apply(void 0, [ 1, 2 ]); -(_o13 = o1) === null || _o13 === void 0 ? void 0 : _o13.apply(void 0, [ +o1 === null || o1 === void 0 ? void 0 : o1.apply(void 0, [ 1, 2, 3, 4 ]); -(_o24 = o2) === null || _o24 === void 0 ? void 0 : _o24.b(); -(_o25 = o2) === null || _o25 === void 0 ? void 0 : _o25.b(1); -(_o26 = o2) === null || _o26 === void 0 ? void 0 : (_o2 = _o26).b.apply(_o2, [ +o2 === null || o2 === void 0 ? void 0 : o2.b(); +o2 === null || o2 === void 0 ? void 0 : o2.b(1); +o2 === null || o2 === void 0 ? void 0 : (_o2 = o2).b.apply(_o2, [ 1, 2 ]); -(_o27 = o2) === null || _o27 === void 0 ? void 0 : (_o21 = _o27).b.apply(_o21, [ +o2 === null || o2 === void 0 ? void 0 : (_o21 = o2).b.apply(_o21, [ 1, 2, 3, 4 ]); -(_o28 = o2) === null || _o28 === void 0 ? void 0 : _o28["b"](); -(_o29 = o2) === null || _o29 === void 0 ? void 0 : _o29["b"](1); -(_o210 = o2) === null || _o210 === void 0 ? void 0 : (_o22 = _o210)["b"].apply(_o22, [ +o2 === null || o2 === void 0 ? void 0 : o2["b"](); +o2 === null || o2 === void 0 ? void 0 : o2["b"](1); +o2 === null || o2 === void 0 ? void 0 : (_o22 = o2)["b"].apply(_o22, [ 1, 2 ]); -(_o211 = o2) === null || _o211 === void 0 ? void 0 : (_o23 = _o211)["b"].apply(_o23, [ +o2 === null || o2 === void 0 ? void 0 : (_o23 = o2)["b"].apply(_o23, [ 1, 2, 3, 4 ]); -(_o3_b6 = (_o3 = o3).b) === null || _o3_b6 === void 0 ? void 0 : _o3_b6.call(_o3).c; -(_o3_b7 = (_o31 = o3).b) === null || _o3_b7 === void 0 ? void 0 : _o3_b7.call(_o31, 1).c; -(_o3_b8 = (_o32 = o3).b) === null || _o3_b8 === void 0 ? void 0 : (_o3_b = _o3_b8).call.apply(_o3_b, [ - _o32, +(_o3_b6 = o3.b) === null || _o3_b6 === void 0 ? void 0 : _o3_b6.call(o3).c; +(_o3_b7 = o3.b) === null || _o3_b7 === void 0 ? void 0 : _o3_b7.call(o3, 1).c; +(_o3_b8 = o3.b) === null || _o3_b8 === void 0 ? void 0 : (_o3_b = _o3_b8).call.apply(_o3_b, [ + o3, 1, 2 ]).c; -(_o3_b9 = (_o33 = o3).b) === null || _o3_b9 === void 0 ? void 0 : (_o3_b1 = _o3_b9).call.apply(_o3_b1, [ - _o33, +(_o3_b9 = o3.b) === null || _o3_b9 === void 0 ? void 0 : (_o3_b1 = _o3_b9).call.apply(_o3_b1, [ + o3, 1, 2, 3, 4 ]).c; -(_o3_b10 = (_o34 = o3).b) === null || _o3_b10 === void 0 ? void 0 : _o3_b10.call(_o34)["c"]; -(_o3_b11 = (_o35 = o3).b) === null || _o3_b11 === void 0 ? void 0 : _o3_b11.call(_o35, 1)["c"]; -(_o3_b12 = (_o36 = o3).b) === null || _o3_b12 === void 0 ? void 0 : (_o3_b2 = _o3_b12).call.apply(_o3_b2, [ - _o36, +(_o3_b10 = o3.b) === null || _o3_b10 === void 0 ? void 0 : _o3_b10.call(o3)["c"]; +(_o3_b11 = o3.b) === null || _o3_b11 === void 0 ? void 0 : _o3_b11.call(o3, 1)["c"]; +(_o3_b12 = o3.b) === null || _o3_b12 === void 0 ? void 0 : (_o3_b2 = _o3_b12).call.apply(_o3_b2, [ + o3, 1, 2 ])["c"]; -(_o3_b13 = (_o37 = o3).b) === null || _o3_b13 === void 0 ? void 0 : (_o3_b3 = _o3_b13).call.apply(_o3_b3, [ - _o37, +(_o3_b13 = o3.b) === null || _o3_b13 === void 0 ? void 0 : (_o3_b3 = _o3_b13).call.apply(_o3_b3, [ + o3, 1, 2, 3, 4 ])["c"]; -(_o3_b14 = (_o38 = o3)["b"]) === null || _o3_b14 === void 0 ? void 0 : _o3_b14.call(_o38).c; -(_o3_b15 = (_o39 = o3)["b"]) === null || _o3_b15 === void 0 ? void 0 : _o3_b15.call(_o39, 1).c; -(_o3_b16 = (_o310 = o3)["b"]) === null || _o3_b16 === void 0 ? void 0 : (_o3_b4 = _o3_b16).call.apply(_o3_b4, [ - _o310, +(_o3_b14 = o3["b"]) === null || _o3_b14 === void 0 ? void 0 : _o3_b14.call(o3).c; +(_o3_b15 = o3["b"]) === null || _o3_b15 === void 0 ? void 0 : _o3_b15.call(o3, 1).c; +(_o3_b16 = o3["b"]) === null || _o3_b16 === void 0 ? void 0 : (_o3_b4 = _o3_b16).call.apply(_o3_b4, [ + o3, 1, 2 ]).c; -(_o3_b17 = (_o311 = o3)["b"]) === null || _o3_b17 === void 0 ? void 0 : (_o3_b5 = _o3_b17).call.apply(_o3_b5, [ - _o311, +(_o3_b17 = o3["b"]) === null || _o3_b17 === void 0 ? void 0 : (_o3_b5 = _o3_b17).call.apply(_o3_b5, [ + o3, 1, 2, 3, 4 ]).c; -var v = (_o4 = o4) === null || _o4 === void 0 ? void 0 : _o4(incr); +var v = o4 === null || o4 === void 0 ? void 0 : o4(incr); (_o5 = o5()) === null || _o5 === void 0 ? void 0 : _o5(); -(_o212 = o2) === null || _o212 === void 0 ? void 0 : _o212.b().toString; -(_o213 = o2) === null || _o213 === void 0 ? void 0 : _o213.b().toString; +// GH#36031 +o2 === null || o2 === void 0 ? void 0 : o2.b().toString; +o2 === null || o2 === void 0 ? void 0 : o2.b().toString; diff --git a/crates/swc/tests/tsc-references/callChain.2.1.normal.js b/crates/swc/tests/tsc-references/callChain.2.1.normal.js index eacdd8b3100..3bbc5c0421f 100644 --- a/crates/swc/tests/tsc-references/callChain.2.1.normal.js +++ b/crates/swc/tests/tsc-references/callChain.2.1.normal.js @@ -1,5 +1,5 @@ //// [callChain.2.ts] -var _o1, _o2, _o3_b, _o3; -(_o1 = o1) === null || _o1 === void 0 ? void 0 : _o1(); -(_o2 = o2) === null || _o2 === void 0 ? void 0 : _o2.b(); -(_o3_b = (_o3 = o3).b) === null || _o3_b === void 0 ? void 0 : _o3_b.call(_o3).c; +var _o3_b; +o1 === null || o1 === void 0 ? void 0 : o1(); +o2 === null || o2 === void 0 ? void 0 : o2.b(); +(_o3_b = o3.b) === null || _o3_b === void 0 ? void 0 : _o3_b.call(o3).c; diff --git a/crates/swc/tests/tsc-references/callChain.2.2.minified.js b/crates/swc/tests/tsc-references/callChain.2.2.minified.js index aaf2e8f210b..f6718e2799c 100644 --- a/crates/swc/tests/tsc-references/callChain.2.2.minified.js +++ b/crates/swc/tests/tsc-references/callChain.2.2.minified.js @@ -1,3 +1,3 @@ //// [callChain.2.ts] -var _o1, _o2, _o3_b, _o3; -null === (_o1 = o1) || void 0 === _o1 || _o1(), null === (_o2 = o2) || void 0 === _o2 || _o2.b(), null === (_o3_b = (_o3 = o3).b) || void 0 === _o3_b || _o3_b.call(_o3).c; +var _o3_b; +null == o1 || o1(), null == o2 || o2.b(), null === (_o3_b = o3.b) || void 0 === _o3_b || _o3_b.call(o3).c; diff --git a/crates/swc/tests/tsc-references/callChain.2.minified.js b/crates/swc/tests/tsc-references/callChain.2.minified.js index 1b5200b606e..1a7e93d99ba 100644 --- a/crates/swc/tests/tsc-references/callChain.2.minified.js +++ b/crates/swc/tests/tsc-references/callChain.2.minified.js @@ -1,58 +1,58 @@ //// [callChain.ts] -var _o1, _o11, _o12, _o13, _o24, _o25, _o26, _o27, _o28, _o29, _o210, _o211, _o3_b6, _o3, _o3_b7, _o31, _o3_b8, _o32, _o3_b9, _o33, _o3_b10, _o34, _o3_b11, _o35, _o3_b12, _o36, _o3_b13, _o37, _o3_b14, _o38, _o3_b15, _o39, _o3_b16, _o310, _o3_b17, _o311, _o4, _o5, // GH#36031 -_o212, _o213; -null === (_o1 = o1) || void 0 === _o1 || _o1(), null === (_o11 = o1) || void 0 === _o11 || _o11(1), null === (_o12 = o1) || void 0 === _o12 || _o12.apply(void 0, [ +var _o2, _o21, _o22, _o23, _o3_b6, _o3_b7, _o3_b8, _o3_b9, _o3_b10, _o3_b11, _o3_b12, _o3_b13, _o3_b14, _o3_b15, _o3_b16, _o3_b17, _o5; +null == o1 || o1(), null == o1 || o1(1), null == o1 || o1.apply(void 0, [ 1, 2 -]), null === (_o13 = o1) || void 0 === _o13 || _o13.apply(void 0, [ +]), null == o1 || o1.apply(void 0, [ 1, 2, 3, 4 -]), null === (_o24 = o2) || void 0 === _o24 || _o24.b(), null === (_o25 = o2) || void 0 === _o25 || _o25.b(1), null === (_o26 = o2) || void 0 === _o26 || _o26.b.apply(_o26, [ +]), null == o2 || o2.b(), null == o2 || o2.b(1), null == o2 || (_o2 = o2).b.apply(_o2, [ 1, 2 -]), null === (_o27 = o2) || void 0 === _o27 || _o27.b.apply(_o27, [ +]), null == o2 || (_o21 = o2).b.apply(_o21, [ 1, 2, 3, 4 -]), null === (_o28 = o2) || void 0 === _o28 || _o28.b(), null === (_o29 = o2) || void 0 === _o29 || _o29.b(1), null === (_o210 = o2) || void 0 === _o210 || _o210.b.apply(_o210, [ +]), null == o2 || o2.b(), null == o2 || o2.b(1), null == o2 || (_o22 = o2).b.apply(_o22, [ 1, 2 -]), null === (_o211 = o2) || void 0 === _o211 || _o211.b.apply(_o211, [ +]), null == o2 || (_o23 = o2).b.apply(_o23, [ 1, 2, 3, 4 -]), null === (_o3_b6 = (_o3 = o3).b) || void 0 === _o3_b6 || _o3_b6.call(_o3).c, null === (_o3_b7 = (_o31 = o3).b) || void 0 === _o3_b7 || _o3_b7.call(_o31, 1).c, null === (_o3_b8 = (_o32 = o3).b) || void 0 === _o3_b8 || _o3_b8.call.apply(_o3_b8, [ - _o32, +]), null === (_o3_b6 = o3.b) || void 0 === _o3_b6 || _o3_b6.call(o3).c, null === (_o3_b7 = o3.b) || void 0 === _o3_b7 || _o3_b7.call(o3, 1).c, null === (_o3_b8 = o3.b) || void 0 === _o3_b8 || _o3_b8.call.apply(_o3_b8, [ + o3, 1, 2 -]).c, null === (_o3_b9 = (_o33 = o3).b) || void 0 === _o3_b9 || _o3_b9.call.apply(_o3_b9, [ - _o33, +]).c, null === (_o3_b9 = o3.b) || void 0 === _o3_b9 || _o3_b9.call.apply(_o3_b9, [ + o3, 1, 2, 3, 4 -]).c, null === (_o3_b10 = (_o34 = o3).b) || void 0 === _o3_b10 || _o3_b10.call(_o34).c, null === (_o3_b11 = (_o35 = o3).b) || void 0 === _o3_b11 || _o3_b11.call(_o35, 1).c, null === (_o3_b12 = (_o36 = o3).b) || void 0 === _o3_b12 || _o3_b12.call.apply(_o3_b12, [ - _o36, +]).c, null === (_o3_b10 = o3.b) || void 0 === _o3_b10 || _o3_b10.call(o3).c, null === (_o3_b11 = o3.b) || void 0 === _o3_b11 || _o3_b11.call(o3, 1).c, null === (_o3_b12 = o3.b) || void 0 === _o3_b12 || _o3_b12.call.apply(_o3_b12, [ + o3, 1, 2 -]).c, null === (_o3_b13 = (_o37 = o3).b) || void 0 === _o3_b13 || _o3_b13.call.apply(_o3_b13, [ - _o37, +]).c, null === (_o3_b13 = o3.b) || void 0 === _o3_b13 || _o3_b13.call.apply(_o3_b13, [ + o3, 1, 2, 3, 4 -]).c, null === (_o3_b14 = (_o38 = o3).b) || void 0 === _o3_b14 || _o3_b14.call(_o38).c, null === (_o3_b15 = (_o39 = o3).b) || void 0 === _o3_b15 || _o3_b15.call(_o39, 1).c, null === (_o3_b16 = (_o310 = o3).b) || void 0 === _o3_b16 || _o3_b16.call.apply(_o3_b16, [ - _o310, +]).c, null === (_o3_b14 = o3.b) || void 0 === _o3_b14 || _o3_b14.call(o3).c, null === (_o3_b15 = o3.b) || void 0 === _o3_b15 || _o3_b15.call(o3, 1).c, null === (_o3_b16 = o3.b) || void 0 === _o3_b16 || _o3_b16.call.apply(_o3_b16, [ + o3, 1, 2 -]).c, null === (_o3_b17 = (_o311 = o3).b) || void 0 === _o3_b17 || _o3_b17.call.apply(_o3_b17, [ - _o311, +]).c, null === (_o3_b17 = o3.b) || void 0 === _o3_b17 || _o3_b17.call.apply(_o3_b17, [ + o3, 1, 2, 3, 4 -]).c, null === (_o4 = o4) || void 0 === _o4 || _o4(incr), null === (_o5 = o5()) || void 0 === _o5 || _o5(), null === (_o212 = o2) || void 0 === _o212 || _o212.b().toString, null === (_o213 = o2) || void 0 === _o213 || _o213.b().toString; +]).c, null == o4 || o4(incr), null === (_o5 = o5()) || void 0 === _o5 || _o5(), null == // GH#36031 +o2 || o2.b().toString, null == o2 || o2.b().toString; diff --git a/crates/swc/tests/tsc-references/callChain.3.1.normal.js b/crates/swc/tests/tsc-references/callChain.3.1.normal.js index 5af3e27f2b1..c8e1c745cc2 100644 --- a/crates/swc/tests/tsc-references/callChain.3.1.normal.js +++ b/crates/swc/tests/tsc-references/callChain.3.1.normal.js @@ -1,19 +1,19 @@ //// [callChain.3.ts] -var _a_m, _a, _a_m1, _a1, _a_m2, _a2, _a_m3, _a3, _a_m4, _a4; -var n1 = (_a = a) === null || _a === void 0 ? void 0 : (_a_m = _a.m) === null || _a_m === void 0 ? void 0 : _a_m.call(_a, { +var _a_m, _a_m1, _a_m2, _a_m3, _a_m4; +var n1 = a === null || a === void 0 ? void 0 : (_a_m = a.m) === null || _a_m === void 0 ? void 0 : _a_m.call(a, { x: 12 }); // should be an error (`undefined` is not assignable to `number`) -var n2 = (_a1 = a) === null || _a1 === void 0 ? void 0 : (_a_m1 = _a1.m) === null || _a_m1 === void 0 ? void 0 : _a_m1.call(_a1, { +var n2 = a === null || a === void 0 ? void 0 : (_a_m1 = a.m) === null || _a_m1 === void 0 ? void 0 : _a_m1.call(a, { x: absorb() }); // likewise -var n3 = (_a2 = a) === null || _a2 === void 0 ? void 0 : (_a_m2 = _a2.m) === null || _a_m2 === void 0 ? void 0 : _a_m2.call(_a2, { +var n3 = a === null || a === void 0 ? void 0 : (_a_m2 = a.m) === null || _a_m2 === void 0 ? void 0 : _a_m2.call(a, { x: 12 }); // should be ok -var n4 = (_a3 = a) === null || _a3 === void 0 ? void 0 : (_a_m3 = _a3.m) === null || _a_m3 === void 0 ? void 0 : _a_m3.call(_a3, { +var n4 = a === null || a === void 0 ? void 0 : (_a_m3 = a.m) === null || _a_m3 === void 0 ? void 0 : _a_m3.call(a, { x: absorb() }); // likewise // Also a test showing `!` vs `?` for good measure -var t1 = (_a4 = a) === null || _a4 === void 0 ? void 0 : (_a_m4 = _a4.m) === null || _a_m4 === void 0 ? void 0 : _a_m4.call(_a4, { +var t1 = a === null || a === void 0 ? void 0 : (_a_m4 = a.m) === null || _a_m4 === void 0 ? void 0 : _a_m4.call(a, { x: 12 }); t1 = a.m({ diff --git a/crates/swc/tests/tsc-references/callChain.3.2.minified.js b/crates/swc/tests/tsc-references/callChain.3.2.minified.js index 0f5e69dbfc9..f18c49f9686 100644 --- a/crates/swc/tests/tsc-references/callChain.3.2.minified.js +++ b/crates/swc/tests/tsc-references/callChain.3.2.minified.js @@ -1,15 +1,15 @@ //// [callChain.3.ts] // Also a test showing `!` vs `?` for good measure -var _a_m, _a, _a_m1, _a1, _a_m2, _a2, _a_m3, _a3, _a_m4, _a4; -null === (_a = a) || void 0 === _a || null === (_a_m = _a.m) || void 0 === _a_m || _a_m.call(_a, { +var _a_m, _a_m1, _a_m2, _a_m3, _a_m4; +null == a || null === (_a_m = a.m) || void 0 === _a_m || _a_m.call(a, { x: 12 -}), null === (_a1 = a) || void 0 === _a1 || null === (_a_m1 = _a1.m) || void 0 === _a_m1 || _a_m1.call(_a1, { +}), null == a || null === (_a_m1 = a.m) || void 0 === _a_m1 || _a_m1.call(a, { x: absorb() -}), null === (_a2 = a) || void 0 === _a2 || null === (_a_m2 = _a2.m) || void 0 === _a_m2 || _a_m2.call(_a2, { +}), null == a || null === (_a_m2 = a.m) || void 0 === _a_m2 || _a_m2.call(a, { x: 12 -}), null === (_a3 = a) || void 0 === _a3 || null === (_a_m3 = _a3.m) || void 0 === _a_m3 || _a_m3.call(_a3, { +}), null == a || null === (_a_m3 = a.m) || void 0 === _a_m3 || _a_m3.call(a, { x: absorb() -}), null === (_a4 = a) || void 0 === _a4 || null === (_a_m4 = _a4.m) || void 0 === _a_m4 || _a_m4.call(_a4, { +}), null == a || null === (_a_m4 = a.m) || void 0 === _a_m4 || _a_m4.call(a, { x: 12 }), a.m({ x: 12 diff --git a/crates/swc/tests/tsc-references/callChainInference.1.normal.js b/crates/swc/tests/tsc-references/callChainInference.1.normal.js index 3c74c34c0d8..045ee5d9a33 100644 --- a/crates/swc/tests/tsc-references/callChainInference.1.normal.js +++ b/crates/swc/tests/tsc-references/callChainInference.1.normal.js @@ -1,8 +1,6 @@ //// [callChainInference.ts] // Repro from #42404 -var _value; if (value) { - var _value1; - (_value1 = value) === null || _value1 === void 0 ? void 0 : _value1.foo("a"); + value === null || value === void 0 ? void 0 : value.foo("a"); } -(_value = value) === null || _value === void 0 ? void 0 : _value.foo("a"); +value === null || value === void 0 ? void 0 : value.foo("a"); diff --git a/crates/swc/tests/tsc-references/callChainInference.2.minified.js b/crates/swc/tests/tsc-references/callChainInference.2.minified.js index 194e1db2c4f..32c22446523 100644 --- a/crates/swc/tests/tsc-references/callChainInference.2.minified.js +++ b/crates/swc/tests/tsc-references/callChainInference.2.minified.js @@ -1,4 +1,3 @@ //// [callChainInference.ts] // Repro from #42404 -var _value, _value1; -value && (null === (_value1 = value) || void 0 === _value1 || _value1.foo("a")), null === (_value = value) || void 0 === _value || _value.foo("a"); +value && (null == value || value.foo("a")), null == value || value.foo("a"); diff --git a/crates/swc/tests/tsc-references/controlFlowOptionalChain.1.normal.js b/crates/swc/tests/tsc-references/controlFlowOptionalChain.1.normal.js index e24531e4225..d55e065cab6 100644 --- a/crates/swc/tests/tsc-references/controlFlowOptionalChain.1.normal.js +++ b/crates/swc/tests/tsc-references/controlFlowOptionalChain.1.normal.js @@ -2,20 +2,20 @@ // assignments in shortcutting chain import { _ as _instanceof } from "@swc/helpers/_/_instanceof"; import { _ as _type_of } from "@swc/helpers/_/_type_of"; -var _o, _o1, _o2, _o3, _f, _o21, _o22, _o31, _o32, _o4_x, _o4_x1, _o5_x_y_z, _o5_x, _o5_x1, _o5_x2, _o5_x_y_z1, _o5_x3, _o6, _o61, _arr_i; +var _o4_x, _o4_x1, _o5_x_y_z, _o5_x, _o5_x1, _o5_x2, _o5_x_y_z1, _o5_x3, _arr_i; var a; -(_o = o) === null || _o === void 0 ? void 0 : _o[a = 1]; +o === null || o === void 0 ? void 0 : o[a = 1]; a.toString(); var b; -(_o1 = o) === null || _o1 === void 0 ? void 0 : _o1.x[b = 1]; +o === null || o === void 0 ? void 0 : o.x[b = 1]; b.toString(); var c; -(_o2 = o) === null || _o2 === void 0 ? void 0 : _o2(c = 1); +o === null || o === void 0 ? void 0 : o(c = 1); c.toString(); var d; -(_o3 = o) === null || _o3 === void 0 ? void 0 : _o3.x(d = 1); +o === null || o === void 0 ? void 0 : o.x(d = 1); d.toString(); -if ((_f = f) === null || _f === void 0 ? void 0 : _f(x)) { +if (f === null || f === void 0 ? void 0 : f(x)) { x; // number f; // (x: any) => x is number f(x); @@ -27,36 +27,32 @@ if ((_f = f) === null || _f === void 0 ? void 0 : _f(x)) { x; f; f(x); -if ((_o21 = o2) === null || _o21 === void 0 ? void 0 : _o21.f(x)) { - var _o23, _o24; +if (o2 === null || o2 === void 0 ? void 0 : o2.f(x)) { x; // number o2.f; // (x: any) => x is number - (_o23 = o2) === null || _o23 === void 0 ? void 0 : _o23.f; - (_o24 = o2) === null || _o24 === void 0 ? void 0 : _o24.f(x); + o2 === null || o2 === void 0 ? void 0 : o2.f; + o2 === null || o2 === void 0 ? void 0 : o2.f(x); } else { - var _o25; x; o2; - (_o25 = o2) === null || _o25 === void 0 ? void 0 : _o25.f; + o2 === null || o2 === void 0 ? void 0 : o2.f; o2.f; } x; o2; -(_o22 = o2) === null || _o22 === void 0 ? void 0 : _o22.f; +o2 === null || o2 === void 0 ? void 0 : o2.f; o2.f; -if (((_o31 = o3) === null || _o31 === void 0 ? void 0 : _o31.x) === 1) { - var _o33; +if ((o3 === null || o3 === void 0 ? void 0 : o3.x) === 1) { o3; o3.x; - (_o33 = o3) === null || _o33 === void 0 ? void 0 : _o33.x; + o3 === null || o3 === void 0 ? void 0 : o3.x; } else { - var _o34; o3; - (_o34 = o3) === null || _o34 === void 0 ? void 0 : _o34.x; + o3 === null || o3 === void 0 ? void 0 : o3.x; o3.x; } o3; -(_o32 = o3) === null || _o32 === void 0 ? void 0 : _o32.x; +o3 === null || o3 === void 0 ? void 0 : o3.x; o3.x; if ((_o4_x = o4.x) === null || _o4_x === void 0 ? void 0 : _o4_x.y) { var _o4_x2; @@ -96,319 +92,300 @@ o5.x; (_o5_x3 = o5.x) === null || _o5_x3 === void 0 ? void 0 : (_o5_x_y_z1 = _o5_x3.y.z) === null || _o5_x_y_z1 === void 0 ? void 0 : _o5_x_y_z1.w; o5.x.y; o5.x.y.z.w; -if ((_o6 = o6) === null || _o6 === void 0 ? void 0 : _o6.f()) { +if (o6 === null || o6 === void 0 ? void 0 : o6.f()) { o6; // Derived o6.f; } else { - var _o62; o6; - (_o62 = o6) === null || _o62 === void 0 ? void 0 : _o62.f; + o6 === null || o6 === void 0 ? void 0 : o6.f; o6.f; } o6; -(_o61 = o6) === null || _o61 === void 0 ? void 0 : _o61.f; +o6 === null || o6 === void 0 ? void 0 : o6.f; o6.f; function f01(x1) { if (!!true) { - var _isString; - (_isString = isString) === null || _isString === void 0 ? void 0 : _isString(x1); + isString === null || isString === void 0 ? void 0 : isString(x1); x1; } if (!!true) { - var _maybeIsString; - (_maybeIsString = maybeIsString) === null || _maybeIsString === void 0 ? void 0 : _maybeIsString(x1); + maybeIsString === null || maybeIsString === void 0 ? void 0 : maybeIsString(x1); x1; } if (!!true) { - var _maybeIsString1; isDefined(maybeIsString); - (_maybeIsString1 = maybeIsString) === null || _maybeIsString1 === void 0 ? void 0 : _maybeIsString1(x1); + maybeIsString === null || maybeIsString === void 0 ? void 0 : maybeIsString(x1); x1; } if (!!true) { - var _maybeNever; - (_maybeNever = maybeNever) === null || _maybeNever === void 0 ? void 0 : _maybeNever(); + maybeNever === null || maybeNever === void 0 ? void 0 : maybeNever(); x1; } } function f10(o1, value) { - var _o, _o1, _o2, _o3, _o4, _o5; - if (((_o = o1) === null || _o === void 0 ? void 0 : _o.foo) === value) { + if ((o1 === null || o1 === void 0 ? void 0 : o1.foo) === value) { o1.foo; } - if (((_o1 = o1) === null || _o1 === void 0 ? void 0 : _o1["foo"]) === value) { + if ((o1 === null || o1 === void 0 ? void 0 : o1["foo"]) === value) { o1["foo"]; } - if (((_o2 = o1) === null || _o2 === void 0 ? void 0 : _o2.bar()) === value) { + if ((o1 === null || o1 === void 0 ? void 0 : o1.bar()) === value) { o1.bar; } - if (((_o3 = o1) === null || _o3 === void 0 ? void 0 : _o3.foo) == value) { + if ((o1 === null || o1 === void 0 ? void 0 : o1.foo) == value) { o1.foo; } - if (((_o4 = o1) === null || _o4 === void 0 ? void 0 : _o4["foo"]) == value) { + if ((o1 === null || o1 === void 0 ? void 0 : o1["foo"]) == value) { o1["foo"]; } - if (((_o5 = o1) === null || _o5 === void 0 ? void 0 : _o5.bar()) == value) { + if ((o1 === null || o1 === void 0 ? void 0 : o1.bar()) == value) { o1.bar; } } function f11(o1, value) { - var _o, _o1, _o2, _o3, _o4, _o5; - if (((_o = o1) === null || _o === void 0 ? void 0 : _o.foo) === value) { + if ((o1 === null || o1 === void 0 ? void 0 : o1.foo) === value) { o1.foo; } - if (((_o1 = o1) === null || _o1 === void 0 ? void 0 : _o1["foo"]) === value) { + if ((o1 === null || o1 === void 0 ? void 0 : o1["foo"]) === value) { o1["foo"]; } - if (((_o2 = o1) === null || _o2 === void 0 ? void 0 : _o2.bar()) === value) { + if ((o1 === null || o1 === void 0 ? void 0 : o1.bar()) === value) { o1.bar; } - if (((_o3 = o1) === null || _o3 === void 0 ? void 0 : _o3.foo) == value) { + if ((o1 === null || o1 === void 0 ? void 0 : o1.foo) == value) { o1.foo; } - if (((_o4 = o1) === null || _o4 === void 0 ? void 0 : _o4["foo"]) == value) { + if ((o1 === null || o1 === void 0 ? void 0 : o1["foo"]) == value) { o1["foo"]; } - if (((_o5 = o1) === null || _o5 === void 0 ? void 0 : _o5.bar()) == value) { + if ((o1 === null || o1 === void 0 ? void 0 : o1.bar()) == value) { o1.bar; } } function f12(o1, value) { - var _o, _o1, _o2, _o3, _o4, _o5; - if (((_o = o1) === null || _o === void 0 ? void 0 : _o.foo) === value) { + if ((o1 === null || o1 === void 0 ? void 0 : o1.foo) === value) { o1.foo; // Error } - if (((_o1 = o1) === null || _o1 === void 0 ? void 0 : _o1["foo"]) === value) { + if ((o1 === null || o1 === void 0 ? void 0 : o1["foo"]) === value) { o1["foo"]; // Error } - if (((_o2 = o1) === null || _o2 === void 0 ? void 0 : _o2.bar()) === value) { + if ((o1 === null || o1 === void 0 ? void 0 : o1.bar()) === value) { o1.bar; // Error } - if (((_o3 = o1) === null || _o3 === void 0 ? void 0 : _o3.foo) == value) { + if ((o1 === null || o1 === void 0 ? void 0 : o1.foo) == value) { o1.foo; // Error } - if (((_o4 = o1) === null || _o4 === void 0 ? void 0 : _o4["foo"]) == value) { + if ((o1 === null || o1 === void 0 ? void 0 : o1["foo"]) == value) { o1["foo"]; // Error } - if (((_o5 = o1) === null || _o5 === void 0 ? void 0 : _o5.bar()) == value) { + if ((o1 === null || o1 === void 0 ? void 0 : o1.bar()) == value) { o1.bar; // Error } } function f12a(o1, value) { - var _o, _o1, _o2, _o3, _o4, _o5; - if (((_o = o1) === null || _o === void 0 ? void 0 : _o.foo) === value) { + if ((o1 === null || o1 === void 0 ? void 0 : o1.foo) === value) { o1.foo; } - if (((_o1 = o1) === null || _o1 === void 0 ? void 0 : _o1["foo"]) === value) { + if ((o1 === null || o1 === void 0 ? void 0 : o1["foo"]) === value) { o1["foo"]; } - if (((_o2 = o1) === null || _o2 === void 0 ? void 0 : _o2.bar()) === value) { + if ((o1 === null || o1 === void 0 ? void 0 : o1.bar()) === value) { o1.bar; } - if (((_o3 = o1) === null || _o3 === void 0 ? void 0 : _o3.foo) == value) { + if ((o1 === null || o1 === void 0 ? void 0 : o1.foo) == value) { o1.foo; // Error } - if (((_o4 = o1) === null || _o4 === void 0 ? void 0 : _o4["foo"]) == value) { + if ((o1 === null || o1 === void 0 ? void 0 : o1["foo"]) == value) { o1["foo"]; // Error } - if (((_o5 = o1) === null || _o5 === void 0 ? void 0 : _o5.bar()) == value) { + if ((o1 === null || o1 === void 0 ? void 0 : o1.bar()) == value) { o1.bar; // Error } } function f13(o1) { - var _o, _o1, _o2, _o3, _o4, _o5; - if (((_o = o1) === null || _o === void 0 ? void 0 : _o.foo) !== undefined) { + if ((o1 === null || o1 === void 0 ? void 0 : o1.foo) !== undefined) { o1.foo; } - if (((_o1 = o1) === null || _o1 === void 0 ? void 0 : _o1["foo"]) !== undefined) { + if ((o1 === null || o1 === void 0 ? void 0 : o1["foo"]) !== undefined) { o1["foo"]; } - if (((_o2 = o1) === null || _o2 === void 0 ? void 0 : _o2.bar()) !== undefined) { + if ((o1 === null || o1 === void 0 ? void 0 : o1.bar()) !== undefined) { o1.bar; } - if (((_o3 = o1) === null || _o3 === void 0 ? void 0 : _o3.foo) != undefined) { + if ((o1 === null || o1 === void 0 ? void 0 : o1.foo) != undefined) { o1.foo; } - if (((_o4 = o1) === null || _o4 === void 0 ? void 0 : _o4["foo"]) != undefined) { + if ((o1 === null || o1 === void 0 ? void 0 : o1["foo"]) != undefined) { o1["foo"]; } - if (((_o5 = o1) === null || _o5 === void 0 ? void 0 : _o5.bar()) != undefined) { + if ((o1 === null || o1 === void 0 ? void 0 : o1.bar()) != undefined) { o1.bar; } } function f13a(o1) { - var _o, _o1, _o2, _o3, _o4, _o5; - if (((_o = o1) === null || _o === void 0 ? void 0 : _o.foo) !== null) { + if ((o1 === null || o1 === void 0 ? void 0 : o1.foo) !== null) { o1.foo; // Error } - if (((_o1 = o1) === null || _o1 === void 0 ? void 0 : _o1["foo"]) !== null) { + if ((o1 === null || o1 === void 0 ? void 0 : o1["foo"]) !== null) { o1["foo"]; // Error } - if (((_o2 = o1) === null || _o2 === void 0 ? void 0 : _o2.bar()) !== null) { + if ((o1 === null || o1 === void 0 ? void 0 : o1.bar()) !== null) { o1.bar; // Error } - if (((_o3 = o1) === null || _o3 === void 0 ? void 0 : _o3.foo) != null) { + if ((o1 === null || o1 === void 0 ? void 0 : o1.foo) != null) { o1.foo; } - if (((_o4 = o1) === null || _o4 === void 0 ? void 0 : _o4["foo"]) != null) { + if ((o1 === null || o1 === void 0 ? void 0 : o1["foo"]) != null) { o1["foo"]; } - if (((_o5 = o1) === null || _o5 === void 0 ? void 0 : _o5.bar()) != null) { + if ((o1 === null || o1 === void 0 ? void 0 : o1.bar()) != null) { o1.bar; } } function f14(o1) { - var _o, _o1, _o2; - if (((_o = o1) === null || _o === void 0 ? void 0 : _o.foo) !== undefined) { + if ((o1 === null || o1 === void 0 ? void 0 : o1.foo) !== undefined) { o1.foo; } - if (((_o1 = o1) === null || _o1 === void 0 ? void 0 : _o1["foo"]) !== undefined) { + if ((o1 === null || o1 === void 0 ? void 0 : o1["foo"]) !== undefined) { o1["foo"]; } - if (((_o2 = o1) === null || _o2 === void 0 ? void 0 : _o2.bar()) !== undefined) { + if ((o1 === null || o1 === void 0 ? void 0 : o1.bar()) !== undefined) { o1.bar; } } function f15(o1, value) { - var _o, _o1, _o2, _o3; - if (((_o = o1) === null || _o === void 0 ? void 0 : _o.foo) === value) { + if ((o1 === null || o1 === void 0 ? void 0 : o1.foo) === value) { o1.foo; } else { o1.foo; // Error } - if (((_o1 = o1) === null || _o1 === void 0 ? void 0 : _o1.foo) !== value) { + if ((o1 === null || o1 === void 0 ? void 0 : o1.foo) !== value) { o1.foo; // Error } else { o1.foo; } - if (((_o2 = o1) === null || _o2 === void 0 ? void 0 : _o2.foo) == value) { + if ((o1 === null || o1 === void 0 ? void 0 : o1.foo) == value) { o1.foo; } else { o1.foo; // Error } - if (((_o3 = o1) === null || _o3 === void 0 ? void 0 : _o3.foo) != value) { + if ((o1 === null || o1 === void 0 ? void 0 : o1.foo) != value) { o1.foo; // Error } else { o1.foo; } } function f15a(o1, value) { - var _o, _o1, _o2, _o3; - if (((_o = o1) === null || _o === void 0 ? void 0 : _o.foo) === value) { + if ((o1 === null || o1 === void 0 ? void 0 : o1.foo) === value) { o1.foo; // Error } else { o1.foo; // Error } - if (((_o1 = o1) === null || _o1 === void 0 ? void 0 : _o1.foo) !== value) { + if ((o1 === null || o1 === void 0 ? void 0 : o1.foo) !== value) { o1.foo; // Error } else { o1.foo; // Error } - if (((_o2 = o1) === null || _o2 === void 0 ? void 0 : _o2.foo) == value) { + if ((o1 === null || o1 === void 0 ? void 0 : o1.foo) == value) { o1.foo; // Error } else { o1.foo; // Error } - if (((_o3 = o1) === null || _o3 === void 0 ? void 0 : _o3.foo) != value) { + if ((o1 === null || o1 === void 0 ? void 0 : o1.foo) != value) { o1.foo; // Error } else { o1.foo; // Error } } function f16(o1) { - var _o, _o1, _o2, _o3; - if (((_o = o1) === null || _o === void 0 ? void 0 : _o.foo) === undefined) { + if ((o1 === null || o1 === void 0 ? void 0 : o1.foo) === undefined) { o1.foo; // Error } else { o1.foo; } - if (((_o1 = o1) === null || _o1 === void 0 ? void 0 : _o1.foo) !== undefined) { + if ((o1 === null || o1 === void 0 ? void 0 : o1.foo) !== undefined) { o1.foo; } else { o1.foo; // Error } - if (((_o2 = o1) === null || _o2 === void 0 ? void 0 : _o2.foo) == undefined) { + if ((o1 === null || o1 === void 0 ? void 0 : o1.foo) == undefined) { o1.foo; // Error } else { o1.foo; } - if (((_o3 = o1) === null || _o3 === void 0 ? void 0 : _o3.foo) != undefined) { + if ((o1 === null || o1 === void 0 ? void 0 : o1.foo) != undefined) { o1.foo; } else { o1.foo; // Error } } function f20(o1) { - var _o, _o1, _o2, _o3; - if (typeof ((_o = o1) === null || _o === void 0 ? void 0 : _o.foo) === "number") { + if (typeof (o1 === null || o1 === void 0 ? void 0 : o1.foo) === "number") { o1.foo; } - if (typeof ((_o1 = o1) === null || _o1 === void 0 ? void 0 : _o1["foo"]) === "number") { + if (typeof (o1 === null || o1 === void 0 ? void 0 : o1["foo"]) === "number") { o1["foo"]; } - if (typeof ((_o2 = o1) === null || _o2 === void 0 ? void 0 : _o2.bar()) === "number") { + if (typeof (o1 === null || o1 === void 0 ? void 0 : o1.bar()) === "number") { o1.bar; } - if (_instanceof((_o3 = o1) === null || _o3 === void 0 ? void 0 : _o3.baz, Error)) { + if (_instanceof(o1 === null || o1 === void 0 ? void 0 : o1.baz, Error)) { o1.baz; } } function f21(o1) { - var _o, _o1, _o2, _o3; - if (typeof ((_o = o1) === null || _o === void 0 ? void 0 : _o.foo) === "number") { + if (typeof (o1 === null || o1 === void 0 ? void 0 : o1.foo) === "number") { o1.foo; } - if (typeof ((_o1 = o1) === null || _o1 === void 0 ? void 0 : _o1["foo"]) === "number") { + if (typeof (o1 === null || o1 === void 0 ? void 0 : o1["foo"]) === "number") { o1["foo"]; } - if (typeof ((_o2 = o1) === null || _o2 === void 0 ? void 0 : _o2.bar()) === "number") { + if (typeof (o1 === null || o1 === void 0 ? void 0 : o1.bar()) === "number") { o1.bar; } - if (_instanceof((_o3 = o1) === null || _o3 === void 0 ? void 0 : _o3.baz, Error)) { + if (_instanceof(o1 === null || o1 === void 0 ? void 0 : o1.baz, Error)) { o1.baz; } } function f22(o1) { - var _o, _o1, _o2, _o3; - if (typeof ((_o = o1) === null || _o === void 0 ? void 0 : _o.foo) === "number") { + if (typeof (o1 === null || o1 === void 0 ? void 0 : o1.foo) === "number") { o1.foo; } else { o1.foo; // Error } - if (typeof ((_o1 = o1) === null || _o1 === void 0 ? void 0 : _o1.foo) !== "number") { + if (typeof (o1 === null || o1 === void 0 ? void 0 : o1.foo) !== "number") { o1.foo; // Error } else { o1.foo; } - if (typeof ((_o2 = o1) === null || _o2 === void 0 ? void 0 : _o2.foo) == "number") { + if (typeof (o1 === null || o1 === void 0 ? void 0 : o1.foo) == "number") { o1.foo; } else { o1.foo; // Error } - if (typeof ((_o3 = o1) === null || _o3 === void 0 ? void 0 : _o3.foo) != "number") { + if (typeof (o1 === null || o1 === void 0 ? void 0 : o1.foo) != "number") { o1.foo; // Error } else { o1.foo; } } function f23(o1) { - var _o, _o1, _o2, _o3; - if (typeof ((_o = o1) === null || _o === void 0 ? void 0 : _o.foo) === "undefined") { + if (typeof (o1 === null || o1 === void 0 ? void 0 : o1.foo) === "undefined") { o1.foo; // Error } else { o1.foo; } - if (typeof ((_o1 = o1) === null || _o1 === void 0 ? void 0 : _o1.foo) !== "undefined") { + if (typeof (o1 === null || o1 === void 0 ? void 0 : o1.foo) !== "undefined") { o1.foo; } else { o1.foo; // Error } - if (typeof ((_o2 = o1) === null || _o2 === void 0 ? void 0 : _o2.foo) == "undefined") { + if (typeof (o1 === null || o1 === void 0 ? void 0 : o1.foo) == "undefined") { o1.foo; // Error } else { o1.foo; } - if (typeof ((_o3 = o1) === null || _o3 === void 0 ? void 0 : _o3.foo) != "undefined") { + if (typeof (o1 === null || o1 === void 0 ? void 0 : o1.foo) != "undefined") { o1.foo; } else { o1.foo; // Error @@ -416,29 +393,24 @@ function f23(o1) { } function f30(o1) { if (!!true) { - var _o; - assert((_o = o1) === null || _o === void 0 ? void 0 : _o.foo); + assert(o1 === null || o1 === void 0 ? void 0 : o1.foo); o1.foo; } if (!!true) { - var _o1; - assert(((_o1 = o1) === null || _o1 === void 0 ? void 0 : _o1.foo) === 42); + assert((o1 === null || o1 === void 0 ? void 0 : o1.foo) === 42); o1.foo; } if (!!true) { - var _o2; - assert(typeof ((_o2 = o1) === null || _o2 === void 0 ? void 0 : _o2.foo) === "number"); + assert(typeof (o1 === null || o1 === void 0 ? void 0 : o1.foo) === "number"); o1.foo; } if (!!true) { - var _o3; - assertNonNull((_o3 = o1) === null || _o3 === void 0 ? void 0 : _o3.foo); + assertNonNull(o1 === null || o1 === void 0 ? void 0 : o1.foo); o1.foo; } } function f40(o1) { - var _o; - switch((_o = o1) === null || _o === void 0 ? void 0 : _o.foo){ + switch(o1 === null || o1 === void 0 ? void 0 : o1.foo){ case "abc": o1.foo; break; @@ -454,8 +426,7 @@ function f40(o1) { } } function f41(o1) { - var _o; - switch(_type_of((_o = o1) === null || _o === void 0 ? void 0 : _o.foo)){ + switch(_type_of(o1 === null || o1 === void 0 ? void 0 : o1.foo)){ case "string": o1.foo; break; @@ -471,8 +442,7 @@ function f41(o1) { } } function getArea(shape) { - var _shape; - switch((_shape = shape) === null || _shape === void 0 ? void 0 : _shape.type){ + switch(shape === null || shape === void 0 ? void 0 : shape.type){ case "circle": return Math.PI * Math.pow(shape.radius, 2); case "rectangle": @@ -490,12 +460,10 @@ function extractCoordinates(f1) { } var lastSomeProperty; function someFunction(someOptionalObject) { - var _someOptionalObject; - if (((_someOptionalObject = someOptionalObject) === null || _someOptionalObject === void 0 ? void 0 : _someOptionalObject.someProperty) !== lastSomeProperty) { - var _someOptionalObject1; + if ((someOptionalObject === null || someOptionalObject === void 0 ? void 0 : someOptionalObject.someProperty) !== lastSomeProperty) { console.log(someOptionalObject); console.log(someOptionalObject.someProperty); // Error - lastSomeProperty = (_someOptionalObject1 = someOptionalObject) === null || _someOptionalObject1 === void 0 ? void 0 : _someOptionalObject1.someProperty; + lastSomeProperty = someOptionalObject === null || someOptionalObject === void 0 ? void 0 : someOptionalObject.someProperty; } } var someObject = { diff --git a/crates/swc/tests/tsc-references/controlFlowOptionalChain.2.minified.js b/crates/swc/tests/tsc-references/controlFlowOptionalChain.2.minified.js index 9eda7950fe3..a1c9ba9eb4c 100644 --- a/crates/swc/tests/tsc-references/controlFlowOptionalChain.2.minified.js +++ b/crates/swc/tests/tsc-references/controlFlowOptionalChain.2.minified.js @@ -5,8 +5,8 @@ import "@swc/helpers/_/_type_of"; function someFunction(someOptionalObject) { (null == someOptionalObject ? void 0 : someOptionalObject.someProperty) !== lastSomeProperty && (console.log(someOptionalObject), console.log(someOptionalObject.someProperty), lastSomeProperty = null == someOptionalObject ? void 0 : someOptionalObject.someProperty); } -null === (_o = o) || void 0 === _o || _o[a = 1], a.toString(), null === (_o1 = o) || void 0 === _o1 || _o1.x[b = 1], b.toString(), null === (_o2 = o) || void 0 === _o2 || _o2(c = 1), c.toString(), null === (_o3 = o) || void 0 === _o3 || _o3.x(d = 1), d.toString(), null === (_f = f) || void 0 === _f || _f(x), x, f, f(x), x, f, f(x), (null === (_o21 = o2) || void 0 === _o21 ? void 0 : _o21.f(x)) ? (x, o2.f, null === (_o23 = o2) || void 0 === _o23 || _o23.f, null === (_o24 = o2) || void 0 === _o24 || _o24.f(x)) : (x, o2, null === (_o25 = o2) || void 0 === _o25 || _o25.f, o2.f), x, o2, null === (_o22 = o2) || void 0 === _o22 || _o22.f, o2.f, (null === (_o31 = o3) || void 0 === _o31 ? void 0 : _o31.x) === 1 ? (o3, o3.x, null === (_o33 = o3) || void 0 === _o33 || _o33.x) : (o3, null === (_o34 = o3) || void 0 === _o34 || _o34.x, o3.x), o3, null === (_o32 = o3) || void 0 === _o32 || _o32.x, o3.x, (null === (_o4_x = o4.x) || void 0 === _o4_x ? void 0 : _o4_x.y) ? (o4.x, o4.x.y, null === (_o4_x2 = o4.x) || void 0 === _o4_x2 || _o4_x2.y) : (o4.x, null === (_o4_x3 = o4.x) || void 0 === _o4_x3 || _o4_x3.y, o4.x.y), o4.x, null === (_o4_x1 = o4.x) || void 0 === _o4_x1 || _o4_x1.y, o4.x.y, (null === (_o5_x = o5.x) || void 0 === _o5_x ? void 0 : null === (_o5_x_y_z = _o5_x.y.z) || void 0 === _o5_x_y_z ? void 0 : _o5_x_y_z.w) ? (o5.x, o5.x.y, o5.x.y.z, o5.x.y.z.w, null === (_o5_x_y_z2 = o5.x.y.z) || void 0 === _o5_x_y_z2 || _o5_x_y_z2.w, null === (_o5_x4 = o5.x) || void 0 === _o5_x4 || _o5_x4.y.z.w, null === (_o5_x5 = o5.x) || void 0 === _o5_x5 || null === (_o5_x_y_z3 = _o5_x5.y.z) || void 0 === _o5_x_y_z3 || _o5_x_y_z3.w) : (o5.x, null === (_o5_x6 = o5.x) || void 0 === _o5_x6 || _o5_x6.y, null === (_o5_x7 = o5.x) || void 0 === _o5_x7 || _o5_x7.y.z, null === (_o5_x8 = o5.x) || void 0 === _o5_x8 || null === (_o5_x_y_z4 = _o5_x8.y.z) || void 0 === _o5_x_y_z4 || _o5_x_y_z4.w, o5.x.y, o5.x.y.z.w), o5.x, null === (_o5_x1 = o5.x) || void 0 === _o5_x1 || _o5_x1.y, null === (_o5_x2 = o5.x) || void 0 === _o5_x2 || _o5_x2.y.z, null === (_o5_x3 = o5.x) || void 0 === _o5_x3 || null === (_o5_x_y_z1 = _o5_x3.y.z) || void 0 === _o5_x_y_z1 || _o5_x_y_z1.w, o5.x.y, o5.x.y.z.w, (null === (_o6 = o6) || void 0 === _o6 ? void 0 : _o6.f()) ? o6 : (o6, null === (_o62 = o6) || void 0 === _o62 || _o62.f), o6.f, o6, null === (_o61 = o6) || void 0 === _o61 || _o61.f, o6.f, someFunction({ +null == o || o[a = 1], a.toString(), null == o || o.x[b = 1], b.toString(), null == o || o(c = 1), c.toString(), null == o || o.x(d = 1), d.toString(), null == f || f(x), x, f, f(x), x, f, f(x), (null == o2 ? void 0 : o2.f(x)) ? (x, o2.f, null == o2 || o2.f, null == o2 || o2.f(x)) : (x, o2, null == o2 || o2.f, o2.f), x, o2, null == o2 || o2.f, o2.f, (null == o3 ? void 0 : o3.x) === 1 ? (o3, o3.x, null == o3 || o3.x) : (o3, null == o3 || o3.x, o3.x), o3, null == o3 || o3.x, o3.x, (null === (_o4_x = o4.x) || void 0 === _o4_x ? void 0 : _o4_x.y) ? (o4.x, o4.x.y, null === (_o4_x2 = o4.x) || void 0 === _o4_x2 || _o4_x2.y) : (o4.x, null === (_o4_x3 = o4.x) || void 0 === _o4_x3 || _o4_x3.y, o4.x.y), o4.x, null === (_o4_x1 = o4.x) || void 0 === _o4_x1 || _o4_x1.y, o4.x.y, (null === (_o5_x = o5.x) || void 0 === _o5_x ? void 0 : null === (_o5_x_y_z = _o5_x.y.z) || void 0 === _o5_x_y_z ? void 0 : _o5_x_y_z.w) ? (o5.x, o5.x.y, o5.x.y.z, o5.x.y.z.w, null === (_o5_x_y_z2 = o5.x.y.z) || void 0 === _o5_x_y_z2 || _o5_x_y_z2.w, null === (_o5_x4 = o5.x) || void 0 === _o5_x4 || _o5_x4.y.z.w, null === (_o5_x5 = o5.x) || void 0 === _o5_x5 || null === (_o5_x_y_z3 = _o5_x5.y.z) || void 0 === _o5_x_y_z3 || _o5_x_y_z3.w) : (o5.x, null === (_o5_x6 = o5.x) || void 0 === _o5_x6 || _o5_x6.y, null === (_o5_x7 = o5.x) || void 0 === _o5_x7 || _o5_x7.y.z, null === (_o5_x8 = o5.x) || void 0 === _o5_x8 || null === (_o5_x_y_z4 = _o5_x8.y.z) || void 0 === _o5_x_y_z4 || _o5_x_y_z4.w, o5.x.y, o5.x.y.z.w), o5.x, null === (_o5_x1 = o5.x) || void 0 === _o5_x1 || _o5_x1.y, null === (_o5_x2 = o5.x) || void 0 === _o5_x2 || _o5_x2.y.z, null === (_o5_x3 = o5.x) || void 0 === _o5_x3 || null === (_o5_x_y_z1 = _o5_x3.y.z) || void 0 === _o5_x_y_z1 || _o5_x_y_z1.w, o5.x.y, o5.x.y.z.w, (null == o6 ? void 0 : o6.f()) ? o6 : (o6, null == o6 || o6.f), o6.f, o6, null == o6 || o6.f, o6.f, someFunction({ someProperty: 42 }), someFunction(void 0); for(// Repro from #35970 -var _o, _o1, _o2, _o3, _f, _o21, _o22, _o31, _o32, _o4_x, _o4_x1, _o5_x_y_z, _o5_x, _o5_x1, _o5_x2, _o5_x_y_z1, _o5_x3, _o6, _o61, _arr_i, a, b, c, d, _o23, _o24, _o25, _o33, _o34, _o4_x2, _o4_x3, _o5_x_y_z2, _o5_x4, _o5_x_y_z3, _o5_x5, _o5_x6, _o5_x7, _o5_x_y_z4, _o5_x8, _o62, lastSomeProperty, _arr_i1, i = 0; (null === (_arr_i = arr[i]) || void 0 === _arr_i ? void 0 : _arr_i.tag) === "left";)i += 1, (null === (_arr_i1 = arr[i]) || void 0 === _arr_i1 ? void 0 : _arr_i1.tag) === "right" && console.log("I should ALSO be reachable"); +var _o4_x, _o4_x1, _o5_x_y_z, _o5_x, _o5_x1, _o5_x2, _o5_x_y_z1, _o5_x3, _arr_i, a, b, c, d, _o4_x2, _o4_x3, _o5_x_y_z2, _o5_x4, _o5_x_y_z3, _o5_x5, _o5_x6, _o5_x7, _o5_x_y_z4, _o5_x8, lastSomeProperty, _arr_i1, i = 0; (null === (_arr_i = arr[i]) || void 0 === _arr_i ? void 0 : _arr_i.tag) === "left";)i += 1, (null === (_arr_i1 = arr[i]) || void 0 === _arr_i1 ? void 0 : _arr_i1.tag) === "right" && console.log("I should ALSO be reachable"); diff --git a/crates/swc/tests/tsc-references/controlFlowOptionalChain2.1.normal.js b/crates/swc/tests/tsc-references/controlFlowOptionalChain2.1.normal.js index f666c618c2e..94b42b6269c 100644 --- a/crates/swc/tests/tsc-references/controlFlowOptionalChain2.1.normal.js +++ b/crates/swc/tests/tsc-references/controlFlowOptionalChain2.1.normal.js @@ -1,81 +1,71 @@ //// [controlFlowOptionalChain2.ts] function funcTwo(arg) { - var _arg, _arg1; - if (((_arg = arg) === null || _arg === void 0 ? void 0 : _arg.type) === "B") { + if ((arg === null || arg === void 0 ? void 0 : arg.type) === "B") { arg; // `B` return; } arg; - (_arg1 = arg) === null || _arg1 === void 0 ? void 0 : _arg1.name; + arg === null || arg === void 0 ? void 0 : arg.name; } function funcThree(arg) { - var _arg, _arg1; - if (((_arg = arg) === null || _arg === void 0 ? void 0 : _arg.type) === "B") { + if ((arg === null || arg === void 0 ? void 0 : arg.type) === "B") { arg; // `B` return; } arg; - (_arg1 = arg) === null || _arg1 === void 0 ? void 0 : _arg1.name; + arg === null || arg === void 0 ? void 0 : arg.name; } function f1(x) { - var _x; - if (((_x = x) === null || _x === void 0 ? void 0 : _x.kind) === undefined) { + if ((x === null || x === void 0 ? void 0 : x.kind) === undefined) { x; // U | undefined } else { x; // X } } function f2(x) { - var _x; - if (((_x = x) === null || _x === void 0 ? void 0 : _x.kind) === undefined) { + if ((x === null || x === void 0 ? void 0 : x.kind) === undefined) { x; // undefined } else { x; // X | N } } function f3(x) { - var _x; - if (((_x = x) === null || _x === void 0 ? void 0 : _x.kind) === undefined) { + if ((x === null || x === void 0 ? void 0 : x.kind) === undefined) { x; // U | null } else { x; // X } } function f4(x) { - var _x; - if (((_x = x) === null || _x === void 0 ? void 0 : _x.kind) === undefined) { + if ((x === null || x === void 0 ? void 0 : x.kind) === undefined) { x; // null } else { x; // X | N } } function f5(x) { - var _x; - if (((_x = x) === null || _x === void 0 ? void 0 : _x.kind) === null) { + if ((x === null || x === void 0 ? void 0 : x.kind) === null) { x; // never } else { x; // X | U | undefined } } function f6(x) { - var _x; - if (((_x = x) === null || _x === void 0 ? void 0 : _x.kind) === null) { + if ((x === null || x === void 0 ? void 0 : x.kind) === null) { x; // N } else { x; // X | undefined } } function f7(x) { - var _x; - if (((_x = x) === null || _x === void 0 ? void 0 : _x.kind) === null) { + if ((x === null || x === void 0 ? void 0 : x.kind) === null) { x; // never } else { x; // X | U | null } } function f8(x) { - var _x; - if (((_x = x) === null || _x === void 0 ? void 0 : _x.kind) === null) { + if ((x === null || x === void 0 ? void 0 : x.kind) === null) { x; // N } else { x; // X | null diff --git a/crates/swc/tests/tsc-references/deleteChain.1.normal.js b/crates/swc/tests/tsc-references/deleteChain.1.normal.js index 790f9fee63f..3f03d680fa1 100644 --- a/crates/swc/tests/tsc-references/deleteChain.1.normal.js +++ b/crates/swc/tests/tsc-references/deleteChain.1.normal.js @@ -1,15 +1,15 @@ //// [deleteChain.ts] -var _o1, _o11, _o2, _o21, _o3_b, _o3_b1, _o4_b_c_d, _o4_b, _this, _o4_b1, _o4_b_c_d1, _o4_b2, _o5_b_c_d, _o5_b, _o5, _o5_b_c_d1, _o5_b1, _o51, _o6_b_c_d, _o6_b, _o6_b_c_d1, _o6_b1; -(_o1 = o1) === null || _o1 === void 0 ? true : delete _o1.b; -delete ((_o11 = o1) === null || _o11 === void 0 ? void 0 : _o11.b); -(_o2 = o2) === null || _o2 === void 0 ? true : delete _o2.b.c; -delete ((_o21 = o2) === null || _o21 === void 0 ? void 0 : _o21.b.c); +var _o3_b, _o3_b1, _o4_b_c_d, _o4_b, _this, _o4_b1, _o4_b_c_d1, _o4_b2, _o5_b_c_d, _o5_b, _o5_b_c_d1, _o5_b1, _o6_b_c_d, _o6_b, _o6_b_c_d1, _o6_b1; +o1 === null || o1 === void 0 ? true : delete o1.b; +delete (o1 === null || o1 === void 0 ? void 0 : o1.b); +o2 === null || o2 === void 0 ? true : delete o2.b.c; +delete (o2 === null || o2 === void 0 ? void 0 : o2.b.c); (_o3_b = o3.b) === null || _o3_b === void 0 ? true : delete _o3_b.c; delete ((_o3_b1 = o3.b) === null || _o3_b1 === void 0 ? void 0 : _o3_b1.c); (_o4_b = o4.b) === null || _o4_b === void 0 ? true : (_o4_b_c_d = _o4_b.c.d) === null || _o4_b_c_d === void 0 ? true : delete _o4_b_c_d.e; (_this = (_o4_b1 = o4.b) === null || _o4_b1 === void 0 ? void 0 : _o4_b1.c.d) === null || _this === void 0 ? true : delete _this.e; delete ((_o4_b2 = o4.b) === null || _o4_b2 === void 0 ? void 0 : (_o4_b_c_d1 = _o4_b2.c.d) === null || _o4_b_c_d1 === void 0 ? void 0 : _o4_b_c_d1.e); -(_o5_b = (_o5 = o5).b) === null || _o5_b === void 0 ? true : (_o5_b_c_d = _o5_b.call(_o5).c.d) === null || _o5_b_c_d === void 0 ? true : delete _o5_b_c_d.e; -delete ((_o5_b1 = (_o51 = o5).b) === null || _o5_b1 === void 0 ? void 0 : (_o5_b_c_d1 = _o5_b1.call(_o51).c.d) === null || _o5_b_c_d1 === void 0 ? void 0 : _o5_b_c_d1.e); +(_o5_b = o5.b) === null || _o5_b === void 0 ? true : (_o5_b_c_d = _o5_b.call(o5).c.d) === null || _o5_b_c_d === void 0 ? true : delete _o5_b_c_d.e; +delete ((_o5_b1 = o5.b) === null || _o5_b1 === void 0 ? void 0 : (_o5_b_c_d1 = _o5_b1.call(o5).c.d) === null || _o5_b_c_d1 === void 0 ? void 0 : _o5_b_c_d1.e); (_o6_b = o6.b) === null || _o6_b === void 0 ? true : (_o6_b_c_d = _o6_b["c"].d) === null || _o6_b_c_d === void 0 ? true : delete _o6_b_c_d["e"]; delete ((_o6_b1 = o6.b) === null || _o6_b1 === void 0 ? void 0 : (_o6_b_c_d1 = _o6_b1["c"].d) === null || _o6_b_c_d1 === void 0 ? void 0 : _o6_b_c_d1["e"]); diff --git a/crates/swc/tests/tsc-references/deleteChain.2.minified.js b/crates/swc/tests/tsc-references/deleteChain.2.minified.js index b55a36419ff..df8c98213be 100644 --- a/crates/swc/tests/tsc-references/deleteChain.2.minified.js +++ b/crates/swc/tests/tsc-references/deleteChain.2.minified.js @@ -1,3 +1,3 @@ //// [deleteChain.ts] -var _o1, _o11, _o2, _o21, _o3_b, _o3_b1, _o4_b_c_d, _o4_b, _this, _o4_b1, _o4_b_c_d1, _o4_b2, _o5_b_c_d, _o5_b, _o5, _o5_b_c_d1, _o5_b1, _o51, _o6_b_c_d, _o6_b, _o6_b_c_d1, _o6_b1; -null === (_o1 = o1) || void 0 === _o1 || delete _o1.b, delete (null === (_o11 = o1) || void 0 === _o11 ? void 0 : _o11.b), null === (_o2 = o2) || void 0 === _o2 || delete _o2.b.c, delete (null === (_o21 = o2) || void 0 === _o21 ? void 0 : _o21.b.c), null === (_o3_b = o3.b) || void 0 === _o3_b || delete _o3_b.c, delete (null === (_o3_b1 = o3.b) || void 0 === _o3_b1 ? void 0 : _o3_b1.c), null === (_o4_b = o4.b) || void 0 === _o4_b || null === (_o4_b_c_d = _o4_b.c.d) || void 0 === _o4_b_c_d || delete _o4_b_c_d.e, null === (_this = null === (_o4_b1 = o4.b) || void 0 === _o4_b1 ? void 0 : _o4_b1.c.d) || void 0 === _this || delete _this.e, delete (null === (_o4_b2 = o4.b) || void 0 === _o4_b2 ? void 0 : null === (_o4_b_c_d1 = _o4_b2.c.d) || void 0 === _o4_b_c_d1 ? void 0 : _o4_b_c_d1.e), null === (_o5_b = (_o5 = o5).b) || void 0 === _o5_b || null === (_o5_b_c_d = _o5_b.call(_o5).c.d) || void 0 === _o5_b_c_d || delete _o5_b_c_d.e, delete (null === (_o5_b1 = (_o51 = o5).b) || void 0 === _o5_b1 ? void 0 : null === (_o5_b_c_d1 = _o5_b1.call(_o51).c.d) || void 0 === _o5_b_c_d1 ? void 0 : _o5_b_c_d1.e), null === (_o6_b = o6.b) || void 0 === _o6_b || null === (_o6_b_c_d = _o6_b.c.d) || void 0 === _o6_b_c_d || delete _o6_b_c_d.e, delete (null === (_o6_b1 = o6.b) || void 0 === _o6_b1 ? void 0 : null === (_o6_b_c_d1 = _o6_b1.c.d) || void 0 === _o6_b_c_d1 ? void 0 : _o6_b_c_d1.e); +var _o3_b, _o3_b1, _o4_b_c_d, _o4_b, _this, _o4_b1, _o4_b_c_d1, _o4_b2, _o5_b_c_d, _o5_b, _o5_b_c_d1, _o5_b1, _o6_b_c_d, _o6_b, _o6_b_c_d1, _o6_b1; +null == o1 || delete o1.b, delete (null == o1 ? void 0 : o1.b), null == o2 || delete o2.b.c, delete (null == o2 ? void 0 : o2.b.c), null === (_o3_b = o3.b) || void 0 === _o3_b || delete _o3_b.c, delete (null === (_o3_b1 = o3.b) || void 0 === _o3_b1 ? void 0 : _o3_b1.c), null === (_o4_b = o4.b) || void 0 === _o4_b || null === (_o4_b_c_d = _o4_b.c.d) || void 0 === _o4_b_c_d || delete _o4_b_c_d.e, null === (_this = null === (_o4_b1 = o4.b) || void 0 === _o4_b1 ? void 0 : _o4_b1.c.d) || void 0 === _this || delete _this.e, delete (null === (_o4_b2 = o4.b) || void 0 === _o4_b2 ? void 0 : null === (_o4_b_c_d1 = _o4_b2.c.d) || void 0 === _o4_b_c_d1 ? void 0 : _o4_b_c_d1.e), null === (_o5_b = o5.b) || void 0 === _o5_b || null === (_o5_b_c_d = _o5_b.call(o5).c.d) || void 0 === _o5_b_c_d || delete _o5_b_c_d.e, delete (null === (_o5_b1 = o5.b) || void 0 === _o5_b1 ? void 0 : null === (_o5_b_c_d1 = _o5_b1.call(o5).c.d) || void 0 === _o5_b_c_d1 ? void 0 : _o5_b_c_d1.e), null === (_o6_b = o6.b) || void 0 === _o6_b || null === (_o6_b_c_d = _o6_b.c.d) || void 0 === _o6_b_c_d || delete _o6_b_c_d.e, delete (null === (_o6_b1 = o6.b) || void 0 === _o6_b1 ? void 0 : null === (_o6_b_c_d1 = _o6_b1.c.d) || void 0 === _o6_b_c_d1 ? void 0 : _o6_b_c_d1.e); diff --git a/crates/swc/tests/tsc-references/elementAccessChain.1.normal.js b/crates/swc/tests/tsc-references/elementAccessChain.1.normal.js index 94cf3acee33..39ac1712526 100644 --- a/crates/swc/tests/tsc-references/elementAccessChain.1.normal.js +++ b/crates/swc/tests/tsc-references/elementAccessChain.1.normal.js @@ -1,19 +1,19 @@ //// [elementAccessChain.ts] -var _o1, _o2, _o21, _o3_b, _o3_b1, _o4_b_c_d, _o4_b, _o4_b_c_d1, _o4_b1, _o5_b_c_d, _o5_b, _o5, _o5_b_c_d1, _o5_b1, _o51, _o5_b_c_d2, _o5_b2, _o52, _o5_b_c_d3, _o5_b3, _o53, _o6, // GH#36031 -_o22, _o23, _o24, _o25; -(_o1 = o1) === null || _o1 === void 0 ? void 0 : _o1["b"]; -(_o2 = o2) === null || _o2 === void 0 ? void 0 : _o2["b"].c; -(_o21 = o2) === null || _o21 === void 0 ? void 0 : _o21.b["c"]; +var _o3_b, _o3_b1, _o4_b_c_d, _o4_b, _o4_b_c_d1, _o4_b1, _o5_b_c_d, _o5_b, _o5_b_c_d1, _o5_b1, _o5_b_c_d2, _o5_b2, _o5_b_c_d3, _o5_b3, _o6; +o1 === null || o1 === void 0 ? void 0 : o1["b"]; +o2 === null || o2 === void 0 ? void 0 : o2["b"].c; +o2 === null || o2 === void 0 ? void 0 : o2.b["c"]; (_o3_b = o3["b"]) === null || _o3_b === void 0 ? void 0 : _o3_b.c; (_o3_b1 = o3.b) === null || _o3_b1 === void 0 ? void 0 : _o3_b1["c"]; (_o4_b = o4.b) === null || _o4_b === void 0 ? void 0 : (_o4_b_c_d = _o4_b["c"].d) === null || _o4_b_c_d === void 0 ? void 0 : _o4_b_c_d.e; (_o4_b1 = o4.b) === null || _o4_b1 === void 0 ? void 0 : (_o4_b_c_d1 = _o4_b1["c"].d) === null || _o4_b_c_d1 === void 0 ? void 0 : _o4_b_c_d1["e"]; -(_o5_b = (_o5 = o5).b) === null || _o5_b === void 0 ? void 0 : (_o5_b_c_d = _o5_b.call(_o5)["c"].d) === null || _o5_b_c_d === void 0 ? void 0 : _o5_b_c_d.e; -(_o5_b1 = (_o51 = o5).b) === null || _o5_b1 === void 0 ? void 0 : (_o5_b_c_d1 = _o5_b1.call(_o51)["c"].d) === null || _o5_b_c_d1 === void 0 ? void 0 : _o5_b_c_d1["e"]; -(_o5_b2 = (_o52 = o5)["b"]) === null || _o5_b2 === void 0 ? void 0 : (_o5_b_c_d2 = _o5_b2.call(_o52)["c"].d) === null || _o5_b_c_d2 === void 0 ? void 0 : _o5_b_c_d2.e; -(_o5_b3 = (_o53 = o5)["b"]) === null || _o5_b3 === void 0 ? void 0 : (_o5_b_c_d3 = _o5_b3.call(_o53)["c"].d) === null || _o5_b_c_d3 === void 0 ? void 0 : _o5_b_c_d3["e"]; +(_o5_b = o5.b) === null || _o5_b === void 0 ? void 0 : (_o5_b_c_d = _o5_b.call(o5)["c"].d) === null || _o5_b_c_d === void 0 ? void 0 : _o5_b_c_d.e; +(_o5_b1 = o5.b) === null || _o5_b1 === void 0 ? void 0 : (_o5_b_c_d1 = _o5_b1.call(o5)["c"].d) === null || _o5_b_c_d1 === void 0 ? void 0 : _o5_b_c_d1["e"]; +(_o5_b2 = o5["b"]) === null || _o5_b2 === void 0 ? void 0 : (_o5_b_c_d2 = _o5_b2.call(o5)["c"].d) === null || _o5_b_c_d2 === void 0 ? void 0 : _o5_b_c_d2.e; +(_o5_b3 = o5["b"]) === null || _o5_b3 === void 0 ? void 0 : (_o5_b_c_d3 = _o5_b3.call(o5)["c"].d) === null || _o5_b_c_d3 === void 0 ? void 0 : _o5_b_c_d3["e"]; (_o6 = o6()) === null || _o6 === void 0 ? void 0 : _o6["x"]; -(_o22 = o2) === null || _o22 === void 0 ? void 0 : _o22["b"].c; -(_o23 = o2) === null || _o23 === void 0 ? void 0 : _o23["b"]["c"]; -(_o24 = o2) === null || _o24 === void 0 ? void 0 : _o24["b"].c; -(_o25 = o2) === null || _o25 === void 0 ? void 0 : _o25["b"]["c"]; +// GH#36031 +o2 === null || o2 === void 0 ? void 0 : o2["b"].c; +o2 === null || o2 === void 0 ? void 0 : o2["b"]["c"]; +o2 === null || o2 === void 0 ? void 0 : o2["b"].c; +o2 === null || o2 === void 0 ? void 0 : o2["b"]["c"]; diff --git a/crates/swc/tests/tsc-references/elementAccessChain.2.1.normal.js b/crates/swc/tests/tsc-references/elementAccessChain.2.1.normal.js index 841b1c98ecc..3492073aa98 100644 --- a/crates/swc/tests/tsc-references/elementAccessChain.2.1.normal.js +++ b/crates/swc/tests/tsc-references/elementAccessChain.2.1.normal.js @@ -1,7 +1,7 @@ //// [elementAccessChain.2.ts] -var _o1, _o2, _o21, _o3_b, _o3_b1; -(_o1 = o1) === null || _o1 === void 0 ? void 0 : _o1["b"]; -(_o2 = o2) === null || _o2 === void 0 ? void 0 : _o2["b"].c; -(_o21 = o2) === null || _o21 === void 0 ? void 0 : _o21.b["c"]; +var _o3_b, _o3_b1; +o1 === null || o1 === void 0 ? void 0 : o1["b"]; +o2 === null || o2 === void 0 ? void 0 : o2["b"].c; +o2 === null || o2 === void 0 ? void 0 : o2.b["c"]; (_o3_b = o3["b"]) === null || _o3_b === void 0 ? void 0 : _o3_b.c; (_o3_b1 = o3.b) === null || _o3_b1 === void 0 ? void 0 : _o3_b1["c"]; diff --git a/crates/swc/tests/tsc-references/elementAccessChain.2.2.minified.js b/crates/swc/tests/tsc-references/elementAccessChain.2.2.minified.js index dc5b81cdb59..b2e17050ccd 100644 --- a/crates/swc/tests/tsc-references/elementAccessChain.2.2.minified.js +++ b/crates/swc/tests/tsc-references/elementAccessChain.2.2.minified.js @@ -1,3 +1,3 @@ //// [elementAccessChain.2.ts] -var _o1, _o2, _o21, _o3_b, _o3_b1; -null === (_o1 = o1) || void 0 === _o1 || _o1.b, null === (_o2 = o2) || void 0 === _o2 || _o2.b.c, null === (_o21 = o2) || void 0 === _o21 || _o21.b.c, null === (_o3_b = o3.b) || void 0 === _o3_b || _o3_b.c, null === (_o3_b1 = o3.b) || void 0 === _o3_b1 || _o3_b1.c; +var _o3_b, _o3_b1; +null == o1 || o1.b, null == o2 || o2.b.c, null == o2 || o2.b.c, null === (_o3_b = o3.b) || void 0 === _o3_b || _o3_b.c, null === (_o3_b1 = o3.b) || void 0 === _o3_b1 || _o3_b1.c; diff --git a/crates/swc/tests/tsc-references/elementAccessChain.2.minified.js b/crates/swc/tests/tsc-references/elementAccessChain.2.minified.js index cc8c7a1d33a..dc205365297 100644 --- a/crates/swc/tests/tsc-references/elementAccessChain.2.minified.js +++ b/crates/swc/tests/tsc-references/elementAccessChain.2.minified.js @@ -1,4 +1,4 @@ //// [elementAccessChain.ts] -var _o1, _o2, _o21, _o3_b, _o3_b1, _o4_b_c_d, _o4_b, _o4_b_c_d1, _o4_b1, _o5_b_c_d, _o5_b, _o5, _o5_b_c_d1, _o5_b1, _o51, _o5_b_c_d2, _o5_b2, _o52, _o5_b_c_d3, _o5_b3, _o53, _o6, // GH#36031 -_o22, _o23, _o24, _o25; -null === (_o1 = o1) || void 0 === _o1 || _o1.b, null === (_o2 = o2) || void 0 === _o2 || _o2.b.c, null === (_o21 = o2) || void 0 === _o21 || _o21.b.c, null === (_o3_b = o3.b) || void 0 === _o3_b || _o3_b.c, null === (_o3_b1 = o3.b) || void 0 === _o3_b1 || _o3_b1.c, null === (_o4_b = o4.b) || void 0 === _o4_b || null === (_o4_b_c_d = _o4_b.c.d) || void 0 === _o4_b_c_d || _o4_b_c_d.e, null === (_o4_b1 = o4.b) || void 0 === _o4_b1 || null === (_o4_b_c_d1 = _o4_b1.c.d) || void 0 === _o4_b_c_d1 || _o4_b_c_d1.e, null === (_o5_b = (_o5 = o5).b) || void 0 === _o5_b || null === (_o5_b_c_d = _o5_b.call(_o5).c.d) || void 0 === _o5_b_c_d || _o5_b_c_d.e, null === (_o5_b1 = (_o51 = o5).b) || void 0 === _o5_b1 || null === (_o5_b_c_d1 = _o5_b1.call(_o51).c.d) || void 0 === _o5_b_c_d1 || _o5_b_c_d1.e, null === (_o5_b2 = (_o52 = o5).b) || void 0 === _o5_b2 || null === (_o5_b_c_d2 = _o5_b2.call(_o52).c.d) || void 0 === _o5_b_c_d2 || _o5_b_c_d2.e, null === (_o5_b3 = (_o53 = o5).b) || void 0 === _o5_b3 || null === (_o5_b_c_d3 = _o5_b3.call(_o53).c.d) || void 0 === _o5_b_c_d3 || _o5_b_c_d3.e, null === (_o6 = o6()) || void 0 === _o6 || _o6.x, null === (_o22 = o2) || void 0 === _o22 || _o22.b.c, null === (_o23 = o2) || void 0 === _o23 || _o23.b.c, null === (_o24 = o2) || void 0 === _o24 || _o24.b.c, null === (_o25 = o2) || void 0 === _o25 || _o25.b.c; +var _o3_b, _o3_b1, _o4_b_c_d, _o4_b, _o4_b_c_d1, _o4_b1, _o5_b_c_d, _o5_b, _o5_b_c_d1, _o5_b1, _o5_b_c_d2, _o5_b2, _o5_b_c_d3, _o5_b3, _o6; +null == o1 || o1.b, null == o2 || o2.b.c, null == o2 || o2.b.c, null === (_o3_b = o3.b) || void 0 === _o3_b || _o3_b.c, null === (_o3_b1 = o3.b) || void 0 === _o3_b1 || _o3_b1.c, null === (_o4_b = o4.b) || void 0 === _o4_b || null === (_o4_b_c_d = _o4_b.c.d) || void 0 === _o4_b_c_d || _o4_b_c_d.e, null === (_o4_b1 = o4.b) || void 0 === _o4_b1 || null === (_o4_b_c_d1 = _o4_b1.c.d) || void 0 === _o4_b_c_d1 || _o4_b_c_d1.e, null === (_o5_b = o5.b) || void 0 === _o5_b || null === (_o5_b_c_d = _o5_b.call(o5).c.d) || void 0 === _o5_b_c_d || _o5_b_c_d.e, null === (_o5_b1 = o5.b) || void 0 === _o5_b1 || null === (_o5_b_c_d1 = _o5_b1.call(o5).c.d) || void 0 === _o5_b_c_d1 || _o5_b_c_d1.e, null === (_o5_b2 = o5.b) || void 0 === _o5_b2 || null === (_o5_b_c_d2 = _o5_b2.call(o5).c.d) || void 0 === _o5_b_c_d2 || _o5_b_c_d2.e, null === (_o5_b3 = o5.b) || void 0 === _o5_b3 || null === (_o5_b_c_d3 = _o5_b3.call(o5).c.d) || void 0 === _o5_b_c_d3 || _o5_b_c_d3.e, null === (_o6 = o6()) || void 0 === _o6 || _o6.x, null == // GH#36031 +o2 || o2.b.c, null == o2 || o2.b.c, null == o2 || o2.b.c, null == o2 || o2.b.c; diff --git a/crates/swc/tests/tsc-references/exhaustiveSwitchStatements1.1.normal.js b/crates/swc/tests/tsc-references/exhaustiveSwitchStatements1.1.normal.js index 64561f2a239..1eb599d9c8e 100644 --- a/crates/swc/tests/tsc-references/exhaustiveSwitchStatements1.1.normal.js +++ b/crates/swc/tests/tsc-references/exhaustiveSwitchStatements1.1.normal.js @@ -199,9 +199,8 @@ Animal; Animal[Animal["CAT"] = 1] = "CAT"; })(Animal || (Animal = {})); function expression() { - var _zoo; var _zoo_animal; - switch((_zoo_animal = (_zoo = zoo) === null || _zoo === void 0 ? void 0 : _zoo.animal) !== null && _zoo_animal !== void 0 ? _zoo_animal : Animal.DOG){ + switch((_zoo_animal = zoo === null || zoo === void 0 ? void 0 : zoo.animal) !== null && _zoo_animal !== void 0 ? _zoo_animal : Animal.DOG){ case Animal.DOG: return Animal.DOG; case Animal.CAT: diff --git a/crates/swc/tests/tsc-references/logicalAssignment8(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/logicalAssignment8(target=es2015).1.normal.js index 69867c1210c..1f503ac8c6d 100644 --- a/crates/swc/tests/tsc-references/logicalAssignment8(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/logicalAssignment8(target=es2015).1.normal.js @@ -1,16 +1,13 @@ //// [logicalAssignment8.ts] function foo1(results) { - var _bar; var _bar_value; - (results || (results = (_bar_value = (_bar = bar) === null || _bar === void 0 ? void 0 : _bar.value) !== null && _bar_value !== void 0 ? _bar_value : [])).push(100); + (results || (results = (_bar_value = bar === null || bar === void 0 ? void 0 : bar.value) !== null && _bar_value !== void 0 ? _bar_value : [])).push(100); } function foo2(results) { - var _bar; var _bar_value; - (results !== null && results !== void 0 ? results : results = (_bar_value = (_bar = bar) === null || _bar === void 0 ? void 0 : _bar.value) !== null && _bar_value !== void 0 ? _bar_value : []).push(100); + (results !== null && results !== void 0 ? results : results = (_bar_value = bar === null || bar === void 0 ? void 0 : bar.value) !== null && _bar_value !== void 0 ? _bar_value : []).push(100); } function foo3(results) { - var _bar; var _bar_value; - (results && (results = (_bar_value = (_bar = bar) === null || _bar === void 0 ? void 0 : _bar.value) !== null && _bar_value !== void 0 ? _bar_value : [])).push(100); + (results && (results = (_bar_value = bar === null || bar === void 0 ? void 0 : bar.value) !== null && _bar_value !== void 0 ? _bar_value : [])).push(100); } diff --git a/crates/swc/tests/tsc-references/noPropertyAccessFromIndexSignature1.1.normal.js b/crates/swc/tests/tsc-references/noPropertyAccessFromIndexSignature1.1.normal.js index 676955b1977..81dd0760e70 100644 --- a/crates/swc/tests/tsc-references/noPropertyAccessFromIndexSignature1.1.normal.js +++ b/crates/swc/tests/tsc-references/noPropertyAccessFromIndexSignature1.1.normal.js @@ -1,7 +1,4 @@ //// [noPropertyAccessFromIndexSignature1.ts] -var // optional access property -_d, _d1, // optional access index signature -_d2, _d3; // access property a.foo; a["foo"]; @@ -14,7 +11,9 @@ c["foo"]; // access index signature c.bar; c["bar"]; -(_d = d) === null || _d === void 0 ? void 0 : _d.foo; -(_d1 = d) === null || _d1 === void 0 ? void 0 : _d1["foo"]; -(_d2 = d) === null || _d2 === void 0 ? void 0 : _d2.bar; -(_d3 = d) === null || _d3 === void 0 ? void 0 : _d3["bar"]; +// optional access property +d === null || d === void 0 ? void 0 : d.foo; +d === null || d === void 0 ? void 0 : d["foo"]; +// optional access index signature +d === null || d === void 0 ? void 0 : d.bar; +d === null || d === void 0 ? void 0 : d["bar"]; diff --git a/crates/swc/tests/tsc-references/noPropertyAccessFromIndexSignature1.2.minified.js b/crates/swc/tests/tsc-references/noPropertyAccessFromIndexSignature1.2.minified.js index e4fb36dd01d..179ad30bb31 100644 --- a/crates/swc/tests/tsc-references/noPropertyAccessFromIndexSignature1.2.minified.js +++ b/crates/swc/tests/tsc-references/noPropertyAccessFromIndexSignature1.2.minified.js @@ -1,9 +1,8 @@ //// [noPropertyAccessFromIndexSignature1.ts] -var // optional access property -_d, _d1, // optional access index signature -_d2, _d3; // access property a.foo, a.foo, // access index signature b.foo, b.foo, // access property c.foo, c.foo, // access index signature -c.bar, c.bar, null === (_d = d) || void 0 === _d || _d.foo, null === (_d1 = d) || void 0 === _d1 || _d1.foo, null === (_d2 = d) || void 0 === _d2 || _d2.bar, null === (_d3 = d) || void 0 === _d3 || _d3.bar; +c.bar, c.bar, null == // optional access property +d || d.foo, null == d || d.foo, null == // optional access index signature +d || d.bar, null == d || d.bar; diff --git a/crates/swc/tests/tsc-references/nullishCoalescingOperator12.1.normal.js b/crates/swc/tests/tsc-references/nullishCoalescingOperator12.1.normal.js index c2870d099e9..0dfb46befe7 100644 --- a/crates/swc/tests/tsc-references/nullishCoalescingOperator12.1.normal.js +++ b/crates/swc/tests/tsc-references/nullishCoalescingOperator12.1.normal.js @@ -1,7 +1,6 @@ //// [nullishCoalescingOperator12.ts] -var _obj; const obj = { arr: [] }; var _obj_arr; -for (const i of (_obj_arr = (_obj = obj) === null || _obj === void 0 ? void 0 : _obj.arr) !== null && _obj_arr !== void 0 ? _obj_arr : []){} +for (const i of (_obj_arr = obj === null || obj === void 0 ? void 0 : obj.arr) !== null && _obj_arr !== void 0 ? _obj_arr : []){} diff --git a/crates/swc/tests/tsc-references/nullishCoalescingOperator12.2.minified.js b/crates/swc/tests/tsc-references/nullishCoalescingOperator12.2.minified.js index eae3c6c5e88..60fdbe8d6b1 100644 --- a/crates/swc/tests/tsc-references/nullishCoalescingOperator12.2.minified.js +++ b/crates/swc/tests/tsc-references/nullishCoalescingOperator12.2.minified.js @@ -1,2 +1,6 @@ //// [nullishCoalescingOperator12.ts] -for (const i of []); +var _obj_arr; +const obj = { + arr: [] +}; +for (const i of null !== (_obj_arr = null == obj ? void 0 : obj.arr) && void 0 !== _obj_arr ? _obj_arr : []); diff --git a/crates/swc/tests/tsc-references/optionalChainingInArrow.1.normal.js b/crates/swc/tests/tsc-references/optionalChainingInArrow.1.normal.js index 8f0bbd2dd65..eb598fbb3ac 100644 --- a/crates/swc/tests/tsc-references/optionalChainingInArrow.1.normal.js +++ b/crates/swc/tests/tsc-references/optionalChainingInArrow.1.normal.js @@ -1,9 +1,8 @@ //// [optionalChainingInArrow.ts] // https://github.com/microsoft/TypeScript/issues/41814 var test = function(names) { - var // single-line comment - _names; - return (_names = names) === null || _names === void 0 ? void 0 : _names.filter(function(x) { + return(// single-line comment + names === null || names === void 0 ? void 0 : names.filter(function(x) { return x; - }); + })); }; diff --git a/crates/swc/tests/tsc-references/optionalChainingInTypeAssertions(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/optionalChainingInTypeAssertions(target=es2015).1.normal.js index f25f6ecc712..444a346e35a 100644 --- a/crates/swc/tests/tsc-references/optionalChainingInTypeAssertions(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/optionalChainingInTypeAssertions(target=es2015).1.normal.js @@ -1,15 +1,15 @@ //// [optionalChainingInTypeAssertions.ts] -var _foo_m, _foo, _foo_m1, _foo1, /*a1*/ /*a2*/ _foo_m2, _foo2, /*b1*/ _foo_m3 /*b3*/ , _foo3, _foo4, _foo5, _foo6, _foo7; +var _foo_m, _foo_m1, /*a1*/ /*a2*/ _foo_m2, /*b1*/ _foo_m3 /*b3*/ ; class Foo { m() {} } const foo = new Foo(); -(_foo_m = (_foo = foo).m) === null || _foo_m === void 0 ? void 0 : _foo_m.call(_foo); -(_foo_m1 = (_foo1 = foo).m) === null || _foo_m1 === void 0 ? void 0 : _foo_m1.call(_foo1); -(_foo_m2 = (_foo2 = foo).m) === null || _foo_m2 === void 0 ? void 0 : _foo_m2.call(_foo2); -(_foo_m3 = (_foo3 = foo).m) === null || _foo_m3 === void 0 ? void 0 : _foo_m3.call(_foo3); +(_foo_m = foo.m) === null || _foo_m === void 0 ? void 0 : _foo_m.call(foo); +(_foo_m1 = foo.m) === null || _foo_m1 === void 0 ? void 0 : _foo_m1.call(foo); +(_foo_m2 = foo.m) === null || _foo_m2 === void 0 ? void 0 : _foo_m2.call(foo); +(_foo_m3 = foo.m) === null || _foo_m3 === void 0 ? void 0 : _foo_m3.call(foo); // https://github.com/microsoft/TypeScript/issues/50148 -((_foo4 = foo) === null || _foo4 === void 0 ? void 0 : _foo4.m).length; -((_foo5 = foo) === null || _foo5 === void 0 ? void 0 : _foo5.m).length; -((_foo6 = foo) === null || _foo6 === void 0 ? void 0 : _foo6["m"]).length; -((_foo7 = foo) === null || _foo7 === void 0 ? void 0 : _foo7["m"]).length; +(foo === null || foo === void 0 ? void 0 : foo.m).length; +(foo === null || foo === void 0 ? void 0 : foo.m).length; +(foo === null || foo === void 0 ? void 0 : foo["m"]).length; +(foo === null || foo === void 0 ? void 0 : foo["m"]).length; diff --git a/crates/swc/tests/tsc-references/optionalChainingInference.1.normal.js b/crates/swc/tests/tsc-references/optionalChainingInference.1.normal.js index 37e70d9e985..d0600a4181d 100644 --- a/crates/swc/tests/tsc-references/optionalChainingInference.1.normal.js +++ b/crates/swc/tests/tsc-references/optionalChainingInference.1.normal.js @@ -1,35 +1,34 @@ //// [optionalChainingInference.ts] // https://github.com/microsoft/TypeScript/issues/34579 -var _su, _su1, _su2, _fnu, _su3, _osu, _osu1, _ofnu; var b1 = { - value: (_su = su) === null || _su === void 0 ? void 0 : _su.length + value: su === null || su === void 0 ? void 0 : su.length }; var v1 = unbox(b1); var b2 = { - value: (_su1 = su) === null || _su1 === void 0 ? void 0 : _su1.length + value: su === null || su === void 0 ? void 0 : su.length }; var v2 = unbox(b2); var b3 = { - value: (_su2 = su) === null || _su2 === void 0 ? void 0 : _su2.length + value: su === null || su === void 0 ? void 0 : su.length }; var v3 = unbox(b3); var b4 = { - value: (_fnu = fnu) === null || _fnu === void 0 ? void 0 : _fnu() + value: fnu === null || fnu === void 0 ? void 0 : fnu() }; var v4 = unbox(b4); var b5 = { - value: (_su3 = su) === null || _su3 === void 0 ? void 0 : _su3["length"] + value: su === null || su === void 0 ? void 0 : su["length"] }; var v5 = unbox(b5); var b6 = { - value: (_osu = osu) === null || _osu === void 0 ? void 0 : _osu.prop.length + value: osu === null || osu === void 0 ? void 0 : osu.prop.length }; var v6 = unbox(b6); var b7 = { - value: (_osu1 = osu) === null || _osu1 === void 0 ? void 0 : _osu1.prop["length"] + value: osu === null || osu === void 0 ? void 0 : osu.prop["length"] }; var v7 = unbox(b7); var b8 = { - value: (_ofnu = ofnu) === null || _ofnu === void 0 ? void 0 : _ofnu.prop() + value: ofnu === null || ofnu === void 0 ? void 0 : ofnu.prop() }; var v8 = unbox(b8); diff --git a/crates/swc/tests/tsc-references/optionalChainingInference.2.minified.js b/crates/swc/tests/tsc-references/optionalChainingInference.2.minified.js index 2c48f134cec..53597c12c7b 100644 --- a/crates/swc/tests/tsc-references/optionalChainingInference.2.minified.js +++ b/crates/swc/tests/tsc-references/optionalChainingInference.2.minified.js @@ -1,34 +1,34 @@ //// [optionalChainingInference.ts] // https://github.com/microsoft/TypeScript/issues/34579 -var _su, _su1, _su2, _fnu, _su3, _osu, _osu1, _ofnu, b1 = { - value: null === (_su = su) || void 0 === _su ? void 0 : _su.length +var b1 = { + value: null == su ? void 0 : su.length }; unbox(b1); var b2 = { - value: null === (_su1 = su) || void 0 === _su1 ? void 0 : _su1.length + value: null == su ? void 0 : su.length }; unbox(b2); var b3 = { - value: null === (_su2 = su) || void 0 === _su2 ? void 0 : _su2.length + value: null == su ? void 0 : su.length }; unbox(b3); var b4 = { - value: null === (_fnu = fnu) || void 0 === _fnu ? void 0 : _fnu() + value: null == fnu ? void 0 : fnu() }; unbox(b4); var b5 = { - value: null === (_su3 = su) || void 0 === _su3 ? void 0 : _su3.length + value: null == su ? void 0 : su.length }; unbox(b5); var b6 = { - value: null === (_osu = osu) || void 0 === _osu ? void 0 : _osu.prop.length + value: null == osu ? void 0 : osu.prop.length }; unbox(b6); var b7 = { - value: null === (_osu1 = osu) || void 0 === _osu1 ? void 0 : _osu1.prop.length + value: null == osu ? void 0 : osu.prop.length }; unbox(b7); var b8 = { - value: null === (_ofnu = ofnu) || void 0 === _ofnu ? void 0 : _ofnu.prop() + value: null == ofnu ? void 0 : ofnu.prop() }; unbox(b8); diff --git a/crates/swc/tests/tsc-references/parentheses.1.normal.js b/crates/swc/tests/tsc-references/parentheses.1.normal.js index 579aacf9a4c..f58ca270b55 100644 --- a/crates/swc/tests/tsc-references/parentheses.1.normal.js +++ b/crates/swc/tests/tsc-references/parentheses.1.normal.js @@ -1,6 +1,5 @@ //// [parentheses.ts] -var _o2, _o3, _o4; o1(o1 !== null && o1 !== void 0 ? o1 : 1); -((_o2 = o2) === null || _o2 === void 0 ? void 0 : _o2.b)(o1 !== null && o1 !== void 0 ? o1 : 1); -((_o3 = o3) === null || _o3 === void 0 ? void 0 : _o3.b())(o1 !== null && o1 !== void 0 ? o1 : 1); -((_o4 = o4) === null || _o4 === void 0 ? void 0 : _o4.b().c)(o1 !== null && o1 !== void 0 ? o1 : 1); +(o2 === null || o2 === void 0 ? void 0 : o2.b)(o1 !== null && o1 !== void 0 ? o1 : 1); +(o3 === null || o3 === void 0 ? void 0 : o3.b())(o1 !== null && o1 !== void 0 ? o1 : 1); +(o4 === null || o4 === void 0 ? void 0 : o4.b().c)(o1 !== null && o1 !== void 0 ? o1 : 1); diff --git a/crates/swc/tests/tsc-references/parentheses.2.minified.js b/crates/swc/tests/tsc-references/parentheses.2.minified.js index 6870428c665..ee0dd1315a0 100644 --- a/crates/swc/tests/tsc-references/parentheses.2.minified.js +++ b/crates/swc/tests/tsc-references/parentheses.2.minified.js @@ -1,3 +1,2 @@ //// [parentheses.ts] -var _o2, _o3, _o4; -o1(null != o1 ? o1 : 1), (null === (_o2 = o2) || void 0 === _o2 ? void 0 : _o2.b)(null != o1 ? o1 : 1), (null === (_o3 = o3) || void 0 === _o3 ? void 0 : _o3.b())(null != o1 ? o1 : 1), (null === (_o4 = o4) || void 0 === _o4 ? void 0 : _o4.b().c)(null != o1 ? o1 : 1); +o1(null != o1 ? o1 : 1), (null == o2 ? void 0 : o2.b)(null != o1 ? o1 : 1), (null == o3 ? void 0 : o3.b())(null != o1 ? o1 : 1), (null == o4 ? void 0 : o4.b().c)(null != o1 ? o1 : 1); diff --git a/crates/swc/tests/tsc-references/propertyAccessChain.1.normal.js b/crates/swc/tests/tsc-references/propertyAccessChain.1.normal.js index 5a36d88f4a1..38bb1fa2127 100644 --- a/crates/swc/tests/tsc-references/propertyAccessChain.1.normal.js +++ b/crates/swc/tests/tsc-references/propertyAccessChain.1.normal.js @@ -1,13 +1,13 @@ //// [propertyAccessChain.ts] -var _o1, _o2, _o3_b, _o4_b_c_d, _o4_b, _o5_b_c_d, _o5_b, _o5, _o6, // GH#34109 -_o11, // GH#36031 -_o21, _o22; -(_o1 = o1) === null || _o1 === void 0 ? void 0 : _o1.b; -(_o2 = o2) === null || _o2 === void 0 ? void 0 : _o2.b.c; +var _o3_b, _o4_b_c_d, _o4_b, _o5_b_c_d, _o5_b, _o6; +o1 === null || o1 === void 0 ? void 0 : o1.b; +o2 === null || o2 === void 0 ? void 0 : o2.b.c; (_o3_b = o3.b) === null || _o3_b === void 0 ? void 0 : _o3_b.c; (_o4_b = o4.b) === null || _o4_b === void 0 ? void 0 : (_o4_b_c_d = _o4_b.c.d) === null || _o4_b_c_d === void 0 ? void 0 : _o4_b_c_d.e; -(_o5_b = (_o5 = o5).b) === null || _o5_b === void 0 ? void 0 : (_o5_b_c_d = _o5_b.call(_o5).c.d) === null || _o5_b_c_d === void 0 ? void 0 : _o5_b_c_d.e; +(_o5_b = o5.b) === null || _o5_b === void 0 ? void 0 : (_o5_b_c_d = _o5_b.call(o5).c.d) === null || _o5_b_c_d === void 0 ? void 0 : _o5_b_c_d.e; (_o6 = o6()) === null || _o6 === void 0 ? void 0 : _o6.x; -((_o11 = o1) === null || _o11 === void 0 ? void 0 : _o11.b) ? 1 : 0; -(_o21 = o2) === null || _o21 === void 0 ? void 0 : _o21.b.c; -(_o22 = o2) === null || _o22 === void 0 ? void 0 : _o22.b.c; +// GH#34109 +(o1 === null || o1 === void 0 ? void 0 : o1.b) ? 1 : 0; +// GH#36031 +o2 === null || o2 === void 0 ? void 0 : o2.b.c; +o2 === null || o2 === void 0 ? void 0 : o2.b.c; diff --git a/crates/swc/tests/tsc-references/propertyAccessChain.2.1.normal.js b/crates/swc/tests/tsc-references/propertyAccessChain.2.1.normal.js index c3ccb59e422..73b3b4f0d6c 100644 --- a/crates/swc/tests/tsc-references/propertyAccessChain.2.1.normal.js +++ b/crates/swc/tests/tsc-references/propertyAccessChain.2.1.normal.js @@ -1,5 +1,5 @@ //// [propertyAccessChain.2.ts] -var _o1, _o2, _o3_b; -(_o1 = o1) === null || _o1 === void 0 ? void 0 : _o1.b; -(_o2 = o2) === null || _o2 === void 0 ? void 0 : _o2.b.c; +var _o3_b; +o1 === null || o1 === void 0 ? void 0 : o1.b; +o2 === null || o2 === void 0 ? void 0 : o2.b.c; (_o3_b = o3.b) === null || _o3_b === void 0 ? void 0 : _o3_b.c; diff --git a/crates/swc/tests/tsc-references/propertyAccessChain.2.2.minified.js b/crates/swc/tests/tsc-references/propertyAccessChain.2.2.minified.js index 301f8b4f513..6944a9005a1 100644 --- a/crates/swc/tests/tsc-references/propertyAccessChain.2.2.minified.js +++ b/crates/swc/tests/tsc-references/propertyAccessChain.2.2.minified.js @@ -1,3 +1,3 @@ //// [propertyAccessChain.2.ts] -var _o1, _o2, _o3_b; -null === (_o1 = o1) || void 0 === _o1 || _o1.b, null === (_o2 = o2) || void 0 === _o2 || _o2.b.c, null === (_o3_b = o3.b) || void 0 === _o3_b || _o3_b.c; +var _o3_b; +null == o1 || o1.b, null == o2 || o2.b.c, null === (_o3_b = o3.b) || void 0 === _o3_b || _o3_b.c; diff --git a/crates/swc/tests/tsc-references/propertyAccessChain.2.minified.js b/crates/swc/tests/tsc-references/propertyAccessChain.2.minified.js index bce29942081..feae60dbc8b 100644 --- a/crates/swc/tests/tsc-references/propertyAccessChain.2.minified.js +++ b/crates/swc/tests/tsc-references/propertyAccessChain.2.minified.js @@ -1,5 +1,5 @@ //// [propertyAccessChain.ts] -var _o1, _o2, _o3_b, _o4_b_c_d, _o4_b, _o5_b_c_d, _o5_b, _o5, _o6, // GH#34109 -_o11, // GH#36031 -_o21, _o22; -null === (_o1 = o1) || void 0 === _o1 || _o1.b, null === (_o2 = o2) || void 0 === _o2 || _o2.b.c, null === (_o3_b = o3.b) || void 0 === _o3_b || _o3_b.c, null === (_o4_b = o4.b) || void 0 === _o4_b || null === (_o4_b_c_d = _o4_b.c.d) || void 0 === _o4_b_c_d || _o4_b_c_d.e, null === (_o5_b = (_o5 = o5).b) || void 0 === _o5_b || null === (_o5_b_c_d = _o5_b.call(_o5).c.d) || void 0 === _o5_b_c_d || _o5_b_c_d.e, null === (_o6 = o6()) || void 0 === _o6 || _o6.x, null === (_o11 = o1) || void 0 === _o11 || _o11.b, null === (_o21 = o2) || void 0 === _o21 || _o21.b.c, null === (_o22 = o2) || void 0 === _o22 || _o22.b.c; +var _o3_b, _o4_b_c_d, _o4_b, _o5_b_c_d, _o5_b, _o6; +null == o1 || o1.b, null == o2 || o2.b.c, null === (_o3_b = o3.b) || void 0 === _o3_b || _o3_b.c, null === (_o4_b = o4.b) || void 0 === _o4_b || null === (_o4_b_c_d = _o4_b.c.d) || void 0 === _o4_b_c_d || _o4_b_c_d.e, null === (_o5_b = o5.b) || void 0 === _o5_b || null === (_o5_b_c_d = _o5_b.call(o5).c.d) || void 0 === _o5_b_c_d || _o5_b_c_d.e, null === (_o6 = o6()) || void 0 === _o6 || _o6.x, null == // GH#34109 +o1 || o1.b, null == // GH#36031 +o2 || o2.b.c, null == o2 || o2.b.c; diff --git a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers1(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers1(target=es2015).1.normal.js index ae4c88495ac..e513950424d 100644 --- a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers1(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers1(target=es2015).1.normal.js @@ -6,7 +6,6 @@ import { _ as _get_prototype_of } from "@swc/helpers/_/_get_prototype_of"; import { _ as _object_destructuring_empty } from "@swc/helpers/_/_object_destructuring_empty"; import { _ as _set } from "@swc/helpers/_/_set"; import { _ as _update } from "@swc/helpers/_/_update"; -var _C, _C1; class C extends B { constructor(...args){ super(...args); @@ -19,9 +18,9 @@ class C extends B { _define_property(C, "x", undefined); _define_property(C, "y1", C.x); _define_property(C, "y2", C.x()); -_define_property(C, "y3", (_C = C) === null || _C === void 0 ? void 0 : _C.x()); +_define_property(C, "y3", C === null || C === void 0 ? void 0 : C.x()); _define_property(C, "y4", C["x"]()); -_define_property(C, "y5", (_C1 = C) === null || _C1 === void 0 ? void 0 : _C1["x"]()); +_define_property(C, "y5", C === null || C === void 0 ? void 0 : C["x"]()); _define_property(C, "z1", _get(_get_prototype_of(C), "a", C)); _define_property(C, "z2", _get(_get_prototype_of(C), "a", C)); _define_property(C, "z3", _get(_get_prototype_of(C), "f", C).call(C)); diff --git a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers2(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers2(target=es2015).1.normal.js index 556c8e36c0d..b941ff61eab 100644 --- a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers2(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers2(target=es2015).1.normal.js @@ -24,15 +24,13 @@ class C extends B { C.y2 = C.x(); })(); (()=>{ - var _C; - C.y3 = (_C = C) === null || _C === void 0 ? void 0 : _C.x(); + C.y3 = C === null || C === void 0 ? void 0 : C.x(); })(); (()=>{ C.y4 = C["x"](); })(); (()=>{ - var _C; - C.y5 = (_C = C) === null || _C === void 0 ? void 0 : _C["x"](); + C.y5 = C === null || C === void 0 ? void 0 : C["x"](); })(); (()=>{ C.z1 = _get(_get_prototype_of(C), "a", C); diff --git a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers3.1.normal.js b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers3.1.normal.js index 56b5b36dffc..111673d8464 100644 --- a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers3.1.normal.js +++ b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers3.1.normal.js @@ -6,7 +6,6 @@ import { _ as _get } from "@swc/helpers/_/_get"; import { _ as _get_prototype_of } from "@swc/helpers/_/_get_prototype_of"; import { _ as _inherits } from "@swc/helpers/_/_inherits"; import { _ as _create_super } from "@swc/helpers/_/_create_super"; -var _C, _C1; var C = /*#__PURE__*/ function(B1) { "use strict"; _inherits(C, B1); @@ -26,8 +25,8 @@ var C = /*#__PURE__*/ function(B1) { _define_property(C, "x", undefined); _define_property(C, "y1", C.x); _define_property(C, "y2", C.x()); -_define_property(C, "y3", (_C = C) === null || _C === void 0 ? void 0 : _C.x()); +_define_property(C, "y3", C === null || C === void 0 ? void 0 : C.x()); _define_property(C, "y4", C["x"]()); -_define_property(C, "y5", (_C1 = C) === null || _C1 === void 0 ? void 0 : _C1["x"]()); +_define_property(C, "y5", C === null || C === void 0 ? void 0 : C["x"]()); _define_property(C, "z3", _get(_get_prototype_of(C), "f", C).call(C)); _define_property(C, "z4", _get(_get_prototype_of(C), "f", C).call(C)); diff --git a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers4.1.normal.js b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers4.1.normal.js index 3b87d0378bc..9560d2feee6 100644 --- a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers4.1.normal.js +++ b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers4.1.normal.js @@ -31,15 +31,13 @@ var C = /*#__PURE__*/ function(B1) { C.y2 = C.x(); })(); (function() { - var _C; - C.y3 = (_C = C) === null || _C === void 0 ? void 0 : _C.x(); + C.y3 = C === null || C === void 0 ? void 0 : C.x(); })(); (function() { C.y4 = C["x"](); })(); (function() { - var _C; - C.y5 = (_C = C) === null || _C === void 0 ? void 0 : _C["x"](); + C.y5 = C === null || C === void 0 ? void 0 : C["x"](); })(); (function() { C.z3 = _get(_get_prototype_of(C), "f", C).call(C); diff --git a/crates/swc/tests/tsc-references/thisTypeOptionalCall.1.normal.js b/crates/swc/tests/tsc-references/thisTypeOptionalCall.1.normal.js index b0bcf758699..7fe26aa9b4b 100644 --- a/crates/swc/tests/tsc-references/thisTypeOptionalCall.1.normal.js +++ b/crates/swc/tests/tsc-references/thisTypeOptionalCall.1.normal.js @@ -1,5 +1,4 @@ //// [thisTypeOptionalCall.ts] function maybeBind(obj, fn) { - var _fn; - return (_fn = fn) === null || _fn === void 0 ? void 0 : _fn.bind(obj); + return fn === null || fn === void 0 ? void 0 : fn.bind(obj); } diff --git a/crates/swc/tests/vercel/loader-only/2/output/index.js b/crates/swc/tests/vercel/loader-only/2/output/index.js index 1d9791ebad7..8805cc89e04 100644 --- a/crates/swc/tests/vercel/loader-only/2/output/index.js +++ b/crates/swc/tests/vercel/loader-only/2/output/index.js @@ -4,11 +4,10 @@ import { useRouter } from "next/router"; import { useProject } from "@swr/use-project"; import useTeam from "@swr/use-team"; export default function MyComp() { - var _projectInfo; var _useRouter_query = useRouter().query, projectName = _useRouter_query.project; var _useProject = useProject(projectName), projectInfo = _useProject.data; var teamSlug = useTeam().teamSlug; - var projectId = (_projectInfo = projectInfo) === null || _projectInfo === void 0 ? void 0 : _projectInfo.id; + var projectId = projectInfo === null || projectInfo === void 0 ? void 0 : projectInfo.id; var _useProjectBranches = useProjectBranches(projectId), branches = _useProjectBranches.data; return /*#__PURE__*/ _jsx(_Fragment, {}); } diff --git a/crates/swc_ecma_preset_env/src/lib.rs b/crates/swc_ecma_preset_env/src/lib.rs index d87fed4b4d4..826b7f4a504 100644 --- a/crates/swc_ecma_preset_env/src/lib.rs +++ b/crates/swc_ecma_preset_env/src/lib.rs @@ -173,10 +173,13 @@ where let pass = add!( pass, OptionalChaining, - es2020::optional_chaining(es2020::optional_chaining::Config { - no_document_all: loose || assumptions.no_document_all, - pure_getter: loose || assumptions.pure_getters - }) + es2020::optional_chaining( + es2020::optional_chaining::Config { + no_document_all: loose || assumptions.no_document_all, + pure_getter: loose || assumptions.pure_getters + }, + global_mark + ) ); // ES2019 diff --git a/crates/swc_ecma_transforms_compat/src/es2020/mod.rs b/crates/swc_ecma_transforms_compat/src/es2020/mod.rs index 39d5c674099..c116b3c6ded 100644 --- a/crates/swc_ecma_transforms_compat/src/es2020/mod.rs +++ b/crates/swc_ecma_transforms_compat/src/es2020/mod.rs @@ -1,5 +1,5 @@ use serde::Deserialize; -use swc_common::chain; +use swc_common::{chain, Mark}; use swc_ecma_visit::Fold; pub use self::{ @@ -11,10 +11,10 @@ mod export_namespace_from; pub mod nullish_coalescing; pub mod optional_chaining; -pub fn es2020(config: Config) -> impl Fold { +pub fn es2020(config: Config, unresolved_mark: Mark) -> impl Fold { chain!( nullish_coalescing(config.nullish_coalescing), - optional_chaining(config.optional_chaining), + optional_chaining(config.optional_chaining, unresolved_mark), export_namespace_from(), ) } diff --git a/crates/swc_ecma_transforms_compat/src/es2020/optional_chaining.rs b/crates/swc_ecma_transforms_compat/src/es2020/optional_chaining.rs index 1ce54d21849..034907e4a29 100644 --- a/crates/swc_ecma_transforms_compat/src/es2020/optional_chaining.rs +++ b/crates/swc_ecma_transforms_compat/src/es2020/optional_chaining.rs @@ -1,16 +1,17 @@ use std::mem; use serde::Deserialize; -use swc_common::{util::take::Take, DUMMY_SP}; +use swc_common::{util::take::Take, Mark, SyntaxContext, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_utils::{ alias_ident_for, prepend_stmt, quote_ident, undefined, ExprFactory, StmtLike, }; use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; -pub fn optional_chaining(c: Config) -> impl Fold + VisitMut { +pub fn optional_chaining(c: Config, unresolved_mark: Mark) -> impl Fold + VisitMut { as_folder(OptChaining { c, + unresolved: SyntaxContext::empty().apply_mark(unresolved_mark), ..Default::default() }) } @@ -18,6 +19,7 @@ pub fn optional_chaining(c: Config) -> impl Fold + VisitMut { #[derive(Default)] struct OptChaining { vars: Vec, + unresolved: SyntaxContext, c: Config, } @@ -63,7 +65,7 @@ impl VisitMut for OptChaining { // foo?.bar -> foo == null ? void 0 : foo.bar Expr::OptChain(v) => { let data = self.gather(v.take(), vec![]); - *e = self.construct(data, false, self.c.no_document_all); + *e = self.construct(data, false); } Expr::Unary(UnaryExpr { @@ -75,7 +77,7 @@ impl VisitMut for OptChaining { // delete foo?.bar -> foo == null ? true : delete foo.bar Expr::OptChain(v) => { let data = self.gather(v.take(), vec![]); - *e = self.construct(data, true, self.c.no_document_all); + *e = self.construct(data, true); } _ => e.visit_mut_children_with(self), } @@ -145,12 +147,27 @@ impl VisitMut for OptChaining { } } +#[derive(Debug, Clone)] +enum Memo { + Cache(Ident), + Raw(Box), +} + +impl Memo { + fn into_expr(self) -> Expr { + match self { + Memo::Cache(i) => Expr::Ident(i), + Memo::Raw(e) => *e, + } + } +} + #[derive(Debug)] enum Gathering { Call(CallExpr), Member(MemberExpr), - OptCall(CallExpr, Ident), - OptMember(MemberExpr, Ident), + OptCall(CallExpr, Memo), + OptMember(MemberExpr, Memo), } impl OptChaining { @@ -181,7 +198,7 @@ impl OptChaining { next = m.obj.take(); m.prop.visit_mut_with(self); chain.push(if optional { - Gathering::OptMember(m.take(), self.memoize(&next)) + Gathering::OptMember(m.take(), self.memoize(&next, false)) } else { Gathering::Member(m.take()) }); @@ -192,7 +209,7 @@ impl OptChaining { c.args.visit_mut_with(self); // I don't know why c is an OptCall instead of a CallExpr. chain.push(if optional { - Gathering::OptCall(c.take().into(), self.memoize(&next)) + Gathering::OptCall(c.take().into(), self.memoize(&next, true)) } else { Gathering::Call(c.take().into()) }); @@ -213,12 +230,7 @@ impl OptChaining { /// Constructs a rightward nested conditional expression out of our /// flattened chain. - fn construct( - &mut self, - data: (Expr, usize, Vec), - is_delete: bool, - no_document_all: bool, - ) -> Expr { + fn construct(&mut self, data: (Expr, usize, Vec), is_delete: bool) -> Expr { let (mut current, count, chain) = data; // Stores partially constructed CondExprs for us to assemble later on. @@ -260,16 +272,22 @@ impl OptChaining { Expr::Member(m) => { call = true; let this = ctx.unwrap_or_else(|| { - let this = self.memoize(&m.obj); - m.obj = Box::new(Expr::Assign(AssignExpr { - span: DUMMY_SP, - op: op!("="), - left: this.clone().into(), - right: m.obj.take(), - })); - this + let this = self.memoize(&m.obj, true); + + match &this { + Memo::Cache(i) => { + m.obj = Box::new(Expr::Assign(AssignExpr { + span: DUMMY_SP, + op: op!("="), + left: i.clone().into(), + right: m.obj.take(), + })); + this + } + Memo::Raw(_) => this, + } }); - c.args.insert(0, this.as_arg()); + c.args.insert(0, this.into_expr().as_arg()); } Expr::SuperProp(s) => { call = true; @@ -280,7 +298,7 @@ impl OptChaining { committed_cond.push(CondExpr { span: DUMMY_SP, - test: init_and_eq_null_or_undefined(&memo, current, no_document_all), + test: init_and_eq_null_or_undefined(&memo, current, self.c.no_document_all), cons: if is_delete { true.into() } else { @@ -289,9 +307,11 @@ impl OptChaining { alt: Take::dummy(), }); c.callee = if call { - memo.make_member(quote_ident!("call")).as_callee() + memo.into_expr() + .make_member(quote_ident!("call")) + .as_callee() } else { - memo.as_callee() + memo.into_expr().as_callee() }; ctx = None; Expr::Call(c) @@ -299,7 +319,7 @@ impl OptChaining { Gathering::OptMember(mut m, memo) => { committed_cond.push(CondExpr { span: DUMMY_SP, - test: init_and_eq_null_or_undefined(&memo, current, no_document_all), + test: init_and_eq_null_or_undefined(&memo, current, self.c.no_document_all), cons: if is_delete { true.into() } else { @@ -308,7 +328,7 @@ impl OptChaining { alt: Take::dummy(), }); ctx = Some(memo.clone()); - m.obj = memo.into(); + m.obj = memo.into_expr().into(); Expr::Member(m) } }; @@ -331,15 +351,41 @@ impl OptChaining { current } - fn memoize(&mut self, expr: &Expr) -> Ident { - let memo = alias_ident_for(expr, "_this"); - self.vars.push(VarDeclarator { - span: DUMMY_SP, - name: memo.clone().into(), - init: None, - definite: false, - }); - memo + fn should_memo(&self, expr: &Expr, is_call: bool) -> bool { + fn is_simple_member(e: &Expr) -> bool { + match e { + Expr::Ident(_) => true, + Expr::SuperProp(s) if !s.prop.is_computed() => true, + Expr::Member(m) if !m.prop.is_computed() => is_simple_member(&m.obj), + _ => false, + } + } + + match expr { + Expr::Ident(i) if i.span.ctxt != self.unresolved => false, + _ => { + if is_call && self.c.pure_getter { + !is_simple_member(expr) + } else { + true + } + } + } + } + + fn memoize(&mut self, expr: &Expr, is_call: bool) -> Memo { + if self.should_memo(expr, is_call) { + let memo = alias_ident_for(expr, "_this"); + self.vars.push(VarDeclarator { + span: DUMMY_SP, + name: memo.clone().into(), + init: None, + definite: false, + }); + Memo::Cache(memo) + } else { + Memo::Raw(Box::new(expr.to_owned())) + } } fn visit_mut_stmt_like(&mut self, stmts: &mut Vec) @@ -371,13 +417,16 @@ impl OptChaining { } } -fn init_and_eq_null_or_undefined(i: &Ident, init: Expr, no_document_all: bool) -> Box { - let lhs = Box::new(Expr::Assign(AssignExpr { - span: DUMMY_SP, - op: op!("="), - left: PatOrExpr::Pat(i.clone().into()), - right: Box::new(init), - })); +fn init_and_eq_null_or_undefined(i: &Memo, init: Expr, no_document_all: bool) -> Box { + let lhs = match i { + Memo::Cache(i) => Box::new(Expr::Assign(AssignExpr { + span: DUMMY_SP, + op: op!("="), + left: PatOrExpr::Pat(i.clone().into()), + right: Box::new(init), + })), + Memo::Raw(e) => e.to_owned(), + }; if no_document_all { return Box::new(Expr::Bin(BinExpr { @@ -395,9 +444,14 @@ fn init_and_eq_null_or_undefined(i: &Ident, init: Expr, no_document_all: bool) - right: Box::new(Expr::Lit(Lit::Null(Null { span: DUMMY_SP }))), })); + let left_expr = match i { + Memo::Cache(i) => Box::new(i.clone().into()), + Memo::Raw(e) => e.to_owned(), + }; + let void_cmp = Box::new(Expr::Bin(BinExpr { span: DUMMY_SP, - left: Box::new(Expr::Ident(i.clone())), + left: left_expr, op: op!("==="), right: undefined(DUMMY_SP), })); diff --git a/crates/swc_ecma_transforms_compat/tests/es2020_optional_chaining.rs b/crates/swc_ecma_transforms_compat/tests/es2020_optional_chaining.rs index 63b6d96ca42..5f8161c5d80 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2020_optional_chaining.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2020_optional_chaining.rs @@ -1,12 +1,19 @@ use std::{fs::read_to_string, path::PathBuf}; +use swc_common::{chain, Mark}; use swc_ecma_parser::Syntax; +use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::es2020::{optional_chaining, optional_chaining::Config}; use swc_ecma_transforms_testing::{compare_stdout, test, test_exec, test_fixture}; use swc_ecma_visit::Fold; fn tr(c: Config) -> impl Fold { - optional_chaining(c) + let unresolved_mark = Mark::new(); + let top_level_mark = Mark::new(); + chain!( + resolver(unresolved_mark, top_level_mark, false), + optional_chaining(c, unresolved_mark) + ) } fn syntax() -> Syntax { @@ -264,10 +271,18 @@ fn exec(input: PathBuf) { compare_stdout( Default::default(), |_| { - optional_chaining(Config { - no_document_all: true, - ..Default::default() - }) + let unresolved_mark = Mark::new(); + let top_level_mark = Mark::new(); + chain!( + resolver(unresolved_mark, top_level_mark, false), + optional_chaining( + Config { + no_document_all: true, + ..Default::default() + }, + Mark::new(), + ) + ) }, &src, ); @@ -279,7 +294,14 @@ fn fixture(input: PathBuf) { test_fixture( Default::default(), - &|_| optional_chaining(Default::default()), + &|_| { + let unresolved_mark = Mark::new(); + let top_level_mark = Mark::new(); + chain!( + resolver(unresolved_mark, top_level_mark, false), + optional_chaining(Default::default(), unresolved_mark) + ) + }, &input, &output, Default::default(), @@ -293,10 +315,18 @@ fn fixture_loose(input: PathBuf) { test_fixture( Default::default(), &|_| { - optional_chaining(Config { - no_document_all: true, - pure_getter: true, - }) + let unresolved_mark = Mark::new(); + let top_level_mark = Mark::new(); + chain!( + resolver(unresolved_mark, top_level_mark, false), + optional_chaining( + Config { + no_document_all: true, + pure_getter: true, + }, + Mark::new(), + ) + ) }, &input, &output, diff --git a/crates/swc_ecma_transforms_compat/tests/optional-chaining-loose/general-function-call-loose/output.js b/crates/swc_ecma_transforms_compat/tests/optional-chaining-loose/general-function-call-loose/output.js index 90d964b7874..360de086d20 100644 --- a/crates/swc_ecma_transforms_compat/tests/optional-chaining-loose/general-function-call-loose/output.js +++ b/crates/swc_ecma_transforms_compat/tests/optional-chaining-loose/general-function-call-loose/output.js @@ -1,12 +1,12 @@ -var _foo, _foo1, _foo_bar, _foo2, _foo_bar1, _foo3, _foo_bar_baz, _foo_bar2, _foo_bar3, _foo_bar_baz1, _foo_bar4, _foo4, _foo_bar_baz2, _foo5, _foo_bar5, _foo_bar6, _foo6, _foo_bar_baz3, _foo_bar7, _foo7; -(_foo = foo) == null ? void 0 : _foo(foo); -(_foo1 = foo) == null ? void 0 : _foo1.bar(); -(_foo_bar = (_foo2 = foo).bar) == null ? void 0 : _foo_bar.call(_foo2, foo.bar, false); -(_foo3 = foo) == null ? void 0 : (_foo_bar1 = _foo3.bar) == null ? void 0 : _foo_bar1.call(_foo3, foo.bar, true); -(_foo_bar_baz = (_foo_bar2 = foo.bar).baz) == null ? void 0 : _foo_bar_baz.call(_foo_bar2); -(_foo_bar3 = foo.bar) == null ? void 0 : _foo_bar3.baz(); -(_foo_bar4 = foo.bar) == null ? void 0 : (_foo_bar_baz1 = _foo_bar4.baz) == null ? void 0 : _foo_bar_baz1.call(_foo_bar4); -(_foo4 = foo) == null ? void 0 : _foo4.bar.baz(); -(_foo5 = foo) == null ? void 0 : (_foo_bar_baz2 = (_foo_bar5 = _foo5.bar).baz) == null ? void 0 : _foo_bar_baz2.call(_foo_bar5); -(_foo6 = foo) == null ? void 0 : (_foo_bar6 = _foo6.bar) == null ? void 0 : _foo_bar6.baz(); -(_foo7 = foo) == null ? void 0 : (_foo_bar7 = _foo7.bar) == null ? void 0 : (_foo_bar_baz3 = _foo_bar7.baz) == null ? void 0 : _foo_bar_baz3.call(_foo_bar7); +var _foo_bar, _foo_bar1, _foo_bar_baz, _foo_bar2, _foo_bar_baz1, _foo_bar3, _foo_bar_baz2, _foo_bar4; +foo == null ? void 0 : foo(foo); +foo == null ? void 0 : foo.bar(); +foo.bar == null ? void 0 : foo.bar.call(foo, foo.bar, false); +foo == null ? void 0 : (_foo_bar = foo.bar) == null ? void 0 : _foo_bar.call(foo, foo.bar, true); +foo.bar.baz == null ? void 0 : foo.bar.baz.call(foo.bar); +(_foo_bar1 = foo.bar) == null ? void 0 : _foo_bar1.baz(); +(_foo_bar2 = foo.bar) == null ? void 0 : (_foo_bar_baz = _foo_bar2.baz) == null ? void 0 : _foo_bar_baz.call(_foo_bar2); +foo == null ? void 0 : foo.bar.baz(); +foo == null ? void 0 : (_foo_bar_baz1 = foo.bar.baz) == null ? void 0 : _foo_bar_baz1.call(foo.bar); +foo == null ? void 0 : (_foo_bar3 = foo.bar) == null ? void 0 : _foo_bar3.baz(); +foo == null ? void 0 : (_foo_bar4 = foo.bar) == null ? void 0 : (_foo_bar_baz2 = _foo_bar4.baz) == null ? void 0 : _foo_bar_baz2.call(_foo_bar4); diff --git a/crates/swc_ecma_transforms_compat/tests/optional-chaining-loose/general-function-param-loose/output.js b/crates/swc_ecma_transforms_compat/tests/optional-chaining-loose/general-function-param-loose/output.js index f0f1519e58e..71a47443453 100644 --- a/crates/swc_ecma_transforms_compat/tests/optional-chaining-loose/general-function-param-loose/output.js +++ b/crates/swc_ecma_transforms_compat/tests/optional-chaining-loose/general-function-param-loose/output.js @@ -1,35 +1,17 @@ -var _a, _a_b_c, _a_b, _a_b_c1, _a_b1, _a_b2, _a1; -function f(a = (()=>{ - var _x; - return (_x = x) == null ? void 0 : _x.y; -})()) {} -function g({ a, b = (_a = a) == null ? void 0 : _a.c }) {} -function h(a, { b = (_a_b = a.b) == null ? void 0 : (_a_b_c = _a_b.c) == null ? void 0 : _a_b_c.d.e }) {} -function i(a, { b = ((_a_b1 = a.b) == null ? void 0 : (_a_b_c1 = _a_b1.c) == null ? void 0 : _a_b_c1.d).e }) {} -function j(a, { b = (_a1 = a) == null ? void 0 : (_a_b2 = _a1.b) == null ? void 0 : _a_b2.c().d.e }) {} -const k = function(a, b = (()=>{ - var _a; - return (_a = a) == null ? void 0 : _a.b; -})()) {}; -const l = (a, b = (()=>{ - var _a; - return (_a = a) == null ? void 0 : _a.b; -})())=>{}; +var _a_b_c, _a_b, _a_b_c1, _a_b1, _a_b2; +function f(a1 = x == null ? void 0 : x.y) {} +function g({ a: a1, b: b1 = a1 == null ? void 0 : a1.c }) {} +function h(a1, { b: b1 = (_a_b = a1.b) == null ? void 0 : (_a_b_c = _a_b.c) == null ? void 0 : _a_b_c.d.e }) {} +function i(a1, { b: b1 = ((_a_b1 = a1.b) == null ? void 0 : (_a_b_c1 = _a_b1.c) == null ? void 0 : _a_b_c1.d).e }) {} +function j(a1, { b: b1 = a1 == null ? void 0 : (_a_b2 = a1.b) == null ? void 0 : _a_b2.c().d.e }) {} +const k = function(a1, b1 = a1 == null ? void 0 : a1.b) {}; +const l = (a1, b1 = a1 == null ? void 0 : a1.b)=>{}; const m = { - m (a, b = (()=>{ - var _a; - return (_a = a) == null ? void 0 : _a.b; - })()) {} + m (a1, b1 = a1 == null ? void 0 : a1.b) {} }; const n = class { - n(a, b = (()=>{ - var _a; - return (_a = a) == null ? void 0 : _a.b; - })()) {} + n(a1, b1 = a1 == null ? void 0 : a1.b) {} }; const o = { - set o (a = (()=>{ - var _b; - return (_b = b) == null ? void 0 : _b.c; - })()){} + set o (a = b == null ? void 0 : b.c){} }; diff --git a/crates/swc_ecma_transforms_compat/tests/optional-chaining-loose/general-member-expression-loose/output.js b/crates/swc_ecma_transforms_compat/tests/optional-chaining-loose/general-member-expression-loose/output.js index eed6dadc287..fccc80f266a 100644 --- a/crates/swc_ecma_transforms_compat/tests/optional-chaining-loose/general-member-expression-loose/output.js +++ b/crates/swc_ecma_transforms_compat/tests/optional-chaining-loose/general-member-expression-loose/output.js @@ -1,12 +1,12 @@ -var _foo, _foo1, _foo2, _foo_bar, _foo3, _foo_bar1, _foo4, _foo_bar_baz, _foo_bar2, _foo_bar_baz1, _foo_bar3, _foo5, _foo_bar_baz2, _foo6, _foo_bar4, _foo7, _foo_bar_baz3, _foo_bar5, _foo8; -(_foo = foo) == null ? void 0 : _foo[foo]; -(_foo1 = foo) == null ? void 0 : _foo1.bar[0]; -(_foo_bar = foo.bar) == null ? void 0 : _foo_bar[(_foo2 = foo) == null ? void 0 : _foo2.bar]; -(_foo4 = foo) == null ? void 0 : (_foo_bar1 = _foo4.bar) == null ? void 0 : _foo_bar1[(_foo3 = foo) == null ? void 0 : _foo3.bar]; +var _foo_bar, _foo_bar1, _foo_bar_baz, _foo_bar2, _foo_bar_baz1, _foo_bar3, _foo_bar_baz2, _foo_bar4, _foo_bar_baz3, _foo_bar5; +foo == null ? void 0 : foo[foo]; +foo == null ? void 0 : foo.bar[0]; +(_foo_bar = foo.bar) == null ? void 0 : _foo_bar[foo == null ? void 0 : foo.bar]; +foo == null ? void 0 : (_foo_bar1 = foo.bar) == null ? void 0 : _foo_bar1[foo == null ? void 0 : foo.bar]; (_foo_bar_baz = foo.bar.baz) == null ? void 0 : _foo_bar_baz.d; (_foo_bar2 = foo.bar) == null ? void 0 : _foo_bar2.baz.d; (_foo_bar3 = foo.bar) == null ? void 0 : (_foo_bar_baz1 = _foo_bar3.baz) == null ? void 0 : _foo_bar_baz1.d; -(_foo5 = foo) == null ? void 0 : _foo5.bar.baz.d; -(_foo6 = foo) == null ? void 0 : (_foo_bar_baz2 = _foo6.bar.baz) == null ? void 0 : _foo_bar_baz2.d; -(_foo7 = foo) == null ? void 0 : (_foo_bar4 = _foo7.bar) == null ? void 0 : _foo_bar4.baz.d; -(_foo8 = foo) == null ? void 0 : (_foo_bar5 = _foo8.bar) == null ? void 0 : (_foo_bar_baz3 = _foo_bar5.baz) == null ? void 0 : _foo_bar_baz3.d; +foo == null ? void 0 : foo.bar.baz.d; +foo == null ? void 0 : (_foo_bar_baz2 = foo.bar.baz) == null ? void 0 : _foo_bar_baz2.d; +foo == null ? void 0 : (_foo_bar4 = foo.bar) == null ? void 0 : _foo_bar4.baz.d; +foo == null ? void 0 : (_foo_bar5 = foo.bar) == null ? void 0 : (_foo_bar_baz3 = _foo_bar5.baz) == null ? void 0 : _foo_bar_baz3.d; diff --git a/crates/swc_ecma_transforms_compat/tests/optional-chaining-loose/general-memoize-loose/output.js b/crates/swc_ecma_transforms_compat/tests/optional-chaining-loose/general-memoize-loose/output.js index 18ccebb4e2f..addfd254d07 100644 --- a/crates/swc_ecma_transforms_compat/tests/optional-chaining-loose/general-memoize-loose/output.js +++ b/crates/swc_ecma_transforms_compat/tests/optional-chaining-loose/general-memoize-loose/output.js @@ -1,19 +1,19 @@ "use strict"; function test(foo) { - var _foo, _foo_bar, _foo1, _foo2, _foo3, _foo_get, _foo_bar1, _foo_bar2, _foo_bar_baz, _foo_bar3, _foo_bar_baz1, _foo_bar4, _foo_bar5, _foo4, _foo_bar6, _foo5, _foo_bar7, _foo_bar8, _foo6, _foo_bar_baz2, _foo_bar9, _foo_bar_baz3, _foo_bar10, _foo7; - (_foo = foo) == null ? void 0 : _foo.bar; - (_foo1 = foo) == null ? void 0 : (_foo_bar = _foo1.bar) == null ? void 0 : _foo_bar.baz; - (_foo2 = foo) == null ? void 0 : _foo2(foo); - (_foo3 = foo) == null ? void 0 : _foo3.bar(); + var _foo_bar, _foo_get, _foo_bar1, _foo_bar2, _foo_bar_baz, _foo_bar3, _foo_bar_baz1, _foo_bar4, _foo_bar5, _foo_bar6, _foo_bar7, _foo_bar_baz2, _foo_bar8, _foo_bar_baz3, _foo_bar9; + foo == null ? void 0 : foo.bar; + foo == null ? void 0 : (_foo_bar = foo.bar) == null ? void 0 : _foo_bar.baz; + foo == null ? void 0 : foo(foo); + foo == null ? void 0 : foo.bar(); (_foo_get = foo.get(bar)) == null ? void 0 : _foo_get(); (_foo_bar1 = foo.bar()) == null ? void 0 : _foo_bar1(); (_foo_bar2 = foo[bar]()) == null ? void 0 : _foo_bar2(); (_foo_bar_baz = (_foo_bar3 = foo.bar()).baz) == null ? void 0 : _foo_bar_baz.call(_foo_bar3); (_foo_bar_baz1 = (_foo_bar4 = foo[bar]()).baz) == null ? void 0 : _foo_bar_baz1.call(_foo_bar4); - (_foo_bar5 = (_foo4 = foo).bar) == null ? void 0 : _foo_bar5.call(_foo4, foo.bar, false); - (_foo5 = foo) == null ? void 0 : (_foo_bar6 = _foo5.bar) == null ? void 0 : _foo_bar6.call(_foo5, foo.bar, true); - (_foo_bar7 = foo.bar) == null ? void 0 : _foo_bar7.baz(foo.bar, false); - (_foo6 = foo) == null ? void 0 : (_foo_bar8 = _foo6.bar) == null ? void 0 : _foo_bar8.baz(foo.bar, true); - (_foo_bar9 = foo.bar) == null ? void 0 : (_foo_bar_baz2 = _foo_bar9.baz) == null ? void 0 : _foo_bar_baz2.call(_foo_bar9, foo.bar, false); - (_foo7 = foo) == null ? void 0 : (_foo_bar10 = _foo7.bar) == null ? void 0 : (_foo_bar_baz3 = _foo_bar10.baz) == null ? void 0 : _foo_bar_baz3.call(_foo_bar10, foo.bar, true); + foo.bar == null ? void 0 : foo.bar.call(foo, foo.bar, false); + foo == null ? void 0 : (_foo_bar5 = foo.bar) == null ? void 0 : _foo_bar5.call(foo, foo.bar, true); + (_foo_bar6 = foo.bar) == null ? void 0 : _foo_bar6.baz(foo.bar, false); + foo == null ? void 0 : (_foo_bar7 = foo.bar) == null ? void 0 : _foo_bar7.baz(foo.bar, true); + (_foo_bar8 = foo.bar) == null ? void 0 : (_foo_bar_baz2 = _foo_bar8.baz) == null ? void 0 : _foo_bar_baz2.call(_foo_bar8, foo.bar, false); + foo == null ? void 0 : (_foo_bar9 = foo.bar) == null ? void 0 : (_foo_bar_baz3 = _foo_bar9.baz) == null ? void 0 : _foo_bar_baz3.call(_foo_bar9, foo.bar, true); } diff --git a/crates/swc_ecma_transforms_compat/tests/optional-chaining-loose/general-super-method-call-loose/output.js b/crates/swc_ecma_transforms_compat/tests/optional-chaining-loose/general-super-method-call-loose/output.js index 89803ad8d2f..e1f38d688fa 100644 --- a/crates/swc_ecma_transforms_compat/tests/optional-chaining-loose/general-super-method-call-loose/output.js +++ b/crates/swc_ecma_transforms_compat/tests/optional-chaining-loose/general-super-method-call-loose/output.js @@ -6,7 +6,6 @@ class Base { } class Derived extends Base { method() { - var _super_method; - return (_super_method = super.method) == null ? void 0 : _super_method.call(this); + return super.method == null ? void 0 : super.method.call(this); } } diff --git a/crates/swc_ecma_transforms_compat/tests/optional-chaining/general-assignment/output.js b/crates/swc_ecma_transforms_compat/tests/optional-chaining/general-assignment/output.js index 8f38bcc767c..35da1e985c4 100644 --- a/crates/swc_ecma_transforms_compat/tests/optional-chaining/general-assignment/output.js +++ b/crates/swc_ecma_transforms_compat/tests/optional-chaining/general-assignment/output.js @@ -1,5 +1,5 @@ "use strict"; -var _obj, _obj_a, _obj1, _obj_b, _obj2, _obj_a1, _obj3; +var _obj_a, _obj_b, _obj_a1; const obj = { a: { b: { @@ -9,8 +9,8 @@ const obj = { } } }; -const a = (_obj = obj) === null || _obj === void 0 ? void 0 : _obj.a; -const b = (_obj1 = obj) === null || _obj1 === void 0 ? void 0 : (_obj_a = _obj1.a) === null || _obj_a === void 0 ? void 0 : _obj_a.b; -const bad = (_obj2 = obj) === null || _obj2 === void 0 ? void 0 : (_obj_b = _obj2.b) === null || _obj_b === void 0 ? void 0 : _obj_b.b; +const a = obj === null || obj === void 0 ? void 0 : obj.a; +const b = obj === null || obj === void 0 ? void 0 : (_obj_a = obj.a) === null || _obj_a === void 0 ? void 0 : _obj_a.b; +const bad = obj === null || obj === void 0 ? void 0 : (_obj_b = obj.b) === null || _obj_b === void 0 ? void 0 : _obj_b.b; let val; -val = (_obj3 = obj) === null || _obj3 === void 0 ? void 0 : (_obj_a1 = _obj3.a) === null || _obj_a1 === void 0 ? void 0 : _obj_a1.b; +val = obj === null || obj === void 0 ? void 0 : (_obj_a1 = obj.a) === null || _obj_a1 === void 0 ? void 0 : _obj_a1.b; diff --git a/crates/swc_ecma_transforms_compat/tests/optional-chaining/general-delete/output.js b/crates/swc_ecma_transforms_compat/tests/optional-chaining/general-delete/output.js index b5e2b607027..68bf5daade8 100644 --- a/crates/swc_ecma_transforms_compat/tests/optional-chaining/general-delete/output.js +++ b/crates/swc_ecma_transforms_compat/tests/optional-chaining/general-delete/output.js @@ -1,11 +1,11 @@ "use strict"; -var _obj_a, _obj, _obj1, _obj_b, _obj2, _obj3; +var _obj_a, _obj_b; const obj = { a: { b: 0 } }; -let test = (_obj = obj) === null || _obj === void 0 ? true : (_obj_a = _obj.a) === null || _obj_a === void 0 ? true : delete _obj_a.b; -test = (_obj1 = obj) === null || _obj1 === void 0 ? true : delete _obj1.a.b; -test = (_obj2 = obj) === null || _obj2 === void 0 ? true : (_obj_b = _obj2.b) === null || _obj_b === void 0 ? true : delete _obj_b.b; -(_obj3 = obj) === null || _obj3 === void 0 ? true : delete _obj3.a; +let test = obj === null || obj === void 0 ? true : (_obj_a = obj.a) === null || _obj_a === void 0 ? true : delete _obj_a.b; +test = obj === null || obj === void 0 ? true : delete obj.a.b; +test = obj === null || obj === void 0 ? true : (_obj_b = obj.b) === null || _obj_b === void 0 ? true : delete _obj_b.b; +obj === null || obj === void 0 ? true : delete obj.a; diff --git a/crates/swc_ecma_transforms_compat/tests/optional-chaining/general-memoize/output.js b/crates/swc_ecma_transforms_compat/tests/optional-chaining/general-memoize/output.js index 5b9bebc7dba..4ff1775fe40 100644 --- a/crates/swc_ecma_transforms_compat/tests/optional-chaining/general-memoize/output.js +++ b/crates/swc_ecma_transforms_compat/tests/optional-chaining/general-memoize/output.js @@ -1,13 +1,13 @@ function test(foo) { - var _foo, _foo_bar, _foo1, _foo2, _foo3, _foo_bar1, _foo4, _foo_bar2, _foo5, _foo_bar3, _foo_bar4, _foo6, _foo_bar_baz, _foo_bar5, _foo_bar_baz1, _foo_bar6, _foo7; - (_foo = foo) === null || _foo === void 0 ? void 0 : _foo.bar; - (_foo1 = foo) === null || _foo1 === void 0 ? void 0 : (_foo_bar = _foo1.bar) === null || _foo_bar === void 0 ? void 0 : _foo_bar.baz; - (_foo2 = foo) === null || _foo2 === void 0 ? void 0 : _foo2(foo); - (_foo3 = foo) === null || _foo3 === void 0 ? void 0 : _foo3.bar(); - (_foo_bar1 = (_foo4 = foo).bar) === null || _foo_bar1 === void 0 ? void 0 : _foo_bar1.call(_foo4, foo.bar, false); - (_foo5 = foo) === null || _foo5 === void 0 ? void 0 : (_foo_bar2 = _foo5.bar) === null || _foo_bar2 === void 0 ? void 0 : _foo_bar2.call(_foo5, foo.bar, true); + var _foo_bar, _foo_bar1, _foo_bar2, _foo_bar3, _foo_bar4, _foo_bar_baz, _foo_bar5, _foo_bar_baz1, _foo_bar6; + foo === null || foo === void 0 ? void 0 : foo.bar; + foo === null || foo === void 0 ? void 0 : (_foo_bar = foo.bar) === null || _foo_bar === void 0 ? void 0 : _foo_bar.baz; + foo === null || foo === void 0 ? void 0 : foo(foo); + foo === null || foo === void 0 ? void 0 : foo.bar(); + (_foo_bar1 = foo.bar) === null || _foo_bar1 === void 0 ? void 0 : _foo_bar1.call(foo, foo.bar, false); + foo === null || foo === void 0 ? void 0 : (_foo_bar2 = foo.bar) === null || _foo_bar2 === void 0 ? void 0 : _foo_bar2.call(foo, foo.bar, true); (_foo_bar3 = foo.bar) === null || _foo_bar3 === void 0 ? void 0 : _foo_bar3.baz(foo.bar, false); - (_foo6 = foo) === null || _foo6 === void 0 ? void 0 : (_foo_bar4 = _foo6.bar) === null || _foo_bar4 === void 0 ? void 0 : _foo_bar4.baz(foo.bar, true); + foo === null || foo === void 0 ? void 0 : (_foo_bar4 = foo.bar) === null || _foo_bar4 === void 0 ? void 0 : _foo_bar4.baz(foo.bar, true); (_foo_bar5 = foo.bar) === null || _foo_bar5 === void 0 ? void 0 : (_foo_bar_baz = _foo_bar5.baz) === null || _foo_bar_baz === void 0 ? void 0 : _foo_bar_baz.call(_foo_bar5, foo.bar, false); - (_foo7 = foo) === null || _foo7 === void 0 ? void 0 : (_foo_bar6 = _foo7.bar) === null || _foo_bar6 === void 0 ? void 0 : (_foo_bar_baz1 = _foo_bar6.baz) === null || _foo_bar_baz1 === void 0 ? void 0 : _foo_bar_baz1.call(_foo_bar6, foo.bar, true); + foo === null || foo === void 0 ? void 0 : (_foo_bar6 = foo.bar) === null || _foo_bar6 === void 0 ? void 0 : (_foo_bar_baz1 = _foo_bar6.baz) === null || _foo_bar_baz1 === void 0 ? void 0 : _foo_bar_baz1.call(_foo_bar6, foo.bar, true); } diff --git a/crates/swc_ecma_transforms_compat/tests/optional-chaining/general-unary/output.js b/crates/swc_ecma_transforms_compat/tests/optional-chaining/general-unary/output.js index 8c7ba3673ba..9e7d3045683 100644 --- a/crates/swc_ecma_transforms_compat/tests/optional-chaining/general-unary/output.js +++ b/crates/swc_ecma_transforms_compat/tests/optional-chaining/general-unary/output.js @@ -1,11 +1,11 @@ "use strict"; -var _obj_a, _obj, _obj1, _obj_b, _obj2, _obj_b1, _obj3; +var _obj_a, _obj_b, _obj_b1; const obj = { a: { b: 0 } }; -let test = +((_obj = obj) === null || _obj === void 0 ? void 0 : (_obj_a = _obj.a) === null || _obj_a === void 0 ? void 0 : _obj_a.b); -test = +((_obj1 = obj) === null || _obj1 === void 0 ? void 0 : _obj1.a.b); -test = +((_obj2 = obj) === null || _obj2 === void 0 ? void 0 : (_obj_b = _obj2.b) === null || _obj_b === void 0 ? void 0 : _obj_b.b); -test = +((_obj3 = obj) === null || _obj3 === void 0 ? void 0 : (_obj_b1 = _obj3.b) === null || _obj_b1 === void 0 ? void 0 : _obj_b1.b); +let test = +(obj === null || obj === void 0 ? 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 ? void 0 : (_obj_b = obj.b) === null || _obj_b === void 0 ? void 0 : _obj_b.b); +test = +(obj === null || obj === void 0 ? void 0 : (_obj_b1 = obj.b) === null || _obj_b1 === void 0 ? void 0 : _obj_b1.b); diff --git a/crates/swc_ecma_transforms_typescript/benches/compat.rs b/crates/swc_ecma_transforms_typescript/benches/compat.rs index 9b4e2ca9e7c..705cb879aca 100644 --- a/crates/swc_ecma_transforms_typescript/benches/compat.rs +++ b/crates/swc_ecma_transforms_typescript/benches/compat.rs @@ -152,7 +152,7 @@ fn es2020_nullish_coalescing(b: &mut Bencher) { fn es2020_optional_chaining(b: &mut Bencher) { run(b, || { - swc_ecma_transforms_compat::es2020::optional_chaining(Default::default()) + swc_ecma_transforms_compat::es2020::optional_chaining(Default::default(), Mark::new()) }); } diff --git a/crates/swc_ecma_transforms_typescript/tests/strip.rs b/crates/swc_ecma_transforms_typescript/tests/strip.rs index 549a7ee9a62..0f820fb59e0 100644 --- a/crates/swc_ecma_transforms_typescript/tests/strip.rs +++ b/crates/swc_ecma_transforms_typescript/tests/strip.rs @@ -3146,7 +3146,20 @@ test!( decorators: true, ..Default::default() }), - |_| chain!(tr(), optional_chaining(Default::default())), + |_| { + let unresolved_mark = Mark::new(); + let top_level_mark = Mark::new(); + let config = strip::Config { + no_empty_export: true, + ..Default::default() + }; + chain!( + Optional::new(decorators(Default::default()), false,), + resolver(unresolved_mark, top_level_mark, true), + strip_with_config(config, top_level_mark), + optional_chaining(Default::default(), unresolved_mark) + ) + }, issue_1149_1, " const tmp = tt?.map((t: any) => t).join((v: any) => v); diff --git a/crates/swc_estree_compat/benches/babelify.rs b/crates/swc_estree_compat/benches/babelify.rs index 7b0b94f68c6..5076f7615e6 100644 --- a/crates/swc_estree_compat/benches/babelify.rs +++ b/crates/swc_estree_compat/benches/babelify.rs @@ -55,7 +55,7 @@ fn babelify_only(b: &mut Bencher) { module .fold_with(&mut resolver(unresolved_mark, top_level_mark, true)) .fold_with(&mut typescript::strip(top_level_mark)) - .fold_with(&mut es2020(Default::default())) + .fold_with(&mut es2020(Default::default(), unresolved_mark)) }); b.iter(|| {