mirror of
https://github.com/swc-project/swc.git
synced 2024-12-24 22:22:34 +03:00
feat(es/minifier): Drop empty static blocks (#8152)
**Related issue:** - Closes #8136
This commit is contained in:
parent
64bddc110e
commit
8a461b8957
@ -4,11 +4,5 @@ class C {
|
||||
static #_1 = 1;
|
||||
static #_3 = 3;
|
||||
static #_5 = 5;
|
||||
static{}
|
||||
static{}
|
||||
static{}
|
||||
static{}
|
||||
static{}
|
||||
static{}
|
||||
}
|
||||
console.log(_C__1);
|
||||
|
@ -303,6 +303,28 @@ impl VisitMut for Pure<'_> {
|
||||
self.drop_arguments_of_symbol_call(e);
|
||||
}
|
||||
|
||||
fn visit_mut_class_member(&mut self, m: &mut ClassMember) {
|
||||
m.visit_mut_children_with(self);
|
||||
|
||||
if let ClassMember::StaticBlock(sb) = m {
|
||||
if sb.body.stmts.is_empty() {
|
||||
*m = ClassMember::Empty(EmptyStmt { span: DUMMY_SP });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_mut_class_members(&mut self, m: &mut Vec<ClassMember>) {
|
||||
m.visit_mut_children_with(self);
|
||||
|
||||
m.retain(|m| {
|
||||
if let ClassMember::Empty(..) = m {
|
||||
return false;
|
||||
}
|
||||
|
||||
true
|
||||
});
|
||||
}
|
||||
|
||||
fn visit_mut_cond_expr(&mut self, e: &mut CondExpr) {
|
||||
e.visit_mut_children_with(self);
|
||||
|
||||
@ -560,6 +582,10 @@ impl VisitMut for Pure<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_mut_expr_or_spreads(&mut self, nodes: &mut Vec<ExprOrSpread>) {
|
||||
self.visit_par(nodes);
|
||||
}
|
||||
|
||||
fn visit_mut_expr_stmt(&mut self, s: &mut ExprStmt) {
|
||||
s.visit_mut_children_with(self);
|
||||
|
||||
@ -585,18 +611,6 @@ impl VisitMut for Pure<'_> {
|
||||
self.visit_par(nodes);
|
||||
}
|
||||
|
||||
fn visit_mut_opt_vec_expr_or_spreads(&mut self, nodes: &mut Vec<Option<ExprOrSpread>>) {
|
||||
self.visit_par(nodes);
|
||||
}
|
||||
|
||||
fn visit_mut_expr_or_spreads(&mut self, nodes: &mut Vec<ExprOrSpread>) {
|
||||
self.visit_par(nodes);
|
||||
}
|
||||
|
||||
fn visit_mut_var_declarators(&mut self, nodes: &mut Vec<VarDeclarator>) {
|
||||
self.visit_par(nodes);
|
||||
}
|
||||
|
||||
fn visit_mut_fn_decl(&mut self, n: &mut FnDecl) {
|
||||
#[cfg(feature = "debug")]
|
||||
let _tracing = tracing::span!(
|
||||
@ -727,6 +741,10 @@ impl VisitMut for Pure<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_mut_opt_vec_expr_or_spreads(&mut self, nodes: &mut Vec<Option<ExprOrSpread>>) {
|
||||
self.visit_par(nodes);
|
||||
}
|
||||
|
||||
fn visit_mut_pat_or_expr(&mut self, n: &mut PatOrExpr) {
|
||||
n.visit_mut_children_with(self);
|
||||
|
||||
@ -1039,6 +1057,10 @@ impl VisitMut for Pure<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_mut_var_declarators(&mut self, nodes: &mut Vec<VarDeclarator>) {
|
||||
self.visit_par(nodes);
|
||||
}
|
||||
|
||||
fn visit_mut_while_stmt(&mut self, s: &mut WhileStmt) {
|
||||
s.visit_mut_children_with(self);
|
||||
|
||||
|
@ -0,0 +1,4 @@
|
||||
export class Foo {
|
||||
static { }
|
||||
foo = 2;
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
export class Foo {
|
||||
foo = 2;
|
||||
}
|
Loading…
Reference in New Issue
Block a user