mirror of
https://github.com/swc-project/swc.git
synced 2024-12-23 05:32:09 +03:00
feat(es/minifier): Drop pure new
calls (#4478)
This commit is contained in:
parent
588adf0913
commit
918c9c8a21
@ -5,30 +5,7 @@ export var AppType;
|
|||||||
export var AppStyle;
|
export var AppStyle;
|
||||||
!function(AppStyle) {
|
!function(AppStyle) {
|
||||||
AppStyle[AppStyle.Tree = 0] = "Tree", AppStyle[AppStyle.TreeEntity = 1] = "TreeEntity", AppStyle[AppStyle.Standard = 2] = "Standard", AppStyle[AppStyle.MiniApp = 3] = "MiniApp", AppStyle[AppStyle.PivotTable = 4] = "PivotTable";
|
AppStyle[AppStyle.Tree = 0] = "Tree", AppStyle[AppStyle.TreeEntity = 1] = "TreeEntity", AppStyle[AppStyle.Standard = 2] = "Standard", AppStyle[AppStyle.MiniApp = 3] = "MiniApp", AppStyle[AppStyle.PivotTable = 4] = "PivotTable";
|
||||||
}(AppStyle || (AppStyle = {})), new Map([
|
}(AppStyle || (AppStyle = {})), AppType.Standard, AppStyle.Standard, AppStyle.MiniApp, AppType.Relationship, AppStyle.Standard, AppStyle.Tree, AppStyle.TreeEntity, AppType.AdvancedList, AppStyle.Standard, AppStyle.MiniApp, foo({
|
||||||
[
|
|
||||||
AppType.Standard,
|
|
||||||
[
|
|
||||||
AppStyle.Standard,
|
|
||||||
AppStyle.MiniApp
|
|
||||||
]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
AppType.Relationship,
|
|
||||||
[
|
|
||||||
AppStyle.Standard,
|
|
||||||
AppStyle.Tree,
|
|
||||||
AppStyle.TreeEntity
|
|
||||||
]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
AppType.AdvancedList,
|
|
||||||
[
|
|
||||||
AppStyle.Standard,
|
|
||||||
AppStyle.MiniApp
|
|
||||||
]
|
|
||||||
]
|
|
||||||
]), foo({
|
|
||||||
x: !0
|
x: !0
|
||||||
}, {
|
}, {
|
||||||
x: !1
|
x: !1
|
||||||
|
@ -5,30 +5,7 @@ export var AppType;
|
|||||||
export var AppStyle;
|
export var AppStyle;
|
||||||
!function(AppStyle) {
|
!function(AppStyle) {
|
||||||
AppStyle[AppStyle.Tree = 0] = "Tree", AppStyle[AppStyle.TreeEntity = 1] = "TreeEntity", AppStyle[AppStyle.Standard = 2] = "Standard", AppStyle[AppStyle.MiniApp = 3] = "MiniApp", AppStyle[AppStyle.PivotTable = 4] = "PivotTable";
|
AppStyle[AppStyle.Tree = 0] = "Tree", AppStyle[AppStyle.TreeEntity = 1] = "TreeEntity", AppStyle[AppStyle.Standard = 2] = "Standard", AppStyle[AppStyle.MiniApp = 3] = "MiniApp", AppStyle[AppStyle.PivotTable = 4] = "PivotTable";
|
||||||
}(AppStyle || (AppStyle = {})), new Map([
|
}(AppStyle || (AppStyle = {})), AppType.Standard, AppStyle.Standard, AppStyle.MiniApp, AppType.Relationship, AppStyle.Standard, AppStyle.Tree, AppStyle.TreeEntity, AppType.AdvancedList, AppStyle.Standard, AppStyle.MiniApp, foo({
|
||||||
[
|
|
||||||
AppType.Standard,
|
|
||||||
[
|
|
||||||
AppStyle.Standard,
|
|
||||||
AppStyle.MiniApp
|
|
||||||
]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
AppType.Relationship,
|
|
||||||
[
|
|
||||||
AppStyle.Standard,
|
|
||||||
AppStyle.Tree,
|
|
||||||
AppStyle.TreeEntity
|
|
||||||
]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
AppType.AdvancedList,
|
|
||||||
[
|
|
||||||
AppStyle.Standard,
|
|
||||||
AppStyle.MiniApp
|
|
||||||
]
|
|
||||||
]
|
|
||||||
]), foo({
|
|
||||||
x: !0
|
x: !0
|
||||||
}, {
|
}, {
|
||||||
x: !1
|
x: !1
|
||||||
|
@ -1 +0,0 @@
|
|||||||
new Array(1), new Array(), new Array(1), new Array();
|
|
@ -1 +0,0 @@
|
|||||||
new Array(1), new Array(), new Array(1), new Array();
|
|
@ -1,2 +1,2 @@
|
|||||||
var NUMBER;
|
var NUMBER;
|
||||||
NUMBER.toString(), new Object, NUMBER.toString(), new Object;
|
NUMBER.toString(), NUMBER.toString();
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
var NUMBER;
|
var NUMBER;
|
||||||
NUMBER.toString(), new Object, NUMBER.toString(), new Object;
|
NUMBER.toString(), NUMBER.toString();
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
var NUMBER, STRING;
|
var NUMBER, STRING;
|
||||||
++NUMBER, STRING.charAt(0), new Object(), ++NUMBER, STRING.charAt(0), new Object();
|
++NUMBER, STRING.charAt(0), ++NUMBER, STRING.charAt(0);
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
var NUMBER, STRING;
|
var NUMBER, STRING;
|
||||||
++NUMBER, STRING.charAt(0), new Object(), ++NUMBER, STRING.charAt(0), new Object();
|
++NUMBER, STRING.charAt(0), ++NUMBER, STRING.charAt(0);
|
||||||
|
@ -6,5 +6,5 @@ class C {
|
|||||||
}, M1.F2 = function(x) {
|
}, M1.F2 = function(x) {
|
||||||
return x.toString();
|
return x.toString();
|
||||||
};
|
};
|
||||||
}(M || (M = {})), new Object(), new C(), new C(), new class {
|
}(M || (M = {})), new C(), new C(), new class {
|
||||||
}(), new C(), new M.A();
|
}(), new C(), new M.A();
|
||||||
|
@ -14,4 +14,4 @@ var M, C = function() {
|
|||||||
M1.A = A, M1.F2 = function(x) {
|
M1.A = A, M1.F2 = function(x) {
|
||||||
return x.toString();
|
return x.toString();
|
||||||
};
|
};
|
||||||
}(M || (M = {})), new Object(), new C(), new C(), new D(), new C(), new M.A();
|
}(M || (M = {})), new C(), new C(), new D(), new C(), new M.A();
|
||||||
|
@ -6,5 +6,5 @@ class C {
|
|||||||
}, M1.F2 = function(x) {
|
}, M1.F2 = function(x) {
|
||||||
return x.toString();
|
return x.toString();
|
||||||
};
|
};
|
||||||
}(M || (M = {})), new Object(), new C(), new C(), new class {
|
}(M || (M = {})), new C(), new C(), new class {
|
||||||
}(), new M.A(), M.F2;
|
}(), new M.A(), M.F2;
|
||||||
|
@ -14,4 +14,4 @@ var M, C = function() {
|
|||||||
M1.A = A, M1.F2 = function(x) {
|
M1.A = A, M1.F2 = function(x) {
|
||||||
return x.toString();
|
return x.toString();
|
||||||
};
|
};
|
||||||
}(M || (M = {})), new Object(), new C(), new C(), new D(), new M.A(), M.F2;
|
}(M || (M = {})), new C(), new C(), new D(), new M.A(), M.F2;
|
||||||
|
@ -25,6 +25,6 @@ for(;;);
|
|||||||
for(;;);
|
for(;;);
|
||||||
for(new C(), new C2(), new D();;);
|
for(new C(), new C2(), new D();;);
|
||||||
for(new D();;);
|
for(new D();;);
|
||||||
for(new Array();;);
|
for(;;);
|
||||||
for(;;);
|
for(;;);
|
||||||
M.A;
|
M.A;
|
||||||
|
@ -38,6 +38,6 @@ for(;;);
|
|||||||
for(;;);
|
for(;;);
|
||||||
for(new C(), new C2(), new D();;);
|
for(new C(), new C2(), new D();;);
|
||||||
for(new D();;);
|
for(new D();;);
|
||||||
for(new Array();;);
|
for(;;);
|
||||||
for(;;);
|
for(;;);
|
||||||
M.A;
|
M.A;
|
||||||
|
@ -19,4 +19,4 @@ for(;;);
|
|||||||
for(;;);
|
for(;;);
|
||||||
for(;;);
|
for(;;);
|
||||||
for(;;);
|
for(;;);
|
||||||
for(new Array();;);
|
for(;;);
|
||||||
|
@ -19,4 +19,4 @@ for(;;);
|
|||||||
for(;;);
|
for(;;);
|
||||||
for(;;);
|
for(;;);
|
||||||
for(;;);
|
for(;;);
|
||||||
for(new Array();;);
|
for(;;);
|
||||||
|
@ -10,7 +10,7 @@ for(var M;;);
|
|||||||
for(;;);
|
for(;;);
|
||||||
for(;;);
|
for(;;);
|
||||||
for(;;);
|
for(;;);
|
||||||
for(new Object();;);
|
for(;;);
|
||||||
for(;;);
|
for(;;);
|
||||||
for(;;);
|
for(;;);
|
||||||
for(;;);
|
for(;;);
|
||||||
|
@ -18,7 +18,7 @@ for(!function(M1) {
|
|||||||
for(;;);
|
for(;;);
|
||||||
for(;;);
|
for(;;);
|
||||||
for(;;);
|
for(;;);
|
||||||
for(new Object();;);
|
for(;;);
|
||||||
for(;;);
|
for(;;);
|
||||||
for(;;);
|
for(;;);
|
||||||
for(;;);
|
for(;;);
|
||||||
|
@ -10,4 +10,4 @@ class D {
|
|||||||
}, M1.F2 = function(x) {
|
}, M1.F2 = function(x) {
|
||||||
return x.toString();
|
return x.toString();
|
||||||
};
|
};
|
||||||
}(M || (M = {})), new C(), new D(), new C(), new C2(), new C(), new C2(), new D(), new D(), new Array(), M.A;
|
}(M || (M = {})), new C(), new D(), new C(), new C2(), new C(), new C2(), new D(), new D(), M.A;
|
||||||
|
@ -22,4 +22,4 @@ var M, C = function() {
|
|||||||
M1.A = A, M1.F2 = function(x) {
|
M1.A = A, M1.F2 = function(x) {
|
||||||
return x.toString();
|
return x.toString();
|
||||||
};
|
};
|
||||||
}(M || (M = {})), new C(), new D(), new C(), new C2(), new C(), new C2(), new D(), new D(), new Array(), M.A;
|
}(M || (M = {})), new C(), new D(), new C(), new C2(), new C(), new C2(), new D(), new D(), M.A;
|
||||||
|
@ -5,4 +5,4 @@ function f() {}
|
|||||||
}(E || (E = {})), E.A, (f || (f = {})).bar = 1;
|
}(E || (E = {})), E.A, (f || (f = {})).bar = 1;
|
||||||
class c {
|
class c {
|
||||||
}
|
}
|
||||||
(c || (c = {})).bar = 1, new Object();
|
(c || (c = {})).bar = 1;
|
||||||
|
@ -14,4 +14,4 @@ var c = function() {
|
|||||||
"use strict";
|
"use strict";
|
||||||
swcHelpers.classCallCheck(this, c);
|
swcHelpers.classCallCheck(this, c);
|
||||||
};
|
};
|
||||||
(c || (c = {})).bar = 1, new Object();
|
(c || (c = {})).bar = 1;
|
||||||
|
@ -1 +0,0 @@
|
|||||||
new Array(1);
|
|
@ -1 +0,0 @@
|
|||||||
new Array(1);
|
|
@ -5,5 +5,4 @@ var M;
|
|||||||
}
|
}
|
||||||
M1.fn = fn;
|
M1.fn = fn;
|
||||||
}(M || (M = {})), new class {
|
}(M || (M = {})), new class {
|
||||||
}(), new Object(), (x)=>''
|
}();
|
||||||
;
|
|
||||||
|
@ -14,4 +14,4 @@ var M, C = function() {
|
|||||||
}
|
}
|
||||||
return D;
|
return D;
|
||||||
}(C);
|
}(C);
|
||||||
new C(), new Object();
|
new C();
|
||||||
|
@ -1,2 +1 @@
|
|||||||
for(;;);
|
for(;;);
|
||||||
new Array();
|
|
||||||
|
@ -1,2 +1 @@
|
|||||||
for(;;);
|
for(;;);
|
||||||
new Array();
|
|
||||||
|
@ -806,6 +806,29 @@ impl Pure<'_> {
|
|||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if self.options.side_effects {
|
||||||
|
if let Expr::New(NewExpr { callee, args, .. }) = e {
|
||||||
|
if let Expr::Ident(i) = &**callee {
|
||||||
|
match &*i.sym {
|
||||||
|
"Map" | "Set" | "Array" | "Object" | "Boolean" | "Number" => {
|
||||||
|
if i.span.ctxt.outer() == self.marks.unresolved_mark {
|
||||||
|
report_change!("Dropping a pure new expression");
|
||||||
|
|
||||||
|
self.changed = true;
|
||||||
|
*e = self
|
||||||
|
.make_ignored_expr(
|
||||||
|
args.iter_mut().flatten().map(|arg| arg.expr.take()),
|
||||||
|
)
|
||||||
|
.unwrap_or(Expr::Invalid(Invalid { span: DUMMY_SP }));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Remove pure member expressions.
|
// Remove pure member expressions.
|
||||||
if let Expr::Member(MemberExpr { obj, prop, .. }) = e {
|
if let Expr::Member(MemberExpr { obj, prop, .. }) = e {
|
||||||
if let Expr::Ident(obj) = &**obj {
|
if let Expr::Ident(obj) = &**obj {
|
||||||
|
@ -1991,9 +1991,7 @@
|
|||||||
for(i = 0; i < sourceKeys.length; i++)key = sourceKeys[i], excluded.indexOf(key) >= 0 || (target[key] = source[key]);
|
for(i = 0; i < sourceKeys.length; i++)key = sourceKeys[i], excluded.indexOf(key) >= 0 || (target[key] = source[key]);
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
var loadedImageURLs = new Set();
|
var loadedImageURLs = new Set(), emptyDataURL = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7', loaders = new Map([
|
||||||
new Map();
|
|
||||||
var emptyDataURL = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7', loaders = new Map([
|
|
||||||
[
|
[
|
||||||
'default',
|
'default',
|
||||||
function(param) {
|
function(param) {
|
||||||
|
@ -312,9 +312,7 @@
|
|||||||
for(i = 0; i < sourceKeys.length; i++)key = sourceKeys[i], excluded.indexOf(key) >= 0 || (target[key] = source[key]);
|
for(i = 0; i < sourceKeys.length; i++)key = sourceKeys[i], excluded.indexOf(key) >= 0 || (target[key] = source[key]);
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
var loadedImageURLs = new Set();
|
var loadedImageURLs = new Set(), emptyDataURL = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7', loaders = new Map([
|
||||||
new Map();
|
|
||||||
var emptyDataURL = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7', loaders = new Map([
|
|
||||||
[
|
[
|
||||||
'default',
|
'default',
|
||||||
function(param) {
|
function(param) {
|
||||||
|
@ -602,15 +602,7 @@
|
|||||||
}
|
}
|
||||||
var didWarnAboutDeprecatedCreateFactory = !1;
|
var didWarnAboutDeprecatedCreateFactory = !1;
|
||||||
try {
|
try {
|
||||||
var frozenObject = Object.freeze({});
|
Object.freeze({});
|
||||||
new Map([
|
|
||||||
[
|
|
||||||
frozenObject,
|
|
||||||
null
|
|
||||||
]
|
|
||||||
]), new Set([
|
|
||||||
frozenObject
|
|
||||||
]);
|
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
exports.Children = {
|
exports.Children = {
|
||||||
map: mapChildren,
|
map: mapChildren,
|
||||||
|
@ -8932,15 +8932,7 @@
|
|||||||
}
|
}
|
||||||
hasBadMapPolyfill = !1;
|
hasBadMapPolyfill = !1;
|
||||||
try {
|
try {
|
||||||
var nonExtensibleObject = Object.preventExtensions({});
|
Object.preventExtensions({});
|
||||||
new Map([
|
|
||||||
[
|
|
||||||
nonExtensibleObject,
|
|
||||||
null
|
|
||||||
]
|
|
||||||
]), new Set([
|
|
||||||
nonExtensibleObject
|
|
||||||
]);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
hasBadMapPolyfill = !0;
|
hasBadMapPolyfill = !0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user