mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 20:28:58 +00:00
refactor(minifier): remove EmptyStatement in a single place (#8745)
This commit is contained in:
parent
29417ddc03
commit
0fcff207c7
4 changed files with 2 additions and 13 deletions
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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>) {
|
||||
|
|
|
|||
|
|
@ -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, '_>) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue