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

refactor(es/minifier): Respect top-level when invoking IIFE #7690

Merged
merged 4 commits into from
Jul 25, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions crates/swc/tests/fixture/issues-2xxx/2679/output/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
!function() {
var a = {};
a.b = 1, a = null, window.test = a;
}();
var a;
Austaras marked this conversation as resolved.
Show resolved Hide resolved
(a = {}).b = 1, a = null, window.test = a;
29 changes: 13 additions & 16 deletions crates/swc/tests/fixture/issues-3xxx/3126/1/output/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
!function() {
__webpack_require__.m = {
746: function(__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__1) {
Object.prototype.hasOwnProperty;
}
}, __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]);
});
};
var __webpack_exports__ = __webpack_require__.O(void 0, [
532
], function() {
return __webpack_require__(746);
var __webpack_exports__;
__webpack_require__.m = {
746: function(__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__1) {
Object.prototype.hasOwnProperty;
}
}, __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]);
});
__webpack_exports__ = __webpack_require__.O(__webpack_exports__);
}();
}, __webpack_exports__ = __webpack_require__.O(void 0, [
532
], function() {
return __webpack_require__(746);
}), __webpack_exports__ = __webpack_require__.O(__webpack_exports__);
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//// [ClassAndModuleThatMergeWithStaticFunctionAndExportedFunctionThatShareAName.ts]
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
var A, Point = function() {
var A, Point, A1, Point1 = function() {
function Point(x, y) {
_class_call_check(this, Point), this.x = x, this.y = y;
}
Expand All @@ -11,21 +11,18 @@ var A, Point = function() {
};
}, Point;
}();
(Point || (Point = {})).Origin = function() {
(Point1 || (Point1 = {})).Origin = function() {
return null;
}, function(A) {
var Point = function() {
function Point(x, y) {
_class_call_check(this, Point), this.x = x, this.y = y;
}
return Point.Origin = function() {
return {
x: 0,
y: 0
};
}, Point;
}();
A.Point = Point, (Point = A.Point || (A.Point = {})).Origin = function() {
return "";
};
}(A || (A = {}));
}, A = A1 || (A1 = {}), Point = function() {
function Point(x, y) {
_class_call_check(this, Point), this.x = x, this.y = y;
}
return Point.Origin = function() {
return {
x: 0,
y: 0
};
}, Point;
}(), A.Point = Point, (Point = A.Point || (A.Point = {})).Origin = function() {
return "";
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//// [ClassAndModuleThatMergeWithStaticFunctionAndNonExportedFunctionThatShareAName.ts]
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
var A, Point = function() {
var A, Point, A1, Point1 = function() {
function Point(x, y) {
_class_call_check(this, Point), this.x = x, this.y = y;
}
Expand All @@ -11,17 +11,14 @@ var A, Point = function() {
};
}, Point;
}();
Point || (Point = {}), function(A) {
var Point = function() {
function Point(x, y) {
_class_call_check(this, Point), this.x = x, this.y = y;
}
return Point.Origin = function() {
return {
x: 0,
y: 0
};
}, Point;
}();
A.Point = Point, A.Point || (A.Point = {});
}(A || (A = {}));
Point1 || (Point1 = {}), A = A1 || (A1 = {}), Point = function() {
function Point(x, y) {
_class_call_check(this, Point), this.x = x, this.y = y;
}
return Point.Origin = function() {
return {
x: 0,
y: 0
};
}, Point;
}(), A.Point = Point, A.Point || (A.Point = {});
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
//// [ClassAndModuleThatMergeWithStaticVariableAndExportedVarThatShareAName.ts]
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
var A, Point = function Point(x, y) {
var A, Point, A1, Point1 = function Point(x, y) {
_class_call_check(this, Point), this.x = x, this.y = y;
};
Point.Origin = {
Point1.Origin = {
x: 0,
y: 0
}, (Point || (Point = {})).Origin = "", function(A) {
var Point = function Point(x, y) {
_class_call_check(this, Point), this.x = x, this.y = y;
};
Point.Origin = {
x: 0,
y: 0
}, A.Point = Point, (Point = A.Point || (A.Point = {})).Origin = "";
}(A || (A = {}));
}, (Point1 || (Point1 = {})).Origin = "", A = A1 || (A1 = {}), (Point = function Point(x, y) {
_class_call_check(this, Point), this.x = x, this.y = y;
}).Origin = {
x: 0,
y: 0
}, A.Point = Point, (Point = A.Point || (A.Point = {})).Origin = "";
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
//// [ClassAndModuleThatMergeWithStaticVariableAndNonExportedVarThatShareAName.ts]
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
var A, Point = function Point(x, y) {
var A, Point, A1, Point1 = function Point(x, y) {
_class_call_check(this, Point), this.x = x, this.y = y;
};
Point.Origin = {
Point1.Origin = {
x: 0,
y: 0
}, Point || (Point = {}), function(A) {
var Point = function Point(x, y) {
_class_call_check(this, Point), this.x = x, this.y = y;
};
Point.Origin = {
x: 0,
y: 0
}, A.Point = Point, Point = A.Point || (A.Point = {});
}(A || (A = {}));
}, Point1 || (Point1 = {}), A = A1 || (A1 = {}), (Point = function Point(x, y) {
_class_call_check(this, Point), this.x = x, this.y = y;
}).Origin = {
x: 0,
y: 0
}, A.Point = Point, Point = A.Point || (A.Point = {});
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
_class_call_check(this, Point), this.x = x, this.y = y;
};
//// [module.ts]
var X;
!function(X) {
var Y, Point;
(Point = (Y = X.Y || (X.Y = {})).Point || (Y.Point = {})).Origin = new Point(0, 0);
}(X || (X = {}));
var X, X1, Y, Point;
(Point = (Y = (X1 = X || (X = {})).Y || (X1.Y = {})).Point || (Y.Point = {})).Origin = new Point(0, 0);
//// [test.ts]
new X.Y.Point(1, 1), X.Y.Point.Origin;
//// [simple.ts]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ var X, X1;
}
};
//// [module.ts]
var X;
!function(X) {
var Y;
let Point;
(Point = (Y = X.Y || (X.Y = {})).Point || (Y.Point = {})).Origin = new Point(0, 0);
}(X || (X = {}));
var X, X1, Y;
let Point;
(Point = (Y = (X1 = X || (X = {})).Y || (X1.Y = {})).Point || (Y.Point = {})).Origin = new Point(0, 0);
//// [test.ts]
new X.Y.Point(1, 1), X.Y.Point.Origin;
//// [simple.ts]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
//// [ES5SymbolProperty2.ts]
var M;
var M, M1, _$Symbol, C;
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
!function(M) {
var _$Symbol, C = function() {
function C() {
_class_call_check(this, C);
}
return C.prototype[_$Symbol.iterator] = function() {}, C;
}();
M.C = C, (new C)[_$Symbol.iterator];
}(M || (M = {})), (new M.C)[Symbol.iterator];
M1 = M || (M = {}), C = function() {
function C() {
_class_call_check(this, C);
}
return C.prototype[_$Symbol.iterator] = function() {}, C;
}(), M1.C = C, (new C)[_$Symbol.iterator], (new M.C)[Symbol.iterator];
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
//// [ExportClassWhichExtendsInterfaceWithInaccessibleType.ts]
var A;
var A, A1, Point2d;
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
!function(A) {
var Point2d = function() {
function Point2d(x, y) {
_class_call_check(this, Point2d), this.x = x, this.y = y;
}
return Point2d.prototype.fromOrigin = function(p) {
return 1;
}, Point2d;
}();
A.Point2d = Point2d;
}(A || (A = {}));
A1 = A || (A = {}), Point2d = function() {
function Point2d(x, y) {
_class_call_check(this, Point2d), this.x = x, this.y = y;
}
return Point2d.prototype.fromOrigin = function(p) {
return 1;
}, Point2d;
}(), A1.Point2d = Point2d;
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
//// [ExportClassWithAccessibleTypesInTypeParameterConstraintsClassHeritageListMemberTypeAnnotations.ts]
var A;
var A, A1, Point, Point3d;
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
import { _ as _inherits } from "@swc/helpers/_/_inherits";
import { _ as _create_super } from "@swc/helpers/_/_create_super";
!function(A) {
var Point = function Point() {
_class_call_check(this, Point);
};
A.Point = Point, A.Origin = {
x: 0,
y: 0
};
var Point3d = function(Point) {
_inherits(Point3d, Point);
var _super = _create_super(Point3d);
function Point3d() {
return _class_call_check(this, Point3d), _super.apply(this, arguments);
}
return Point3d;
}(Point);
A.Point3d = Point3d, A.Origin3d = {
x: 0,
y: 0,
z: 0
}, A.Line = function Line(start, end) {
_class_call_check(this, Line), this.start = start, this.end = end;
};
}(A || (A = {}));
A1 = A || (A = {}), Point = function Point() {
_class_call_check(this, Point);
}, A1.Point = Point, A1.Origin = {
x: 0,
y: 0
}, Point3d = function(Point) {
_inherits(Point3d, Point);
var _super = _create_super(Point3d);
function Point3d() {
return _class_call_check(this, Point3d), _super.apply(this, arguments);
}
return Point3d;
}(Point), A1.Point3d = Point3d, A1.Origin3d = {
x: 0,
y: 0,
z: 0
}, A1.Line = function Line(start, end) {
_class_call_check(this, Line), this.start = start, this.end = end;
};
Original file line number Diff line number Diff line change
@@ -1,35 +1,29 @@
//// [ExportClassWithInaccessibleTypeInTypeParameterConstraint.ts]
var A;
var A, A1, Point3d, Line;
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
import { _ as _inherits } from "@swc/helpers/_/_inherits";
import { _ as _create_super } from "@swc/helpers/_/_create_super";
!function(A) {
A.Origin = {
x: 0,
y: 0
};
var Point3d = function(Point) {
_inherits(Point3d, Point);
var _super = _create_super(Point3d);
function Point3d() {
return _class_call_check(this, Point3d), _super.apply(this, arguments);
}
return Point3d;
}(function Point() {
_class_call_check(this, Point);
});
A.Point3d = Point3d, A.Origin3d = {
x: 0,
y: 0,
z: 0
};
var Line = function() {
function Line(start, end) {
_class_call_check(this, Line), this.start = start, this.end = end;
}
return Line.fromorigin2d = function(p) {
return null;
}, Line;
}();
A.Line = Line;
}(A || (A = {}));
(A1 = A || (A = {})).Origin = {
x: 0,
y: 0
}, Point3d = function(Point) {
_inherits(Point3d, Point);
var _super = _create_super(Point3d);
function Point3d() {
return _class_call_check(this, Point3d), _super.apply(this, arguments);
}
return Point3d;
}(function Point() {
_class_call_check(this, Point);
}), A1.Point3d = Point3d, A1.Origin3d = {
x: 0,
y: 0,
z: 0
}, Line = function() {
function Line(start, end) {
_class_call_check(this, Line), this.start = start, this.end = end;
}
return Line.fromorigin2d = function(p) {
return null;
}, Line;
}(), A1.Line = Line;
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
//// [ExportFunctionWithAccessibleTypesInParameterAndReturnTypeAnnotation.ts]
var A;
var A, A1, Line;
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
!function(A) {
A.Point = function Point() {
_class_call_check(this, Point);
};
var Line = function Line(start, end) {
_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);
};
}(A || (A = {}));
(A1 = A || (A = {})).Point = function Point() {
_class_call_check(this, Point);
}, Line = function Line(start, end) {
_class_call_check(this, Line), this.start = start, this.end = end;
}, A1.Line = Line, A1.fromOrigin = function(p) {
return new Line({
x: 0,
y: 0
}, p);
};
Loading