diff --git a/crates/oxc_minifier/src/ast_passes/collapse.rs b/crates/oxc_minifier/src/ast_passes/collapse_variable_declarations.rs similarity index 93% rename from crates/oxc_minifier/src/ast_passes/collapse.rs rename to crates/oxc_minifier/src/ast_passes/collapse_variable_declarations.rs index eacf990446139..c76f7c5118173 100644 --- a/crates/oxc_minifier/src/ast_passes/collapse.rs +++ b/crates/oxc_minifier/src/ast_passes/collapse_variable_declarations.rs @@ -8,13 +8,13 @@ use crate::{CompressOptions, CompressorPass}; /// /// `var a; var b = 1; var c = 2` => `var a, b = 1; c = 2` /// TODO: `a = null; b = null;` => `a = b = null` -pub struct Collapse { +pub struct CollapseVariableDeclarations { options: CompressOptions, } -impl<'a> CompressorPass<'a> for Collapse {} +impl<'a> CompressorPass<'a> for CollapseVariableDeclarations {} -impl<'a> Traverse<'a> for Collapse { +impl<'a> Traverse<'a> for CollapseVariableDeclarations { fn enter_statements(&mut self, stmts: &mut Vec<'a, Statement<'a>>, ctx: &mut TraverseCtx<'a>) { if self.options.join_vars { self.join_vars(stmts, ctx); @@ -22,7 +22,7 @@ impl<'a> Traverse<'a> for Collapse { } } -impl<'a> Collapse { +impl<'a> CollapseVariableDeclarations { pub fn new(options: CompressOptions) -> Self { Self { options } } diff --git a/crates/oxc_minifier/src/ast_passes/mod.rs b/crates/oxc_minifier/src/ast_passes/mod.rs index d63c41106c10d..911c60f85d7df 100644 --- a/crates/oxc_minifier/src/ast_passes/mod.rs +++ b/crates/oxc_minifier/src/ast_passes/mod.rs @@ -1,16 +1,16 @@ -mod collapse; -mod fold_constants; -mod minimize_conditions; -mod remove_dead_code; +mod collapse_variable_declarations; +mod peephole_fold_constants; +mod peephole_minimize_conditions; +mod peephole_remove_dead_code; +mod peephole_substitute_alternate_syntax; mod remove_syntax; -mod substitute_alternate_syntax; -pub use collapse::Collapse; -pub use fold_constants::FoldConstants; -pub use minimize_conditions::MinimizeConditions; -pub use remove_dead_code::RemoveDeadCode; +pub use collapse_variable_declarations::CollapseVariableDeclarations; +pub use peephole_fold_constants::PeepholeFoldConstants; +pub use peephole_minimize_conditions::PeepholeMinimizeConditions; +pub use peephole_remove_dead_code::PeepholeRemoveDeadCode; +pub use peephole_substitute_alternate_syntax::PeepholeSubstituteAlternateSyntax; pub use remove_syntax::RemoveSyntax; -pub use substitute_alternate_syntax::SubstituteAlternateSyntax; use oxc_ast::ast::Program; use oxc_semantic::{ScopeTree, SymbolTable}; diff --git a/crates/oxc_minifier/src/ast_passes/fold_constants.rs b/crates/oxc_minifier/src/ast_passes/peephole_fold_constants.rs similarity index 99% rename from crates/oxc_minifier/src/ast_passes/fold_constants.rs rename to crates/oxc_minifier/src/ast_passes/peephole_fold_constants.rs index 9b12f946e41dc..89a587ea5fd1c 100644 --- a/crates/oxc_minifier/src/ast_passes/fold_constants.rs +++ b/crates/oxc_minifier/src/ast_passes/peephole_fold_constants.rs @@ -21,19 +21,19 @@ use crate::{ /// Constant Folding /// /// -pub struct FoldConstants { +pub struct PeepholeFoldConstants { evaluate: bool, } -impl<'a> CompressorPass<'a> for FoldConstants {} +impl<'a> CompressorPass<'a> for PeepholeFoldConstants {} -impl<'a> Traverse<'a> for FoldConstants { +impl<'a> Traverse<'a> for PeepholeFoldConstants { fn exit_expression(&mut self, expr: &mut Expression<'a>, ctx: &mut TraverseCtx<'a>) { self.fold_expression(expr, ctx); } } -impl<'a> FoldConstants { +impl<'a> PeepholeFoldConstants { pub fn new() -> Self { Self { evaluate: false } } diff --git a/crates/oxc_minifier/src/ast_passes/minimize_conditions.rs b/crates/oxc_minifier/src/ast_passes/peephole_minimize_conditions.rs similarity index 92% rename from crates/oxc_minifier/src/ast_passes/minimize_conditions.rs rename to crates/oxc_minifier/src/ast_passes/peephole_minimize_conditions.rs index 5c270608a924e..a0593721b0635 100644 --- a/crates/oxc_minifier/src/ast_passes/minimize_conditions.rs +++ b/crates/oxc_minifier/src/ast_passes/peephole_minimize_conditions.rs @@ -10,17 +10,17 @@ use crate::{node_util::NodeUtil, tri::Tri, CompressorPass}; /// with `? :` and short-circuit binary operators. /// /// -pub struct MinimizeConditions; +pub struct PeepholeMinimizeConditions; -impl<'a> CompressorPass<'a> for MinimizeConditions {} +impl<'a> CompressorPass<'a> for PeepholeMinimizeConditions {} -impl<'a> Traverse<'a> for MinimizeConditions { +impl<'a> Traverse<'a> for PeepholeMinimizeConditions { fn exit_expression(&mut self, expr: &mut Expression<'a>, ctx: &mut TraverseCtx<'a>) { self.fold_expression(expr, ctx); } } -impl<'a> MinimizeConditions { +impl<'a> PeepholeMinimizeConditions { pub fn new() -> Self { Self } diff --git a/crates/oxc_minifier/src/ast_passes/remove_dead_code.rs b/crates/oxc_minifier/src/ast_passes/peephole_remove_dead_code.rs similarity index 95% rename from crates/oxc_minifier/src/ast_passes/remove_dead_code.rs rename to crates/oxc_minifier/src/ast_passes/peephole_remove_dead_code.rs index b5425e8c8e640..7a84f389b6785 100644 --- a/crates/oxc_minifier/src/ast_passes/remove_dead_code.rs +++ b/crates/oxc_minifier/src/ast_passes/peephole_remove_dead_code.rs @@ -10,11 +10,11 @@ use crate::{keep_var::KeepVar, node_util::NodeUtil, tri::Tri, CompressorPass}; /// Terser option: `dead_code: true`. /// /// See `KeepVar` at the end of this file for `var` hoisting logic. -pub struct RemoveDeadCode; +pub struct PeepholeRemoveDeadCode; -impl<'a> CompressorPass<'a> for RemoveDeadCode {} +impl<'a> CompressorPass<'a> for PeepholeRemoveDeadCode {} -impl<'a> Traverse<'a> for RemoveDeadCode { +impl<'a> Traverse<'a> for PeepholeRemoveDeadCode { fn enter_statement(&mut self, stmt: &mut Statement<'a>, ctx: &mut TraverseCtx<'a>) { Self::fold_if_statement(stmt, ctx); } @@ -25,7 +25,7 @@ impl<'a> Traverse<'a> for RemoveDeadCode { } } -impl<'a> RemoveDeadCode { +impl<'a> PeepholeRemoveDeadCode { pub fn new() -> Self { Self {} } diff --git a/crates/oxc_minifier/src/ast_passes/substitute_alternate_syntax.rs b/crates/oxc_minifier/src/ast_passes/peephole_substitute_alternate_syntax.rs similarity index 97% rename from crates/oxc_minifier/src/ast_passes/substitute_alternate_syntax.rs rename to crates/oxc_minifier/src/ast_passes/peephole_substitute_alternate_syntax.rs index 85d11d31cffe5..56e3dd57da747 100644 --- a/crates/oxc_minifier/src/ast_passes/substitute_alternate_syntax.rs +++ b/crates/oxc_minifier/src/ast_passes/peephole_substitute_alternate_syntax.rs @@ -11,14 +11,14 @@ use crate::{node_util::NodeUtil, CompressOptions, CompressorPass}; /// A peephole optimization that minimizes code by simplifying conditional /// expressions, replacing IFs with HOOKs, replacing object constructors /// with literals, and simplifying returns. -pub struct SubstituteAlternateSyntax { +pub struct PeepholeSubstituteAlternateSyntax { options: CompressOptions, in_define_export: bool, } -impl<'a> CompressorPass<'a> for SubstituteAlternateSyntax {} +impl<'a> CompressorPass<'a> for PeepholeSubstituteAlternateSyntax {} -impl<'a> Traverse<'a> for SubstituteAlternateSyntax { +impl<'a> Traverse<'a> for PeepholeSubstituteAlternateSyntax { fn enter_statement(&mut self, stmt: &mut Statement<'a>, _ctx: &mut TraverseCtx<'a>) { self.compress_block(stmt); // self.compress_while(stmt); @@ -81,7 +81,7 @@ impl<'a> Traverse<'a> for SubstituteAlternateSyntax { } } -impl<'a> SubstituteAlternateSyntax { +impl<'a> PeepholeSubstituteAlternateSyntax { pub fn new(options: CompressOptions) -> Self { Self { options, in_define_export: false } } diff --git a/crates/oxc_minifier/src/compressor.rs b/crates/oxc_minifier/src/compressor.rs index b83e48f3630cb..12338e72443db 100644 --- a/crates/oxc_minifier/src/compressor.rs +++ b/crates/oxc_minifier/src/compressor.rs @@ -5,8 +5,8 @@ use oxc_traverse::TraverseCtx; use crate::{ ast_passes::{ - Collapse, FoldConstants, MinimizeConditions, RemoveDeadCode, RemoveSyntax, - SubstituteAlternateSyntax, + CollapseVariableDeclarations, PeepholeFoldConstants, PeepholeMinimizeConditions, + PeepholeRemoveDeadCode, PeepholeSubstituteAlternateSyntax, RemoveSyntax, }, CompressOptions, CompressorPass, }; @@ -53,31 +53,31 @@ impl<'a> Compressor<'a> { fn minimize_conditions(&self, program: &mut Program<'a>, ctx: &mut TraverseCtx<'a>) { if self.options.minimize_conditions { - MinimizeConditions::new().build(program, ctx); + PeepholeMinimizeConditions::new().build(program, ctx); } } fn fold_constants(&self, program: &mut Program<'a>, ctx: &mut TraverseCtx<'a>) { if self.options.fold_constants { - FoldConstants::new().with_evaluate(self.options.evaluate).build(program, ctx); + PeepholeFoldConstants::new().with_evaluate(self.options.evaluate).build(program, ctx); } } fn substitute_alternate_syntax(&self, program: &mut Program<'a>, ctx: &mut TraverseCtx<'a>) { if self.options.substitute_alternate_syntax { - SubstituteAlternateSyntax::new(self.options).build(program, ctx); + PeepholeSubstituteAlternateSyntax::new(self.options).build(program, ctx); } } fn remove_dead_code(&self, program: &mut Program<'a>, ctx: &mut TraverseCtx<'a>) { if self.options.remove_dead_code { - RemoveDeadCode::new().build(program, ctx); + PeepholeRemoveDeadCode::new().build(program, ctx); } } fn collapse(&self, program: &mut Program<'a>, ctx: &mut TraverseCtx<'a>) { if self.options.collapse { - Collapse::new(self.options).build(program, ctx); + CollapseVariableDeclarations::new(self.options).build(program, ctx); } } } diff --git a/crates/oxc_minifier/src/lib.rs b/crates/oxc_minifier/src/lib.rs index 8d6d6c8cc0dc5..077f81b0877fd 100644 --- a/crates/oxc_minifier/src/lib.rs +++ b/crates/oxc_minifier/src/lib.rs @@ -16,10 +16,7 @@ use oxc_ast::ast::Program; use oxc_mangler::Mangler; pub use crate::{ - ast_passes::{CompressorPass, RemoveDeadCode, RemoveSyntax}, - compressor::Compressor, - options::CompressOptions, - plugins::*, + ast_passes::CompressorPass, compressor::Compressor, options::CompressOptions, plugins::*, }; #[derive(Debug, Clone, Copy)] diff --git a/crates/oxc_minifier/tests/ast_passes/mod.rs b/crates/oxc_minifier/tests/ast_passes/mod.rs index 7b193b434635d..7d962a84d57c0 100644 --- a/crates/oxc_minifier/tests/ast_passes/mod.rs +++ b/crates/oxc_minifier/tests/ast_passes/mod.rs @@ -1,11 +1,11 @@ mod collapse_variable_declarations; mod dead_code_elimination; mod fold_conditions; -mod fold_constants; -mod minimize_conditions; +mod peephole_fold_constants; +mod peephole_minimize_conditions; +mod peephole_substitute_alternate_syntax; mod remove_syntax; mod reorder_constant_expression; -mod substitute_alternate_syntax; // Oxc Integration Tests diff --git a/crates/oxc_minifier/tests/ast_passes/fold_constants.rs b/crates/oxc_minifier/tests/ast_passes/peephole_fold_constants.rs similarity index 100% rename from crates/oxc_minifier/tests/ast_passes/fold_constants.rs rename to crates/oxc_minifier/tests/ast_passes/peephole_fold_constants.rs diff --git a/crates/oxc_minifier/tests/ast_passes/minimize_conditions.rs b/crates/oxc_minifier/tests/ast_passes/peephole_minimize_conditions.rs similarity index 100% rename from crates/oxc_minifier/tests/ast_passes/minimize_conditions.rs rename to crates/oxc_minifier/tests/ast_passes/peephole_minimize_conditions.rs diff --git a/crates/oxc_minifier/tests/ast_passes/substitute_alternate_syntax.rs b/crates/oxc_minifier/tests/ast_passes/peephole_substitute_alternate_syntax.rs similarity index 100% rename from crates/oxc_minifier/tests/ast_passes/substitute_alternate_syntax.rs rename to crates/oxc_minifier/tests/ast_passes/peephole_substitute_alternate_syntax.rs