Skip to content

Commit

Permalink
fix(es/compat): Fix consecutive optional call (#6461)
Browse files Browse the repository at this point in the history
  • Loading branch information
Austaras authored Nov 17, 2022
1 parent c333b0d commit f7072db
Show file tree
Hide file tree
Showing 15 changed files with 90 additions and 59 deletions.
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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.

Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
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 : []){}
Original file line number Diff line number Diff line change
@@ -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 : []);
Loading

1 comment on commit f7072db

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: f7072db Previous: 7441721 Ratio
es/full/bugs-1 334805 ns/iter (± 18127) 336386 ns/iter (± 16008) 1.00
es/full/minify/libraries/antd 1780667832 ns/iter (± 17173485) 1829925137 ns/iter (± 19703431) 0.97
es/full/minify/libraries/d3 381082585 ns/iter (± 7200345) 394936502 ns/iter (± 14038189) 0.96
es/full/minify/libraries/echarts 1547630428 ns/iter (± 22586360) 1597043020 ns/iter (± 32949043) 0.97
es/full/minify/libraries/jquery 98626124 ns/iter (± 2971453) 112455796 ns/iter (± 3168567) 0.88
es/full/minify/libraries/lodash 116907486 ns/iter (± 3089676) 132469716 ns/iter (± 4546946) 0.88
es/full/minify/libraries/moment 58622385 ns/iter (± 2255961) 62608562 ns/iter (± 3260619) 0.94
es/full/minify/libraries/react 19450406 ns/iter (± 510833) 22530641 ns/iter (± 1009319) 0.86
es/full/minify/libraries/terser 289477464 ns/iter (± 7208734) 313290319 ns/iter (± 4965725) 0.92
es/full/minify/libraries/three 542243840 ns/iter (± 7665782) 565116172 ns/iter (± 15612929) 0.96
es/full/minify/libraries/typescript 3245973174 ns/iter (± 22954304) 3353129683 ns/iter (± 25602673) 0.97
es/full/minify/libraries/victory 789988605 ns/iter (± 10590936) 820400434 ns/iter (± 11924354) 0.96
es/full/minify/libraries/vue 148323945 ns/iter (± 3007185) 151618721 ns/iter (± 6198946) 0.98
es/full/codegen/es3 33414 ns/iter (± 1301) 33564 ns/iter (± 533) 1.00
es/full/codegen/es5 33367 ns/iter (± 804) 33552 ns/iter (± 322) 0.99
es/full/codegen/es2015 33589 ns/iter (± 1278) 33492 ns/iter (± 591) 1.00
es/full/codegen/es2016 33485 ns/iter (± 874) 33532 ns/iter (± 765) 1.00
es/full/codegen/es2017 33443 ns/iter (± 926) 33529 ns/iter (± 1367) 1.00
es/full/codegen/es2018 33490 ns/iter (± 1231) 33053 ns/iter (± 979) 1.01
es/full/codegen/es2019 33659 ns/iter (± 996) 33213 ns/iter (± 577) 1.01
es/full/codegen/es2020 33404 ns/iter (± 1846) 32598 ns/iter (± 1170) 1.02
es/full/all/es3 184563807 ns/iter (± 5806100) 189891800 ns/iter (± 5512388) 0.97
es/full/all/es5 174353068 ns/iter (± 5635998) 179208144 ns/iter (± 5100538) 0.97
es/full/all/es2015 139550268 ns/iter (± 2434944) 143821154 ns/iter (± 4045032) 0.97
es/full/all/es2016 138933989 ns/iter (± 3265699) 142141554 ns/iter (± 4979353) 0.98
es/full/all/es2017 137643683 ns/iter (± 2704993) 142283418 ns/iter (± 5250951) 0.97
es/full/all/es2018 136547949 ns/iter (± 3141469) 140380853 ns/iter (± 4125286) 0.97
es/full/all/es2019 136033205 ns/iter (± 2568960) 139195315 ns/iter (± 3421829) 0.98
es/full/all/es2020 130946022 ns/iter (± 2042192) 133959142 ns/iter (± 3532239) 0.98
es/full/parser 687876 ns/iter (± 29004) 721884 ns/iter (± 49747) 0.95
es/full/base/fixer 25829 ns/iter (± 857) 26238 ns/iter (± 1030) 0.98
es/full/base/resolver_and_hygiene 88804 ns/iter (± 3811) 91058 ns/iter (± 4382) 0.98
serialization of ast node 211 ns/iter (± 3) 217 ns/iter (± 2) 0.97
serialization of serde 218 ns/iter (± 5) 221 ns/iter (± 3) 0.99

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.