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

feat(es/minifier): Inline lazy inited vars used once #6237

Merged
merged 3 commits into from Oct 26, 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
@@ -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() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if we want to maintain the function's name

Copy link
Member

Choose a reason for hiding this comment

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

It depends on the configuration

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