fix(es/minifier): Preserve classes with side effects in static fields (#6480)

This commit is contained in:
HeYunfei 2022-11-24 17:43:00 +08:00 committed by GitHub
parent 6fd97971c9
commit 8d906b45e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 612 additions and 78 deletions

View File

@ -1,2 +1,14 @@
//// [classStaticBlock15.ts] //// [classStaticBlock15.ts]
console.log(void 0); var _C__1;
class C {
static #_1 = 1;
static #_3 = 3;
static #_5 = 5;
static{}
static{}
static{}
static{}
static{}
static{}
}
console.log(_C__1);

View File

@ -1,6 +1,11 @@
//// [classStaticBlock23.ts] //// [classStaticBlock23.ts]
[ const nums = [
1, 1,
2, 2,
3 3
].map((n)=>Promise.resolve(n)); ].map((n)=>Promise.resolve(n));
class C {
static{
for await (let nn of nums)console.log(nn);
}
}

View File

@ -1,2 +1,12 @@
//// [classStaticBlock5.ts] //// [classStaticBlock5.ts]
super.a; class B {
static a = 1;
static b = 2;
}
class C extends B {
static b = 3;
static c = super.a;
static{
this.b, super.b, super.a;
}
}

View File

@ -1,2 +1,10 @@
//// [classStaticBlockUseBeforeDef1.ts] //// [classStaticBlockUseBeforeDef1.ts]
this.x; class C {
static{
this.x = 1;
}
static y = this.x;
static{
this.z = this.y;
}
}

View File

@ -1 +1,6 @@
//// [classStaticBlockUseBeforeDef2.ts] //// [classStaticBlockUseBeforeDef2.ts]
class C {
static{
this.x = 1;
}
}

View File

@ -1 +1,13 @@
//// [privateNameComputedPropertyName4.ts] //// [privateNameComputedPropertyName4.ts]
class C1 {
static #qux = 42;
bar() {}
}
class C2 {
static #qux = 42;
static bar() {}
}
class C3 {
static #qux = 42;
static bar = "test";
}

View File

@ -7,150 +7,354 @@ Baz || (Baz = {});
export default class { export default class {
} }
//// [locals.ts] //// [locals.ts]
super.w(), (()=>{ class C extends B {
var { Reflect } = { static _ = [
Reflect: null void super.w(),
}; (()=>{
super.w(); var { Reflect } = {
})(), (()=>{ Reflect: null
var [Reflect] = [ };
null super.w();
})(),
(()=>{
var [Reflect] = [
null
];
super.w();
})(),
void super.w(),
void super.w(),
(()=>{
let Reflect;
Reflect || (Reflect = {}), super.w();
})(),
(()=>{
let Reflect;
Reflect || (Reflect = {}), super.w();
})(),
void super.w(),
void super.w(),
void super.w(),
void super.w()
]; ];
super.w(); static{
})(), super.w(), super.w(), (()=>{ var { Reflect } = {
let Reflect; Reflect: null
Reflect || (Reflect = {}), super.w(); };
})(), (()=>{ super.w();
let Reflect; }
Reflect || (Reflect = {}), super.w(); static{
})(), super.w(), super.w(), super.w(), super.w(); var [Reflect1] = [
null
];
super.w();
}
static{
super.w();
}
static{
super.w();
}
static{
super.w();
}
static{
let Reflect2;
Reflect2 || (Reflect2 = {}), super.w();
}
static{
let Reflect3;
Reflect3 || (Reflect3 = {}), super.w();
}
static{
super.w();
}
static{
super.w();
}
static{
super.w();
}
static{
super.w();
}
}
export { }; export { };
//// [varInContainingScopeStaticField1.ts] //// [varInContainingScopeStaticField1.ts]
super.w(); class C extends B {
static _ = super.w();
}
export { }; export { };
//// [varInContainingScopeStaticField2.ts] //// [varInContainingScopeStaticField2.ts]
var { Reflect } = { var { Reflect } = {
Reflect: null Reflect: null
}; };
super.w(); class C extends B {
static _ = super.w();
}
export { }; export { };
//// [varInContainingScopeStaticField3.ts] //// [varInContainingScopeStaticField3.ts]
var [Reflect] = [ var [Reflect] = [
null null
]; ];
super.w(); class C extends B {
static _ = super.w();
}
export { }; export { };
//// [varInContainingScopeStaticBlock1.ts] //// [varInContainingScopeStaticBlock1.ts]
class C extends B {
static{
super.w();
}
}
export { }; export { };
//// [varInContainingScopeStaticBlock2.ts] //// [varInContainingScopeStaticBlock2.ts]
var { Reflect } = { var { Reflect } = {
Reflect: null Reflect: null
}; };
class C extends B {
static{
super.w();
}
}
export { }; export { };
//// [varInContainingScopeStaticBlock3.ts] //// [varInContainingScopeStaticBlock3.ts]
var [Reflect] = [ var [Reflect] = [
null null
]; ];
class C extends B {
static{
super.w();
}
}
export { }; export { };
//// [classDeclInContainingScopeStaticField.ts] //// [classDeclInContainingScopeStaticField.ts]
super.w(); class C extends B {
static _ = super.w();
}
export { }; export { };
//// [classDeclInContainingScopeStaticBlock.ts] //// [classDeclInContainingScopeStaticBlock.ts]
class C extends B {
static{
super.w();
}
}
export { }; export { };
//// [funcDeclInContainingScopeStaticField.ts] //// [funcDeclInContainingScopeStaticField.ts]
super.w(); class C extends B {
static _ = super.w();
}
export { }; export { };
//// [funcDeclInContainingScopeStaticBlock.ts] //// [funcDeclInContainingScopeStaticBlock.ts]
class C extends B {
static{
super.w();
}
}
export { }; export { };
//// [valueNamespaceInContainingScopeStaticField.ts] //// [valueNamespaceInContainingScopeStaticField.ts]
super.w(); class C extends B {
static _ = super.w();
}
export { }; export { };
//// [valueNamespaceInContainingScopeStaticBlock.ts] //// [valueNamespaceInContainingScopeStaticBlock.ts]
class C extends B {
static{
super.w();
}
}
export { }; export { };
//// [enumInContainingScopeStaticField.ts] //// [enumInContainingScopeStaticField.ts]
var Reflect; var Reflect;
Reflect || (Reflect = {}), super.w(); Reflect || (Reflect = {});
class C extends B {
static _ = super.w();
}
export { }; export { };
//// [enumInContainingScopeStaticBlock.ts] //// [enumInContainingScopeStaticBlock.ts]
var Reflect; var Reflect;
Reflect || (Reflect = {}); Reflect || (Reflect = {});
class C extends B {
static{
super.w();
}
}
export { }; export { };
//// [constEnumInContainingScopeStaticField.ts] //// [constEnumInContainingScopeStaticField.ts]
var Reflect; var Reflect;
Reflect || (Reflect = {}), super.w(); Reflect || (Reflect = {});
class C extends B {
static _ = super.w();
}
export { }; export { };
//// [constEnumInContainingScopeStaticBlock.ts] //// [constEnumInContainingScopeStaticBlock.ts]
var Reflect; var Reflect;
Reflect || (Reflect = {}); Reflect || (Reflect = {});
class C extends B {
static{
super.w();
}
}
export { }; export { };
//// [namespaceImportInContainingScopeStaticField.ts] //// [namespaceImportInContainingScopeStaticField.ts]
super.w(); class C extends B {
static _ = super.w();
}
export { }; export { };
//// [namespaceImportInContainingScopeStaticBlock.ts] //// [namespaceImportInContainingScopeStaticBlock.ts]
class C extends B {
static{
super.w();
}
}
export { }; export { };
//// [namedImportInContainingScopeStaticField.ts] //// [namedImportInContainingScopeStaticField.ts]
super.w(); class C extends B {
static _ = super.w();
}
export { }; export { };
//// [namedImportInContainingScopeStaticBlock.ts] //// [namedImportInContainingScopeStaticBlock.ts]
class C extends B {
static{
super.w();
}
}
export { }; export { };
//// [namedImportOfInterfaceInContainingScopeStaticField.ts] //// [namedImportOfInterfaceInContainingScopeStaticField.ts]
super.w(); class C extends B {
static _ = super.w();
}
export { }; export { };
//// [namedImportOfInterfaceInContainingScopeStaticBlock.ts] //// [namedImportOfInterfaceInContainingScopeStaticBlock.ts]
class C extends B {
static{
super.w();
}
}
export { }; export { };
//// [namedImportOfUninstantiatedNamespaceInContainingScopeStaticField.ts] //// [namedImportOfUninstantiatedNamespaceInContainingScopeStaticField.ts]
super.w(); class C extends B {
static _ = super.w();
}
export { }; export { };
//// [namedImportOfUninstantiatedNamespaceInContainingScopeStaticBlock.ts] //// [namedImportOfUninstantiatedNamespaceInContainingScopeStaticBlock.ts]
class C extends B {
static{
super.w();
}
}
export { }; export { };
//// [namedImportOfConstEnumInContainingScopeStaticField.ts] //// [namedImportOfConstEnumInContainingScopeStaticField.ts]
super.w(); class C extends B {
static _ = super.w();
}
export { }; export { };
//// [namedImportOfConstEnumInContainingScopeStaticBlock.ts] //// [namedImportOfConstEnumInContainingScopeStaticBlock.ts]
class C extends B {
static{
super.w();
}
}
export { }; export { };
//// [typeOnlyNamedImportInContainingScopeStaticField.ts] //// [typeOnlyNamedImportInContainingScopeStaticField.ts]
super.w(); class C extends B {
static _ = super.w();
}
export { }; export { };
//// [typeOnlyNamedImportInContainingScopeStaticBlock.ts] //// [typeOnlyNamedImportInContainingScopeStaticBlock.ts]
class C extends B {
static{
super.w();
}
}
export { }; export { };
//// [defaultImportInContainingScopeStaticField.ts] //// [defaultImportInContainingScopeStaticField.ts]
super.w(); class C extends B {
static _ = super.w();
}
export { }; export { };
//// [defaultImportInContainingScopeStaticBlock.ts] //// [defaultImportInContainingScopeStaticBlock.ts]
class C extends B {
static{
super.w();
}
}
export { }; export { };
//// [typeOnlyDefaultImportInContainingScopeStaticField.ts] //// [typeOnlyDefaultImportInContainingScopeStaticField.ts]
super.w(); class C extends B {
static _ = super.w();
}
export { }; export { };
//// [typeOnlyDefaultImportInContainingScopeStaticBlock.ts] //// [typeOnlyDefaultImportInContainingScopeStaticBlock.ts]
class C extends B {
static{
super.w();
}
}
export { }; export { };
//// [typeInContainingScopeStaticField.ts] //// [typeInContainingScopeStaticField.ts]
super.w(); class C extends B {
static _ = super.w();
}
export { }; export { };
//// [typeInContainingScopeStaticBlock.ts] //// [typeInContainingScopeStaticBlock.ts]
class C extends B {
static{
super.w();
}
}
export { }; export { };
//// [interfaceInContainingScopeStaticField.ts] //// [interfaceInContainingScopeStaticField.ts]
super.w(); class C extends B {
static _ = super.w();
}
export { }; export { };
//// [interfaceInContainingScopeStaticBlock.ts] //// [interfaceInContainingScopeStaticBlock.ts]
class C extends B {
static{
super.w();
}
}
export { }; export { };
//// [uninstantiatedNamespaceInContainingScopeStaticField.ts] //// [uninstantiatedNamespaceInContainingScopeStaticField.ts]
super.w(); class C extends B {
static _ = super.w();
}
export { }; export { };
//// [uninstantiatedNamespaceInContainingScopeStaticBlock.ts] //// [uninstantiatedNamespaceInContainingScopeStaticBlock.ts]
class C extends B {
static{
super.w();
}
}
export { }; export { };
//// [classExprInContainingScopeStaticField.ts] //// [classExprInContainingScopeStaticField.ts]
super.w(); class C extends B {
static _ = super.w();
}
export { }; export { };
//// [classExprInContainingScopeStaticBlock.ts] //// [classExprInContainingScopeStaticBlock.ts]
class C extends B {
static{
super.w();
}
}
export { }; export { };
//// [inContainingClassExprStaticField.ts] //// [inContainingClassExprStaticField.ts]
export { }; export { };
//// [inContainingClassExprStaticBlock.ts] //// [inContainingClassExprStaticBlock.ts]
export { }; export { };
//// [funcExprInContainingScopeStaticField.ts] //// [funcExprInContainingScopeStaticField.ts]
super.w(); class C extends B {
static _ = super.w();
}
export { }; export { };
//// [funcExprInContainingScopeStaticBlock.ts] //// [funcExprInContainingScopeStaticBlock.ts]
class C extends B {
static{
super.w();
}
}
export { }; export { };
//// [inContainingFuncExprStaticField.ts] //// [inContainingFuncExprStaticField.ts]
export { }; export { };

View File

@ -1,14 +1,42 @@
//// [thisAndSuperInStaticMembers1.ts] //// [thisAndSuperInStaticMembers1.ts]
this.x, this.x(), this?.x(), this.x(), this?.x(), super.a, super.a, super.f(), super.f(), super.a = 0, super.a += 1, super.a = 0, [super.a] = [ class C extends B {
0 static x = void 0;
], [super.a = 0] = [ static y1 = this.x;
0 static y2 = this.x();
], [...super.a] = [ static y3 = this?.x();
0 static y4 = this.x();
], ({ x: super.a } = { static y5 = this?.x();
x: 0 static z1 = super.a;
}), ({ x: super.a = 0 } = { static z2 = super.a;
x: 0 static z3 = super.f();
}), ({ ...super.a } = { static z4 = super.f();
x: 0 static z5 = super.a = 0;
}), ++super.a, --super.a, ++super.a, super.a++, super.a``; static z6 = super.a += 1;
static z7 = void (super.a = 0);
static z8 = [super.a] = [
0
];
static z9 = [super.a = 0] = [
0
];
static z10 = [...super.a] = [
0
];
static z11 = { x: super.a } = {
x: 0
};
static z12 = { x: super.a = 0 } = {
x: 0
};
static z13 = { ...super.a } = {
x: 0
};
static z14 = ++super.a;
static z15 = --super.a;
static z16 = ++super.a;
static z17 = super.a++;
static z18 = super.a``;
x = 1;
y = this.x;
z = super.f();
}

View File

@ -1,14 +1,42 @@
//// [thisAndSuperInStaticMembers2.ts] //// [thisAndSuperInStaticMembers2.ts]
this.x, this.x(), this?.x(), this.x(), this?.x(), super.a, super.a, super.f(), super.f(), super.a = 0, super.a += 1, super.a = 0, [super.a] = [ class C extends B {
0 static x = void 0;
], [super.a = 0] = [ static y1 = this.x;
0 static y2 = this.x();
], [...super.a] = [ static y3 = this?.x();
0 static y4 = this.x();
], ({ x: super.a } = { static y5 = this?.x();
x: 0 static z1 = super.a;
}), ({ x: super.a = 0 } = { static z2 = super.a;
x: 0 static z3 = super.f();
}), ({ ...super.a } = { static z4 = super.f();
x: 0 static z5 = super.a = 0;
}), ++super.a, --super.a, ++super.a, super.a++, super.a``; static z6 = super.a += 1;
static z7 = void (super.a = 0);
static z8 = [super.a] = [
0
];
static z9 = [super.a = 0] = [
0
];
static z10 = [...super.a] = [
0
];
static z11 = { x: super.a } = {
x: 0
};
static z12 = { x: super.a = 0 } = {
x: 0
};
static z13 = { ...super.a } = {
x: 0
};
static z14 = ++super.a;
static z15 = --super.a;
static z16 = ++super.a;
static z17 = super.a++;
static z18 = super.a``;
x = 1;
y = this.x;
z = super.f();
}

View File

@ -27,4 +27,26 @@ let D = class extends C {
}; };
D = _ts_decorate([ D = _ts_decorate([
foo foo
], D), this.a, this.c, super.a, this.c; ], D);
class CC {
static a = 1;
static b = this.a + 1;
}
class DD extends CC {
static c = 2;
static d = this.c + 1;
static e = super.a + this.c + 1;
static f = ()=>this.c + 1;
static ff = function() {
this.c;
};
static foo() {
return this.c + 1;
}
static get fa() {
return this.c + 1;
}
static set fa(v) {
this.c = v + 1;
}
}

View File

@ -27,4 +27,26 @@ let D = class extends C {
}; };
D = _ts_decorate([ D = _ts_decorate([
foo foo
], D), this.a, this.c, super.a, this.c; ], D);
class CC {
static a = 1;
static b = this.a + 1;
}
class DD extends CC {
static c = 2;
static d = this.c + 1;
static e = super.a + this.c + 1;
static f = ()=>this.c + 1;
static ff = function() {
this.c;
};
static foo() {
return this.c + 1;
}
static get fa() {
return this.c + 1;
}
static set fa(v) {
this.c = v + 1;
}
}

View File

@ -1,2 +1,8 @@
//// [typeOfThisInStaticMembers12.ts] //// [typeOfThisInStaticMembers12.ts]
this.c, this.c; class C {
static c = "foo";
static bar = class {
static [this.c] = 123;
[this.c] = 123;
};
}

View File

@ -1,2 +1,8 @@
//// [typeOfThisInStaticMembers13.ts] //// [typeOfThisInStaticMembers13.ts]
this.c, this.c; class C {
static c = "foo";
static bar = class {
static [this.c] = 123;
[this.c] = 123;
};
}

View File

@ -1,2 +1,10 @@
//// [typeOfThisInStaticMembers3.ts] //// [typeOfThisInStaticMembers3.ts]
this.a, this.c, super.a, this.c; class C {
static a = 1;
static b = this.a + 1;
}
class D extends C {
static c = 2;
static d = this.c + 1;
static e = super.a + this.c + 1;
}

View File

@ -1,2 +1,10 @@
//// [typeOfThisInStaticMembers4.ts] //// [typeOfThisInStaticMembers4.ts]
this.a, this.c, super.a, this.c; class C {
static a = 1;
static b = this.a + 1;
}
class D extends C {
static c = 2;
static d = this.c + 1;
static e = super.a + this.c + 1;
}

View File

@ -1,2 +1,10 @@
//// [typeOfThisInStaticMembers7.ts] //// [typeOfThisInStaticMembers7.ts]
this.a, this.c, super.a, this.c; class C {
static a = 1;
static b = this.a + 1;
}
class D extends C {
static c = 2;
static d = this.c + 1;
static e = 1 + super.a + (this.c + 1) + 1;
}

View File

@ -1 +1,12 @@
//// [typeOfThisInStaticMembers8.ts] //// [typeOfThisInStaticMembers8.ts]
class C {
static f = 1;
static arrowFunctionBoundary = ()=>this.f + 1;
static functionExprBoundary = function() {
return this.f + 2;
};
static classExprBoundary = class {
a = this.f + 3;
};
static functionAndClassDeclBoundary = void 0;
}

View File

@ -1 +1,14 @@
//// [typeOfThisInStaticMembers9.ts] //// [typeOfThisInStaticMembers9.ts]
class C {
static f = 1;
}
class D extends C {
static arrowFunctionBoundary = ()=>super.f + 1;
static functionExprBoundary = function() {
return super.f + 2;
};
static classExprBoundary = class {
a = super.f + 3;
};
static functionAndClassDeclBoundary = void 0;
}

View File

@ -8,4 +8,34 @@ class C {
readonlyCall = Symbol(); readonlyCall = Symbol();
readwriteCall = Symbol(); readwriteCall = Symbol();
} }
C.readonlyStaticCall, C.readonlyStaticType, C.readonlyStaticTypeAndCall, C.readwriteStaticCall, C.readonlyStaticCall, C.readonlyStaticType, C.readonlyStaticTypeAndCall, C.readwriteStaticCall, c.readonlyCall, c.readwriteCall, c.readonlyCall, c.readwriteCall, c.readonlyCall, c.readwriteCall, i.readonlyType, i.readonlyType, i.readonlyType, l.readonlyType, l.nested.readonlyNestedType, l.readonlyType, l.nested.readonlyNestedType, l.readonlyType, l.nested.readonlyNestedType, Promise.resolve(constCall), f(s), f(N.s), f(N.s), N.s, N.s, N.s, N.s, N.s, N.s, N.s, N.s, o[s], o[N.s], o[N.s], f(s), f(N.s), f(N.s), g(s), g(N.s), g(N.s), N.s, N.s, 2 * Math.random() && N.s, 2 * Math.random() && N.s, N.s; C.readonlyStaticCall, C.readonlyStaticType, C.readonlyStaticTypeAndCall, C.readwriteStaticCall, C.readonlyStaticCall, C.readonlyStaticType, C.readonlyStaticTypeAndCall, C.readwriteStaticCall, c.readonlyCall, c.readwriteCall, c.readonlyCall, c.readwriteCall, c.readonlyCall, c.readwriteCall, i.readonlyType, i.readonlyType, i.readonlyType, l.readonlyType, l.nested.readonlyNestedType, l.readonlyType, l.nested.readonlyNestedType, l.readonlyType, l.nested.readonlyNestedType, Promise.resolve(constCall), f(s), f(N.s), f(N.s), N.s, N.s, N.s, N.s, (p = s)=>p;
class C0 {
static a = s;
static b = N.s;
static c = N.s;
static d = s;
static e = N.s;
static f = N.s;
a = s;
b = N.s;
c = N.s;
d = s;
e = N.s;
f = N.s;
method1() {
return s;
}
async method2() {
return s;
}
async *method3() {
yield s;
}
*method4() {
yield s;
}
method5(p = s) {
return p;
}
}
o[s], o[N.s], o[N.s], f(s), f(N.s), f(N.s), g(s), g(N.s), g(N.s), N.s, N.s, 2 * Math.random() && N.s, 2 * Math.random() && N.s, N.s;

View File

@ -8,4 +8,34 @@ class C {
readonlyCall = Symbol(); readonlyCall = Symbol();
readwriteCall = Symbol(); readwriteCall = Symbol();
} }
C.readonlyStaticCall, C.readonlyStaticType, C.readonlyStaticTypeAndCall, C.readwriteStaticCall, C.readonlyStaticCall, C.readonlyStaticType, C.readonlyStaticTypeAndCall, C.readwriteStaticCall, c.readonlyCall, c.readwriteCall, c.readonlyCall, c.readwriteCall, c.readonlyCall, c.readwriteCall, i.readonlyType, i.readonlyType, i.readonlyType, l.readonlyType, l.nested.readonlyNestedType, l.readonlyType, l.nested.readonlyNestedType, l.readonlyType, l.nested.readonlyNestedType, Promise.resolve(constCall), f(s), f(N.s), f(N.s), N.s, N.s, N.s, N.s, N.s, N.s, N.s, N.s, o[s], o[N.s], o[N.s], f(s), f(N.s), f(N.s), g(s), g(N.s), g(N.s), N.s, N.s, 2 * Math.random() && N.s, 2 * Math.random() && N.s, N.s; C.readonlyStaticCall, C.readonlyStaticType, C.readonlyStaticTypeAndCall, C.readwriteStaticCall, C.readonlyStaticCall, C.readonlyStaticType, C.readonlyStaticTypeAndCall, C.readwriteStaticCall, c.readonlyCall, c.readwriteCall, c.readonlyCall, c.readwriteCall, c.readonlyCall, c.readwriteCall, i.readonlyType, i.readonlyType, i.readonlyType, l.readonlyType, l.nested.readonlyNestedType, l.readonlyType, l.nested.readonlyNestedType, l.readonlyType, l.nested.readonlyNestedType, Promise.resolve(constCall), f(s), f(N.s), f(N.s), N.s, N.s, N.s, N.s, (p = s)=>p;
class C0 {
static a = s;
static b = N.s;
static c = N.s;
static d = s;
static e = N.s;
static f = N.s;
a = s;
b = N.s;
c = N.s;
d = s;
e = N.s;
f = N.s;
method1() {
return s;
}
async method2() {
return s;
}
async *method3() {
yield s;
}
*method4() {
yield s;
}
method5(p = s) {
return p;
}
}
o[s], o[N.s], o[N.s], f(s), f(N.s), f(N.s), g(s), g(N.s), g(N.s), N.s, N.s, 2 * Math.random() && N.s, 2 * Math.random() && N.s, N.s;

View File

@ -1,2 +1,9 @@
//// [uniqueSymbolsDeclarationsInJs.js] //// [uniqueSymbolsDeclarationsInJs.js]
Symbol(), Symbol(), Symbol(), Symbol(); class C {
static readonlyStaticCall = Symbol();
static readonlyStaticTypeAndCall = Symbol();
static readwriteStaticCall = Symbol();
readonlyCall = Symbol();
readwriteCall = Symbol();
}
Symbol();

View File

@ -473,10 +473,33 @@ where
} }
match decl { match decl {
Decl::Class(ClassDecl { ident, .. }) => { Decl::Class(ClassDecl { ident, class, .. }) => {
if ident.sym == js_word!("arguments") { if ident.sym == js_word!("arguments") {
return; return;
} }
// Fix https://github.com/swc-project/swc/issues/5588
let may_have_side_effect = class.body.iter().any(|m| match m {
ClassMember::ClassProp(ClassProp {
is_static: true,
value: Some(_),
..
})
| ClassMember::PrivateProp(PrivateProp {
is_static: true,
value: Some(_),
..
}) => true,
ClassMember::StaticBlock(StaticBlock {
body: BlockStmt { stmts, .. },
..
}) if !stmts.is_empty() => true,
_ => false,
});
if may_have_side_effect {
return;
}
// If it is not used, drop it. // If it is not used, drop it.
if self if self
.data .data

View File

@ -0,0 +1,4 @@
{
"unused": true,
"toplevel": true
}

View File

@ -0,0 +1,12 @@
"use strict";
let getFoo;
let getFoo2
class Foo {
static #foo = 42;
static #_ = getFoo2 = this.#foo
static {
getFoo = () => this.#foo;
}
}
expect(getFoo()).toBe(42);
expect(getFoo2()).toBe(42);

View File

@ -0,0 +1,12 @@
"use strict";
let getFoo;
let getFoo2;
class Foo {
static #foo = 42;
static #_ = getFoo2 = this.#foo;
static{
getFoo = ()=>this.#foo;
}
}
expect(getFoo()).toBe(42);
expect(getFoo2()).toBe(42);