Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(es/compat): Visit arrow body from optional chaining pass #7549

Merged
merged 5 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"use strict";const createRegisterItems=registerType=>async(a,b)=>{const a=root?.test};
"use strict";const createRegisterItems=registerType=>async(a,b)=>{var _root;const a=(_root=root)===null||_root===void 0?void 0:_root.test};
10 changes: 6 additions & 4 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,13 +5,15 @@ var dummyTsFunction = function() {
2
];
var func1 = function(array) {
return(// Mapping array
array?.map(function(i) {
var // Mapping array
_array;
return (_array = array) === null || _array === void 0 ? void 0 : _array.map(function(i) {
return i;
}));
});
};
var func2 = function(array) {
return array?.map(function(i) {
var _array;
return (_array = array) === null || _array === void 0 ? void 0 : _array.map(function(i) {
return i;
});
};
Expand Down
10 changes: 5 additions & 5 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, errors;
var _tx, 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?.meta && tx.meta.logMessages) {
if (((_tx = 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, errors;
var awaitConfirmation, commitment, includesFeePayer, block, transaction, _tmp, _transaction, _transaction1, _transaction2, rawTransaction, options, txid, slot, _confirmation, _confirmation1, 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?.slot || 0;
if (!confirmation?.err) return [
slot = ((_confirmation = confirmation) === null || _confirmation === void 0 ? void 0 : _confirmation.slot) || 0;
if (!((_confirmation1 = confirmation) === null || _confirmation1 === void 0 ? void 0 : _confirmation1.err)) return [
3,
9
];
Expand Down
26 changes: 26 additions & 0 deletions crates/swc/tests/fixture/issues-7xxx/7547/input/1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// code below dont work
const a = {};

new Promise(r => {
r(a?.b);
}).then(a => {
return a?.b;
});

const anony = () => {
return a?.b;
}

// code below works

const b = a?.b;

function fn() {
return a?.b;
}

setTimeout(() => a?.b, 0);

const anony2 = function () { return a?.b };

(function () { return a?.b })();
32 changes: 32 additions & 0 deletions crates/swc/tests/fixture/issues-7xxx/7547/output/1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 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);
}).then(function(a) {
var _a;
return (_a = 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;
};
// code below works
var b = (_a = a) === null || _a === void 0 ? void 0 : _a.b;
function fn() {
var _a;
return (_a = a) === null || _a === void 0 ? void 0 : _a.b;
}
setTimeout(function() {
var _a;
return (_a = 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;
};
(function() {
var _a;
return (_a = a) === null || _a === void 0 ? void 0 : _a.b;
})();
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ class C extends B {
C.y2 = C.x();
})();
(()=>{
C.y3 = C?.x();
var _C;
C.y3 = (_C = C) === null || _C === void 0 ? void 0 : _C.x();
})();
(()=>{
C.y4 = C["x"]();
})();
(()=>{
C.y5 = C?.["x"]();
var _C;
C.y5 = (_C = C) === null || _C === void 0 ? void 0 : _C["x"]();
})();
(()=>{
C.z1 = _get(_get_prototype_of(C), "a", C);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class C extends B {
super(...args), this.x = 1, this.y = this.x, this.z = super.f();
}
}
C.x = void 0, C.y1 = C.x, C.y2 = C.x(), C.y3 = C?.x(), C.y4 = C.x(), C.y5 = C?.x(), C.z1 = _get(_get_prototype_of(C), "a", C), C.z2 = _get(_get_prototype_of(C), "a", C), C.z3 = _get(_get_prototype_of(C), "f", C).call(C), C.z4 = _get(_get_prototype_of(C), "f", C).call(C), C.z5 = _set(_get_prototype_of(C), "a", 0, C, !0), C.z6 = _update(_get_prototype_of(C), "a", C, !0)._ += 1, C.z7 = void _set(_get_prototype_of(C), "a", 0, C, !0), C.z8 = [_update(_get_prototype_of(C), "a", C, !0)._] = [
C.x = void 0, C.y1 = C.x, C.y2 = C.x(), C.y3 = null == C ? void 0 : C.x(), C.y4 = C.x(), C.y5 = null == C ? void 0 : C.x(), C.z1 = _get(_get_prototype_of(C), "a", C), C.z2 = _get(_get_prototype_of(C), "a", C), C.z3 = _get(_get_prototype_of(C), "f", C).call(C), C.z4 = _get(_get_prototype_of(C), "f", C).call(C), C.z5 = _set(_get_prototype_of(C), "a", 0, C, !0), C.z6 = _update(_get_prototype_of(C), "a", C, !0)._ += 1, C.z7 = void _set(_get_prototype_of(C), "a", 0, C, !0), C.z8 = [_update(_get_prototype_of(C), "a", C, !0)._] = [
0
], C.z9 = [_update(_get_prototype_of(C), "a", C, !0)._ = 0] = [
0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ var C = /*#__PURE__*/ function(B1) {
C.y2 = C.x();
})();
(function() {
C.y3 = C?.x();
var _C;
C.y3 = (_C = C) === null || _C === void 0 ? void 0 : _C.x();
})();
(function() {
C.y4 = C["x"]();
})();
(function() {
C.y5 = C?.["x"]();
var _C;
C.y5 = (_C = C) === null || _C === void 0 ? void 0 : _C["x"]();
})();
(function() {
C.z3 = _get(_get_prototype_of(C), "f", C).call(C);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ var C = function(B1) {
}
return C;
}(B);
C.x = void 0, C.y1 = C.x, C.y2 = C.x(), C.y3 = C?.x(), C.y4 = C.x(), C.y5 = C?.x(), C.z3 = _get(_get_prototype_of(C), "f", C).call(C), C.z4 = _get(_get_prototype_of(C), "f", C).call(C);
C.x = void 0, C.y1 = C.x, C.y2 = C.x(), C.y3 = null == C ? void 0 : C.x(), C.y4 = C.x(), C.y5 = null == C ? void 0 : C.x(), C.z3 = _get(_get_prototype_of(C), "f", C).call(C), C.z4 = _get(_get_prototype_of(C), "f", C).call(C);
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ impl VisitMut for OptChaining {
}
_ => *expr = BlockStmtOrExpr::BlockStmt(stmt),
}
} else {
expr.visit_mut_children_with(self);
}
}

Expand Down
Loading