Skip to content

Commit

Permalink
feat(es/minifier): Inline a lazily initialized var if it's used once (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Austaras committed Oct 26, 2022
1 parent 5e60bf4 commit 1cd7f61
Show file tree
Hide file tree
Showing 150 changed files with 5,719 additions and 6,084 deletions.
@@ -1,8 +1,8 @@
var t, n = function() {};
var t;
module.exports = ((t = function() {
"use strict";
function t() {}
return t.prototype.it = function() {
this.bb = new t.MyA();
}, t;
}()).MyA = n, t);
}()).MyA = function() {}, t);
5 changes: 2 additions & 3 deletions crates/swc/tests/fixture/issues-3xxx/3126/1/output/index.js
@@ -1,10 +1,9 @@
!function() {
var __webpack_modules__ = {
__webpack_require__.m = {
746: function(__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__1) {
Object.prototype.hasOwnProperty;
}
};
__webpack_require__.m = __webpack_modules__, __webpack_require__.O = function(result, chunkIds, fn, priority) {
}, __webpack_require__.O = function(result, chunkIds, fn, priority) {
for(var j = 0; j < chunkIds.length; j++)Object.keys(__webpack_require__.O).every(function(key) {
return __webpack_require__.O[key](chunkIds[j]);
});
Expand Down
Expand Up @@ -2,12 +2,9 @@
//// [classPoint.ts]
var A;
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
!function(A) {
var Point = function Point(x, y) {
"use strict";
_class_call_check(this, Point), this.x = x, this.y = y;
};
A.Point = Point;
}(A || (A = {}));
(A || (A = {})).Point = function Point(x, y) {
"use strict";
_class_call_check(this, Point), this.x = x, this.y = y;
};
//// [test.ts]
A.Point.Origin, new A.Point(0, 0);
Expand Up @@ -7,9 +7,6 @@ var clodule = function() {
}
return clodule.fn = function(id) {}, clodule;
}();
!function(clodule) {
var fn = function(x, y) {
return x;
};
clodule.fn = fn;
}(clodule || (clodule = {}));
(clodule || (clodule = {})).fn = function(x, y) {
return x;
};
Expand Up @@ -7,9 +7,6 @@ var clodule = function() {
}
return clodule.fn = function(id) {}, clodule;
}();
!function(clodule) {
var fn = function(x, y) {
return x;
};
clodule.fn = fn;
}(clodule || (clodule = {}));
(clodule || (clodule = {})).fn = function(x, y) {
return x;
};
Expand Up @@ -9,9 +9,6 @@ var clodule = function() {
return 42;
}, clodule;
}();
!function(clodule1) {
var fn = function(x, y) {
return clodule.sfn("a");
};
clodule1.fn = fn;
}(clodule || (clodule = {}));
(clodule || (clodule = {})).fn = function(x, y) {
return clodule.sfn("a");
};
Expand Up @@ -12,12 +12,9 @@ var A, Point = function() {
};
}, Point;
}();
!function(Point) {
var Origin = function() {
return null;
};
Point.Origin = Origin;
}(Point || (Point = {})), function(A) {
(Point || (Point = {})).Origin = function() {
return null;
}, function(A) {
var Point = function() {
"use strict";
function Point(x, y) {
Expand Down
Expand Up @@ -2,11 +2,10 @@
var X;
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
!function(X) {
var Y, Point;
Y = X.Y || (X.Y = {}), Point = function Point(x, y) {
(X.Y || (X.Y = {})).Point = function Point(x, y) {
"use strict";
_class_call_check(this, Point), this.x = x, this.y = y;
}, Y.Point = Point;
};
}(X || (X = {}));
//// [module.ts]
var X;
Expand Down
Expand Up @@ -3,10 +3,7 @@ var enumdule;
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
!function(enumdule) {
enumdule[enumdule.Red = 0] = "Red", enumdule[enumdule.Blue = 1] = "Blue";
}(enumdule || (enumdule = {})), function(enumdule) {
var Point = function Point(x, y) {
"use strict";
_class_call_check(this, Point), this.x = x, this.y = y;
};
enumdule.Point = Point;
}(enumdule || (enumdule = {})), enumdule.Red, new enumdule.Point(0, 0);
}(enumdule || (enumdule = {})), (enumdule || (enumdule = {})).Point = function Point(x, y) {
"use strict";
_class_call_check(this, Point), this.x = x, this.y = y;
}, enumdule.Red, new enumdule.Point(0, 0);
Expand Up @@ -25,10 +25,8 @@ import _create_super from "@swc/helpers/src/_create_super.mjs";
x: 0,
y: 0,
z: 0
};
var Line = function Line(start, end) {
}, A.Line = function Line(start, end) {
"use strict";
_class_call_check(this, Line), this.start = start, this.end = end;
};
A.Line = Line;
}(A || (A = {}));
@@ -1,10 +1,7 @@
//// [ExportClassWithInaccessibleTypeInIndexerTypeAnnotations.ts]
var A;
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
!function(A) {
var points = function points() {
"use strict";
_class_call_check(this, points);
};
A.points = points;
}(A || (A = {}));
(A || (A = {})).points = function points() {
"use strict";
_class_call_check(this, points);
};
Expand Up @@ -4,10 +4,6 @@ import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
import _inherits from "@swc/helpers/src/_inherits.mjs";
import _create_super from "@swc/helpers/src/_create_super.mjs";
!function(A) {
var Point = function Point() {
"use strict";
_class_call_check(this, Point);
};
A.Origin = {
x: 0,
y: 0
Expand All @@ -20,7 +16,10 @@ import _create_super from "@swc/helpers/src/_create_super.mjs";
return _class_call_check(this, Point3d), _super.apply(this, arguments);
}
return Point3d;
}(Point);
}(function Point() {
"use strict";
_class_call_check(this, Point);
});
A.Point3d = Point3d, A.Origin3d = {
x: 0,
y: 0,
Expand Down
Expand Up @@ -2,19 +2,18 @@
var A;
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
!function(A) {
var fromOrigin = function(p) {
return new Line({
x: 0,
y: 0
}, p);
}, Point = function Point() {
A.Point = function Point() {
"use strict";
_class_call_check(this, Point);
};
A.Point = Point;
var Line = function Line(start, end) {
"use strict";
_class_call_check(this, Line), this.start = start, this.end = end;
};
A.Line = Line, A.fromOrigin = fromOrigin;
A.Line = Line, A.fromOrigin = function(p) {
return new Line({
x: 0,
y: 0
}, p);
};
}(A || (A = {}));
Expand Up @@ -2,14 +2,14 @@
var A;
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
!function(A) {
var fromOrigin = function(p) {
var Line = function Line(start, end) {
"use strict";
_class_call_check(this, Line), this.start = start, this.end = end;
};
A.Line = Line, A.fromOrigin = function(p) {
return new Line({
x: 0,
y: 0
}, p);
}, Line = function Line(start, end) {
"use strict";
_class_call_check(this, Line), this.start = start, this.end = end;
};
A.Line = Line, A.fromOrigin = fromOrigin;
}(A || (A = {}));
Expand Up @@ -2,19 +2,18 @@
var A;
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
!function(A) {
var fromOrigin = function(p) {
return new Line({
x: 0,
y: 0
}, p);
}, Point = function Point() {
A.Point = function Point() {
"use strict";
_class_call_check(this, Point);
};
A.Point = Point;
var Line = function Line(start, end) {
"use strict";
_class_call_check(this, Line), this.start = start, this.end = end;
};
A.fromOrigin = fromOrigin;
A.fromOrigin = function(p) {
return new Line({
x: 0,
y: 0
}, p);
};
}(A || (A = {}));
@@ -1,14 +1,11 @@
//// [function.ts]
var A;
!function(A) {
var Point = function() {
return {
x: 0,
y: 0
};
(A || (A = {})).Point = function() {
return {
x: 0,
y: 0
};
A.Point = Point;
}(A || (A = {}));
};
//// [module.ts]
var A;
!function(A) {
Expand Down
@@ -1,14 +1,11 @@
//// [function.ts]
var A;
!function(A) {
var Point = function() {
return {
x: 0,
y: 0
};
(A || (A = {})).Point = function() {
return {
x: 0,
y: 0
};
A.Point = Point;
}(A || (A = {}));
};
//// [module.ts]
var B;
!function(B) {
Expand Down
Expand Up @@ -8,11 +8,10 @@ var X;
var X;
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
!function(X) {
var Y, Point;
Y = X.Y || (X.Y = {}), Point = function Point(x, y) {
(X.Y || (X.Y = {})).Point = function Point(x, y) {
"use strict";
_class_call_check(this, Point), this.x = x, this.y = y;
}, Y.Point = Point;
};
}(X || (X = {}));
//// [simple.ts]
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
Expand Down
@@ -1,12 +1,9 @@
//// [ModuleAndEnumWithSameNameAndCommonRoot.ts]
var enumdule;
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
!function(enumdule) {
var Point = function Point(x, y) {
"use strict";
_class_call_check(this, Point), this.x = x, this.y = y;
};
enumdule.Point = Point;
}(enumdule || (enumdule = {})), function(enumdule) {
(enumdule || (enumdule = {})).Point = function Point(x, y) {
"use strict";
_class_call_check(this, Point), this.x = x, this.y = y;
}, function(enumdule) {
enumdule[enumdule.Red = 0] = "Red", enumdule[enumdule.Blue = 1] = "Blue";
}(enumdule || (enumdule = {})), enumdule.Red, new enumdule.Point(0, 0);
Expand Up @@ -8,15 +8,12 @@ var A;
}(A || (A = {}));
//// [function.ts]
var A;
!function(A) {
var Point = function() {
return {
x: 0,
y: 0
};
(A || (A = {})).Point = function() {
return {
x: 0,
y: 0
};
A.Point = Point;
}(A || (A = {}));
};
//// [simple.ts]
var B;
!function(B) {
Expand Down
Expand Up @@ -2,14 +2,11 @@
var A;
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
!function(A) {
var _$A = function A() {
A.A = function A() {
"use strict";
_class_call_check(this, A);
};
A.A = _$A;
var AG = function AG() {
}, A.AG = function AG() {
"use strict";
_class_call_check(this, AG);
};
A.AG = AG;
}(A || (A = {})), new A.A(), new A.AG(), new A.A2(), new A.A2();
@@ -1,10 +1,9 @@
//// [ModuleWithExportedAndNonExportedFunctions.ts]
var A;
!function(A) {
var fn = function(s) {
A.fn = function(s) {
return !0;
}, fng = function(s) {
}, A.fng = function(s) {
return null;
};
A.fn = fn, A.fng = fng;
}(A || (A = {})), A.fn, A.fng, A.fn2, A.fng2;
@@ -1,13 +1,10 @@
//// [ModuleWithExportedAndNonExportedImportAlias.ts]
var B, Geometry;
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
!function(B) {
var Line = function Line(start, end) {
"use strict";
_class_call_check(this, Line), this.start = start, this.end = end;
};
B.Line = Line;
}(B || (B = {})), function(Geometry) {
(B || (B = {})).Line = function Line(start, end) {
"use strict";
_class_call_check(this, Line), this.start = start, this.end = end;
}, function(Geometry) {
var Points = A;
Geometry.Points = Points;
var Lines = B, Origin = Geometry.Origin = {
Expand Down

1 comment on commit 1cd7f61

@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: 1cd7f61 Previous: 86e265a Ratio
es/full/bugs-1 353134 ns/iter (± 23624) 387271 ns/iter (± 44005) 0.91
es/full/minify/libraries/antd 2003422775 ns/iter (± 95379472) 1919425798 ns/iter (± 69578682) 1.04
es/full/minify/libraries/d3 393512456 ns/iter (± 26057663) 439895874 ns/iter (± 9446188) 0.89
es/full/minify/libraries/echarts 1595531601 ns/iter (± 49723844) 1623574929 ns/iter (± 86070476) 0.98
es/full/minify/libraries/jquery 107226852 ns/iter (± 3040026) 116698378 ns/iter (± 2073008) 0.92
es/full/minify/libraries/lodash 127385981 ns/iter (± 5666823) 130046915 ns/iter (± 7912521) 0.98
es/full/minify/libraries/moment 65590309 ns/iter (± 5409223) 67110690 ns/iter (± 3357764) 0.98
es/full/minify/libraries/react 20245785 ns/iter (± 589418) 22592359 ns/iter (± 1594457) 0.90
es/full/minify/libraries/terser 301288772 ns/iter (± 7120226) 342963771 ns/iter (± 18168980) 0.88
es/full/minify/libraries/three 556002101 ns/iter (± 11301833) 544570838 ns/iter (± 18009687) 1.02
es/full/minify/libraries/typescript 3498194254 ns/iter (± 24193106) 3392895098 ns/iter (± 61855995) 1.03
es/full/minify/libraries/victory 826508015 ns/iter (± 27791646) 836893368 ns/iter (± 32989528) 0.99
es/full/minify/libraries/vue 152861674 ns/iter (± 8117361) 159378942 ns/iter (± 6815178) 0.96
es/full/codegen/es3 33445 ns/iter (± 2668) 34252 ns/iter (± 1631) 0.98
es/full/codegen/es5 32972 ns/iter (± 1990) 34251 ns/iter (± 2242) 0.96
es/full/codegen/es2015 33018 ns/iter (± 1029) 33984 ns/iter (± 855) 0.97
es/full/codegen/es2016 33419 ns/iter (± 1244) 33691 ns/iter (± 1486) 0.99
es/full/codegen/es2017 33515 ns/iter (± 2177) 33807 ns/iter (± 2128) 0.99
es/full/codegen/es2018 33471 ns/iter (± 1561) 33949 ns/iter (± 1012) 0.99
es/full/codegen/es2019 33261 ns/iter (± 1290) 34066 ns/iter (± 701) 0.98
es/full/codegen/es2020 33341 ns/iter (± 2198) 34042 ns/iter (± 502) 0.98
es/full/all/es3 192213712 ns/iter (± 5798939) 201231846 ns/iter (± 10537410) 0.96
es/full/all/es5 184069799 ns/iter (± 11196660) 181233095 ns/iter (± 19041028) 1.02
es/full/all/es2015 147950504 ns/iter (± 6188334) 146046126 ns/iter (± 5716949) 1.01
es/full/all/es2016 147359785 ns/iter (± 4348433) 154544399 ns/iter (± 15929619) 0.95
es/full/all/es2017 146394924 ns/iter (± 6031887) 153665769 ns/iter (± 12731676) 0.95
es/full/all/es2018 144612224 ns/iter (± 6461588) 146092101 ns/iter (± 10370831) 0.99
es/full/all/es2019 143663662 ns/iter (± 3699310) 138399647 ns/iter (± 5247802) 1.04
es/full/all/es2020 138507480 ns/iter (± 3443548) 134339039 ns/iter (± 5818882) 1.03
es/full/parser 724381 ns/iter (± 27667) 705046 ns/iter (± 30302) 1.03
es/full/base/fixer 26016 ns/iter (± 1276) 25879 ns/iter (± 976) 1.01
es/full/base/resolver_and_hygiene 89616 ns/iter (± 3567) 90517 ns/iter (± 8647) 0.99
serialization of ast node 212 ns/iter (± 11) 212 ns/iter (± 7) 1
serialization of serde 217 ns/iter (± 11) 218 ns/iter (± 3) 1.00

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

Please sign in to comment.