Skip to content

Commit

Permalink
refactor(minifier): remove unused code and traits (#8632)
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Jan 21, 2025
1 parent c1d243b commit 52458de
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 397 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion crates/oxc_minifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ oxc_syntax = { workspace = true }
oxc_traverse = { workspace = true }

cow-utils = { workspace = true }
rustc-hash = { workspace = true }

[dev-dependencies]
oxc_parser = { workspace = true }
Expand Down
284 changes: 0 additions & 284 deletions crates/oxc_minifier/src/ast_passes/exploit_assigns.rs

This file was deleted.

33 changes: 8 additions & 25 deletions crates/oxc_minifier/src/ast_passes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,16 @@ use oxc_traverse::{traverse_mut_with_ctx, ReusableTraverseCtx, Traverse, Travers

mod collapse_variable_declarations;
mod convert_to_dotted_properties;
mod exploit_assigns;
mod minimize_exit_points;
mod normalize;
mod peephole_fold_constants;
mod peephole_minimize_conditions;
mod peephole_remove_dead_code;
mod peephole_replace_known_methods;
mod peephole_substitute_alternate_syntax;
mod remove_unused_code;
mod statement_fusion;

pub use normalize::{Normalize, NormalizeOptions};
#[expect(unused)]
pub use remove_unused_code::RemoveUnusedCode;

pub trait CompressorPass<'a>: Traverse<'a> {
fn build(&mut self, program: &mut Program<'a>, ctx: &mut ReusableTraverseCtx<'a>);
}

pub struct PeepholeOptimizations {
target: ESTarget,
Expand All @@ -32,16 +24,16 @@ pub struct PeepholeOptimizations {
in_fixed_loop: bool,
}

impl PeepholeOptimizations {
impl<'a> PeepholeOptimizations {
pub fn new(target: ESTarget, in_fixed_loop: bool) -> Self {
Self { target, changed: false, in_fixed_loop }
}

pub fn run_in_loop<'a>(
&mut self,
program: &mut Program<'a>,
ctx: &mut ReusableTraverseCtx<'a>,
) {
pub fn build(&mut self, program: &mut Program<'a>, ctx: &mut ReusableTraverseCtx<'a>) {
traverse_mut_with_ctx(self, program, ctx);
}

pub fn run_in_loop(&mut self, program: &mut Program<'a>, ctx: &mut ReusableTraverseCtx<'a>) {
let mut i = 0;
loop {
self.changed = false;
Expand All @@ -58,16 +50,9 @@ impl PeepholeOptimizations {
}
}

impl<'a> CompressorPass<'a> for PeepholeOptimizations {
fn build(&mut self, program: &mut Program<'a>, ctx: &mut ReusableTraverseCtx<'a>) {
traverse_mut_with_ctx(self, program, ctx);
}
}

impl<'a> Traverse<'a> for PeepholeOptimizations {
fn exit_statements(&mut self, stmts: &mut Vec<'a, Statement<'a>>, ctx: &mut TraverseCtx<'a>) {
self.statement_fusion_exit_statements(stmts, ctx);
self.exploit_assigns(stmts, ctx);
self.collapse_variable_declarations(stmts, ctx);
self.minimize_conditions_exit_statements(stmts, ctx);
self.remove_dead_code_exit_statements(stmts, ctx);
Expand Down Expand Up @@ -167,14 +152,12 @@ pub struct DeadCodeElimination {
inner: PeepholeOptimizations,
}

impl DeadCodeElimination {
impl<'a> DeadCodeElimination {
pub fn new() -> Self {
Self { inner: PeepholeOptimizations::new(ESTarget::ESNext, false) }
}
}

impl<'a> CompressorPass<'a> for DeadCodeElimination {
fn build(&mut self, program: &mut Program<'a>, ctx: &mut ReusableTraverseCtx<'a>) {
pub fn build(&mut self, program: &mut Program<'a>, ctx: &mut ReusableTraverseCtx<'a>) {
traverse_mut_with_ctx(self, program, ctx);
}
}
Expand Down
Loading

0 comments on commit 52458de

Please sign in to comment.