feat(es/minifier): Drop empty static blocks (#8152)

**Related issue:**

 - Closes #8136
This commit is contained in:
Donny/강동윤 2023-10-19 14:06:12 -07:00 committed by GitHub
parent 64bddc110e
commit 8a461b8957
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 18 deletions

View File

@ -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);

View File

@ -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);

View File

@ -0,0 +1,4 @@
export class Foo {
static { }
foo = 2;
}

View File

@ -0,0 +1,3 @@
export class Foo {
foo = 2;
}