Skip to content

Commit 94946fa

Browse files
kdy1claude
andauthored
feat(es/transformer): Merge logical_assignment_operators (#11369)
Co-authored-by: Claude <noreply@anthropic.com>
1 parent 373048a commit 94946fa

File tree

16 files changed

+361
-31
lines changed

16 files changed

+361
-31
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use strict";
22
function method() {
3-
var _obj;
43
const obj = {};
4+
var _obj;
55
(_obj = obj).prop ?? (_obj.prop = "x".repeat(10000000));
66
}
77
method(); // the large string should be eventually GCed along with the large string, but it will never happen in SWC+es2020
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//// [logicalAssignment10.ts]
2-
var _obj, _incr, _oobj_obj, _incr1;
32
var count = 0;
43
var obj = {};
54
function incr() {
@@ -8,7 +7,11 @@ function incr() {
87
const oobj = {
98
obj
109
};
10+
var _obj;
11+
var _incr;
1112
var _;
1213
(_ = (_obj = obj)[_incr = incr()]) !== null && _ !== void 0 ? _ : _obj[_incr] = incr();
14+
var _oobj_obj;
15+
var _incr1;
1316
var _1;
1417
(_1 = (_oobj_obj = oobj["obj"])[_incr1 = incr()]) !== null && _1 !== void 0 ? _1 : _oobj_obj[_incr1] = incr();
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//// [logicalAssignment10.ts]
2-
var _obj, _incr, _oobj_obj, _incr1;
32
var count = 0;
43
var obj = {};
54
function incr() {
@@ -8,5 +7,9 @@ function incr() {
87
const oobj = {
98
obj
109
};
10+
var _obj;
11+
var _incr;
1112
(_obj = obj)[_incr = incr()] ?? (_obj[_incr] = incr());
13+
var _oobj_obj;
14+
var _incr1;
1215
(_oobj_obj = oobj["obj"])[_incr1 = incr()] ?? (_oobj_obj[_incr1] = incr());
Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
//// [logicalAssignment2.ts]
2-
var _a, _b, _c, _a_foo, _baz, _b_foo, _baz1, _c_foo, _baz2, _a_foo_bar, _b_foo_bar, _c_foo_bar;
2+
var _a;
33
(_a = a).baz && (_a.baz = result.baz);
4+
var _b;
45
(_b = b).baz || (_b.baz = result.baz);
6+
var _c;
7+
var _baz;
8+
(_baz = (_c = c).baz) !== null && _baz !== void 0 ? _baz : _c.baz = result.baz;
9+
var _a_foo;
10+
var _baz1;
11+
(_a_foo = a.foo)[_baz1 = "baz"] && (_a_foo[_baz1] = result.foo.baz);
12+
var _b_foo;
13+
var _baz2;
14+
(_b_foo = b.foo)[_baz2 = "baz"] || (_b_foo[_baz2] = result.foo.baz);
15+
var _c_foo;
516
var _baz3;
6-
(_baz3 = (_c = c).baz) !== null && _baz3 !== void 0 ? _baz3 : _c.baz = result.baz;
7-
(_a_foo = a.foo)[_baz = "baz"] && (_a_foo[_baz] = result.foo.baz);
8-
(_b_foo = b.foo)[_baz1 = "baz"] || (_b_foo[_baz1] = result.foo.baz);
917
var _;
10-
(_ = (_c_foo = c.foo)[_baz2 = "baz"]) !== null && _ !== void 0 ? _ : _c_foo[_baz2] = result.foo.baz;
18+
(_ = (_c_foo = c.foo)[_baz3 = "baz"]) !== null && _ !== void 0 ? _ : _c_foo[_baz3] = result.foo.baz;
19+
var _a_foo_bar;
1120
(_a_foo_bar = a.foo.bar()).baz && (_a_foo_bar.baz = result.foo.bar().baz);
21+
var _b_foo_bar;
1222
(_b_foo_bar = b.foo.bar()).baz || (_b_foo_bar.baz = result.foo.bar().baz);
23+
var _c_foo_bar;
1324
var _baz4;
1425
(_baz4 = (_c_foo_bar = c.foo.bar()).baz) !== null && _baz4 !== void 0 ? _baz4 : _c_foo_bar.baz = result.foo.bar().baz;
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
//// [logicalAssignment2.ts]
2-
var _a, _b, _c, _a_foo, _baz, _b_foo, _baz1, _c_foo, _baz2, _a_foo_bar, _b_foo_bar, _c_foo_bar;
2+
var _a;
33
(_a = a).baz && (_a.baz = result.baz);
4+
var _b;
45
(_b = b).baz || (_b.baz = result.baz);
6+
var _c;
57
(_c = c).baz ?? (_c.baz = result.baz);
8+
var _a_foo;
9+
var _baz;
610
(_a_foo = a.foo)[_baz = "baz"] && (_a_foo[_baz] = result.foo.baz);
11+
var _b_foo;
12+
var _baz1;
713
(_b_foo = b.foo)[_baz1 = "baz"] || (_b_foo[_baz1] = result.foo.baz);
14+
var _c_foo;
15+
var _baz2;
816
(_c_foo = c.foo)[_baz2 = "baz"] ?? (_c_foo[_baz2] = result.foo.baz);
17+
var _a_foo_bar;
918
(_a_foo_bar = a.foo.bar()).baz && (_a_foo_bar.baz = result.foo.bar().baz);
19+
var _b_foo_bar;
1020
(_b_foo_bar = b.foo.bar()).baz || (_b_foo_bar.baz = result.foo.bar().baz);
21+
var _c_foo_bar;
1122
(_c_foo_bar = c.foo.bar()).baz ?? (_c_foo_bar.baz = result.foo.bar().baz);
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//// [logicalAssignment3.ts]
2-
var _a, _b, _c;
2+
var _a;
33
(_a = a).baz && (_a.baz = result.baz);
4+
var _b;
45
(_b = b).baz || (_b.baz = result.baz);
6+
var _c;
57
var _baz;
68
(_baz = (_c = c).baz) !== null && _baz !== void 0 ? _baz : _c.baz = result.baz;
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//// [logicalAssignment3.ts]
2-
var _a, _b, _c;
2+
var _a;
33
(_a = a).baz && (_a.baz = result.baz);
4+
var _b;
45
(_b = b).baz || (_b.baz = result.baz);
6+
var _c;
57
(_c = c).baz ?? (_c.baz = result.baz);
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//// [logicalAssignment9.ts]
2-
var _x, _x1;
2+
var _x;
33
var _a;
44
(_a = (_x = x).a) !== null && _a !== void 0 ? _a : _x.a = true;
5+
var _x1;
56
(_x1 = x).a && (_x1.a = false);

crates/swc/tests/tsc-references/thisPrototypeMethodCompoundAssignmentJs.1.normal.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
//// [thisPrototypeMethodCompoundAssignmentJs.ts]
22
//// [index.js]
3-
var _Element_prototype, /**
4-
* @this Node
5-
*/ _Element_prototype1;
3+
var _Element_prototype;
64
var _remove;
75
(_remove = (_Element_prototype = Element.prototype).remove) !== null && _remove !== void 0 ? _remove : _Element_prototype.remove = function() {
86
var _this_parentNode;
97
(_this_parentNode = this.parentNode) === null || _this_parentNode === void 0 ? void 0 : _this_parentNode.removeChild(this);
108
};
9+
var /**
10+
* @this Node
11+
*/ _Element_prototype1;
1112
var _remove1;
1213
(_remove1 = (_Element_prototype1 = Element.prototype).remove) !== null && _remove1 !== void 0 ? _remove1 : _Element_prototype1.remove = function() {
1314
var _this_parentNode;

0 commit comments

Comments
 (0)