Skip to content

Commit

Permalink
feat(es/compat): impl pure_getters for optional_chaining
Browse files Browse the repository at this point in the history
  • Loading branch information
Austaras committed Sep 10, 2023
1 parent 5431010 commit fe637b8
Show file tree
Hide file tree
Showing 62 changed files with 554 additions and 553 deletions.
19 changes: 11 additions & 8 deletions crates/swc/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
10 changes: 4 additions & 6 deletions crates/swc/tests/fixture/issues-3xxx/3381/1/output/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
};
Expand Down
14 changes: 7 additions & 7 deletions crates/swc/tests/fixture/issues-4xxx/4108/1/output/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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;
Expand Down Expand Up @@ -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){
Expand Down Expand Up @@ -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
];
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
24 changes: 8 additions & 16 deletions crates/swc/tests/fixture/issues-7xxx/7547/output/1.js
Original file line number Diff line number Diff line change
@@ -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;
})();
2 changes: 1 addition & 1 deletion crates/swc/tests/fixture/issues-7xxx/7659/1/output/1.ts
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 1 addition & 1 deletion crates/swc/tests/fixture/issues-7xxx/7659/2/output/1.ts
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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;
Expand Down
70 changes: 35 additions & 35 deletions crates/swc/tests/tsc-references/callChain.1.normal.js
Original file line number Diff line number Diff line change
@@ -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;
8 changes: 4 additions & 4 deletions crates/swc/tests/tsc-references/callChain.2.1.normal.js
Original file line number Diff line number Diff line change
@@ -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;
4 changes: 2 additions & 2 deletions crates/swc/tests/tsc-references/callChain.2.2.minified.js
Original file line number Diff line number Diff line change
@@ -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;
Loading

0 comments on commit fe637b8

Please sign in to comment.