refactor(minifier): remove EmptyStatement in a single place (#8745)

This commit is contained in:
Boshen 2025-01-27 17:08:22 +08:00 committed by GitHub
parent 29417ddc03
commit 0fcff207c7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 2 additions and 13 deletions

View file

@ -133,10 +133,6 @@ impl<'a> PeepholeOptimizations {
_ => {}
}
}
if self.is_current_function_changed() {
stmts.retain(|stmt| !matches!(stmt, Statement::EmptyStatement(_)));
}
}
fn collapse_expr_into_for(

View file

@ -30,7 +30,6 @@ impl<'a> PeepholeOptimizations {
let mut local_change = false;
self.try_replace_if(stmts, &mut local_change, ctx);
if local_change {
stmts.retain(|stmt| !matches!(stmt, Statement::EmptyStatement(_)));
changed = local_change;
} else {
break;

View file

@ -72,11 +72,6 @@ impl<'a> PeepholeOptimizations {
*current_changed = true;
}
pub fn is_current_function_changed(&self) -> bool {
let (_, _, current_changed) = self.current_function.last();
*current_changed
}
#[inline]
fn is_prev_function_changed(&self) -> bool {
let (_, prev_changed, _) = self.current_function.last();
@ -146,6 +141,7 @@ impl<'a> Traverse<'a> for PeepholeOptimizations {
self.collapse_variable_declarations(stmts, ctx);
self.minimize_conditions_exit_statements(stmts, ctx);
self.remove_dead_code_exit_statements(stmts, ctx);
stmts.retain(|stmt| !matches!(stmt, Statement::EmptyStatement(_)));
}
fn exit_statement(&mut self, stmt: &mut Statement<'a>, ctx: &mut TraverseCtx<'a>) {
@ -337,6 +333,7 @@ impl<'a> Traverse<'a> for DeadCodeElimination {
fn exit_statements(&mut self, stmts: &mut Vec<'a, Statement<'a>>, ctx: &mut TraverseCtx<'a>) {
self.inner.remove_dead_code_exit_statements(stmts, Ctx(ctx));
stmts.retain(|stmt| !matches!(stmt, Statement::EmptyStatement(_)));
}
fn exit_expression(&mut self, expr: &mut Expression<'a>, ctx: &mut TraverseCtx<'a>) {

View file

@ -24,9 +24,6 @@ impl<'a, 'b> PeepholeOptimizations {
ctx: Ctx<'a, '_>,
) {
self.dead_code_elimination(stmts, ctx);
if stmts.iter().any(|stmt| matches!(stmt, Statement::EmptyStatement(_))) {
stmts.retain(|stmt| !matches!(stmt, Statement::EmptyStatement(_)));
}
}
pub fn remove_dead_code_exit_statement(&mut self, stmt: &mut Statement<'a>, ctx: Ctx<'a, '_>) {