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): Consecutive optional call #6461

Merged
merged 2 commits into from Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -2,7 +2,7 @@
// assignments in shortcutting chain
import _instanceof from "@swc/helpers/src/_instanceof.mjs";
import _type_of from "@swc/helpers/src/_type_of.mjs";
var _o4_x, _o4_x1, _o5_x, _ref, _o5_x1, _o5_x2, _o5_x3, _ref1, _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 === null || o === void 0 ? void 0 : o[a = 1];
a.toString();
Expand Down Expand Up @@ -68,28 +68,28 @@ if ((_o4_x = o4.x) === null || _o4_x === void 0 ? void 0 : _o4_x.y) {
o4.x;
(_o4_x1 = o4.x) === null || _o4_x1 === void 0 ? void 0 : _o4_x1.y;
o4.x.y;
if ((_ref = (_o5_x = o5.x) === null || _o5_x === void 0 ? void 0 : _o5_x.y.z) === null || _ref === void 0 ? void 0 : _ref.w) {
var _o5_x_y_z, _o5_x4, _o5_x5, _ref2;
if ((_o5_x_y_z = (_o5_x = o5.x) === null || _o5_x === void 0 ? void 0 : _o5_x.y.z) === null || _o5_x_y_z === void 0 ? void 0 : _o5_x_y_z.w) {
var _o5_x_y_z2, _o5_x4, _o5_x_y_z3, _o5_x5;
o5.x;
o5.x.y;
o5.x.y.z;
o5.x.y.z.w; // true
(_o5_x_y_z = o5.x.y.z) === null || _o5_x_y_z === void 0 ? void 0 : _o5_x_y_z.w; // true
(_o5_x_y_z2 = o5.x.y.z) === null || _o5_x_y_z2 === void 0 ? void 0 : _o5_x_y_z2.w; // true
(_o5_x4 = o5.x) === null || _o5_x4 === void 0 ? void 0 : _o5_x4.y.z.w; // true
(_ref2 = (_o5_x5 = o5.x) === null || _o5_x5 === void 0 ? void 0 : _o5_x5.y.z) === null || _ref2 === void 0 ? void 0 : _ref2.w; // true
(_o5_x_y_z3 = (_o5_x5 = o5.x) === null || _o5_x5 === void 0 ? void 0 : _o5_x5.y.z) === null || _o5_x_y_z3 === void 0 ? void 0 : _o5_x_y_z3.w; // true
} else {
var _o5_x6, _o5_x7, _o5_x8, _ref3;
var _o5_x6, _o5_x7, _o5_x_y_z4, _o5_x8;
o5.x;
(_o5_x6 = o5.x) === null || _o5_x6 === void 0 ? void 0 : _o5_x6.y;
(_o5_x7 = o5.x) === null || _o5_x7 === void 0 ? void 0 : _o5_x7.y.z;
(_ref3 = (_o5_x8 = o5.x) === null || _o5_x8 === void 0 ? void 0 : _o5_x8.y.z) === null || _ref3 === void 0 ? void 0 : _ref3.w;
(_o5_x_y_z4 = (_o5_x8 = o5.x) === null || _o5_x8 === void 0 ? void 0 : _o5_x8.y.z) === null || _o5_x_y_z4 === void 0 ? void 0 : _o5_x_y_z4.w;
o5.x.y;
o5.x.y.z.w;
}
o5.x;
(_o5_x1 = o5.x) === null || _o5_x1 === void 0 ? void 0 : _o5_x1.y;
(_o5_x2 = o5.x) === null || _o5_x2 === void 0 ? void 0 : _o5_x2.y.z;
(_ref1 = (_o5_x3 = o5.x) === null || _o5_x3 === void 0 ? void 0 : _o5_x3.y.z) === null || _ref1 === void 0 ? void 0 : _ref1.w;
(_o5_x_y_z1 = (_o5_x3 = o5.x) === null || _o5_x3 === void 0 ? void 0 : _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 === null || o6 === void 0 ? void 0 : o6.f()) {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions crates/swc/tests/tsc-references/deleteChain.1.normal.js
@@ -1,15 +1,15 @@
//// [deleteChain.ts]
var _o3_b, _o3_b1, _o4_b, _ref, _o4_b1, _ref1, _o4_b2, _ref2, _o5_b, _ref3, _o5_b1, _ref4, _o6_b, _ref5, _o6_b1, _ref6;
var _o3_b, _o3_b1, _o4_b_c_d, _o4_b, _o4_b_c_d1, _o4_b1, _o4_b_c_d2, _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 ? void 0 : delete o1.b;
delete (o1 === null || o1 === void 0 ? void 0 : o1.b);
o2 === null || o2 === void 0 ? void 0 : delete o2.b.c;
o2 === null || o2 === void 0 ? void 0 : delete o2.b.c;
(_o3_b = o3.b) === null || _o3_b === void 0 ? void 0 : delete _o3_b.c;
delete ((_o3_b1 = o3.b) === null || _o3_b1 === void 0 ? void 0 : _o3_b1.c);
(_ref = (_o4_b = o4.b) === null || _o4_b === void 0 ? void 0 : _o4_b.c.d) === null || _ref === void 0 ? void 0 : delete _ref.e;
(_ref1 = (_o4_b1 = o4.b) === null || _o4_b1 === void 0 ? void 0 : _o4_b1.c.d) === null || _ref1 === void 0 ? void 0 : delete _ref1.e;
delete ((_ref2 = (_o4_b2 = o4.b) === null || _o4_b2 === void 0 ? void 0 : _o4_b2.c.d) === null || _ref2 === void 0 ? void 0 : _ref2.e);
(_ref3 = (_o5_b = o5.b) === null || _o5_b === void 0 ? void 0 : _o5_b.call(o5).c.d) === null || _ref3 === void 0 ? void 0 : delete _ref3.e;
delete ((_ref4 = (_o5_b1 = o5.b) === null || _o5_b1 === void 0 ? void 0 : _o5_b1.call(o5).c.d) === null || _ref4 === void 0 ? void 0 : _ref4.e);
(_ref5 = (_o6_b = o6.b) === null || _o6_b === void 0 ? void 0 : _o6_b["c"].d) === null || _ref5 === void 0 ? void 0 : delete _ref5["e"];
delete ((_ref6 = (_o6_b1 = o6.b) === null || _o6_b1 === void 0 ? void 0 : _o6_b1["c"].d) === null || _ref6 === void 0 ? void 0 : _ref6["e"]);
(_o4_b_c_d = (_o4_b = o4.b) === null || _o4_b === void 0 ? void 0 : _o4_b.c.d) === null || _o4_b_c_d === void 0 ? void 0 : delete _o4_b_c_d.e;
(_o4_b_c_d1 = (_o4_b1 = o4.b) === null || _o4_b1 === void 0 ? void 0 : _o4_b1.c.d) === null || _o4_b_c_d1 === void 0 ? void 0 : delete _o4_b_c_d1.e;
delete ((_o4_b_c_d2 = (_o4_b2 = o4.b) === null || _o4_b2 === void 0 ? void 0 : _o4_b2.c.d) === null || _o4_b_c_d2 === void 0 ? void 0 : _o4_b_c_d2.e);
(_o5_b_c_d = (_o5_b = o5.b) === null || _o5_b === void 0 ? void 0 : _o5_b.call(o5).c.d) === null || _o5_b_c_d === void 0 ? void 0 : delete _o5_b_c_d.e;
delete ((_o5_b_c_d1 = (_o5_b1 = o5.b) === null || _o5_b1 === void 0 ? void 0 : _o5_b1.call(o5).c.d) === null || _o5_b_c_d1 === void 0 ? void 0 : _o5_b_c_d1.e);
(_o6_b_c_d = (_o6_b = o6.b) === null || _o6_b === void 0 ? void 0 : _o6_b["c"].d) === null || _o6_b_c_d === void 0 ? void 0 : delete _o6_b_c_d["e"];
delete ((_o6_b_c_d1 = (_o6_b1 = o6.b) === null || _o6_b1 === void 0 ? void 0 : _o6_b1["c"].d) === null || _o6_b_c_d1 === void 0 ? void 0 : _o6_b_c_d1["e"]);
4 changes: 2 additions & 2 deletions crates/swc/tests/tsc-references/deleteChain.2.minified.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions crates/swc/tests/tsc-references/elementAccessChain.1.normal.js
@@ -1,16 +1,16 @@
//// [elementAccessChain.ts]
var _o3_b, _o3_b1, _o4_b, _ref, _o4_b1, _ref1, _o5_b, _ref2, _o5_b1, _ref3, _o5_b2, _ref4, _o5_b3, _ref5, _o6;
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"];
(_ref = (_o4_b = o4.b) === null || _o4_b === void 0 ? void 0 : _o4_b["c"].d) === null || _ref === void 0 ? void 0 : _ref.e;
(_ref1 = (_o4_b1 = o4.b) === null || _o4_b1 === void 0 ? void 0 : _o4_b1["c"].d) === null || _ref1 === void 0 ? void 0 : _ref1["e"];
(_ref2 = (_o5_b = o5.b) === null || _o5_b === void 0 ? void 0 : _o5_b.call(o5)["c"].d) === null || _ref2 === void 0 ? void 0 : _ref2.e;
(_ref3 = (_o5_b1 = o5.b) === null || _o5_b1 === void 0 ? void 0 : _o5_b1.call(o5)["c"].d) === null || _ref3 === void 0 ? void 0 : _ref3["e"];
(_ref4 = (_o5_b2 = o5["b"]) === null || _o5_b2 === void 0 ? void 0 : _o5_b2.call(o5)["c"].d) === null || _ref4 === void 0 ? void 0 : _ref4.e;
(_ref5 = (_o5_b3 = o5["b"]) === null || _o5_b3 === void 0 ? void 0 : _o5_b3.call(o5)["c"].d) === null || _ref5 === void 0 ? void 0 : _ref5["e"];
(_o4_b_c_d = (_o4_b = o4.b) === null || _o4_b === void 0 ? void 0 : _o4_b["c"].d) === null || _o4_b_c_d === void 0 ? void 0 : _o4_b_c_d.e;
(_o4_b_c_d1 = (_o4_b1 = o4.b) === null || _o4_b1 === void 0 ? void 0 : _o4_b1["c"].d) === null || _o4_b_c_d1 === void 0 ? void 0 : _o4_b_c_d1["e"];
(_o5_b_c_d = (_o5_b = o5.b) === null || _o5_b === void 0 ? void 0 : _o5_b.call(o5)["c"].d) === null || _o5_b_c_d === void 0 ? void 0 : _o5_b_c_d.e;
(_o5_b_c_d1 = (_o5_b1 = o5.b) === null || _o5_b1 === void 0 ? void 0 : _o5_b1.call(o5)["c"].d) === null || _o5_b_c_d1 === void 0 ? void 0 : _o5_b_c_d1["e"];
(_o5_b_c_d2 = (_o5_b2 = o5["b"]) === null || _o5_b2 === void 0 ? void 0 : _o5_b2.call(o5)["c"].d) === null || _o5_b_c_d2 === void 0 ? void 0 : _o5_b_c_d2.e;
(_o5_b_c_d3 = (_o5_b3 = o5["b"]) === null || _o5_b3 === void 0 ? void 0 : _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"];
// GH#36031
o2 === null || o2 === void 0 ? void 0 : o2["b"].c;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -199,8 +199,8 @@ Animal;
Animal[Animal["CAT"] = 1] = "CAT";
})(Animal || (Animal = {}));
function expression() {
var _ref;
switch((_ref = zoo === null || zoo === void 0 ? void 0 : zoo.animal) !== null && _ref !== void 0 ? _ref : Animal.DOG){
var _zoo_animal;
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:
Expand Down
@@ -1,13 +1,13 @@
//// [logicalAssignment8.ts]
function foo1(results) {
var _ref;
(results || (results = (_ref = bar === null || bar === void 0 ? void 0 : bar.value) !== null && _ref !== void 0 ? _ref : [])).push(100);
var _bar_value;
(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 _ref;
(results !== null && results !== void 0 ? results : results = (_ref = bar === null || bar === void 0 ? void 0 : bar.value) !== null && _ref !== void 0 ? _ref : []).push(100);
var _bar_value;
(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 _ref;
(results && (results = (_ref = bar === null || bar === void 0 ? void 0 : bar.value) !== null && _ref !== void 0 ? _ref : [])).push(100);
var _bar_value;
(results && (results = (_bar_value = bar === null || bar === void 0 ? void 0 : bar.value) !== null && _bar_value !== void 0 ? _bar_value : [])).push(100);
}
Expand Up @@ -2,5 +2,5 @@
const obj = {
arr: []
};
var _ref;
for (const i of (_ref = obj === null || obj === void 0 ? void 0 : obj.arr) !== null && _ref !== void 0 ? _ref : []){}
var _obj_arr;
for (const i of (_obj_arr = obj === null || obj === void 0 ? void 0 : obj.arr) !== null && _obj_arr !== void 0 ? _obj_arr : []){}
@@ -1,6 +1,6 @@
//// [nullishCoalescingOperator12.ts]
var _ref;
var _obj_arr;
const obj = {
arr: []
};
for (const i of null !== (_ref = null == obj ? void 0 : obj.arr) && void 0 !== _ref ? _ref : []);
for (const i of null !== (_obj_arr = null == obj ? void 0 : obj.arr) && void 0 !== _obj_arr ? _obj_arr : []);