Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/oxc_minifier/src/compressor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ use oxc_traverse::ReusableTraverseCtx;

use crate::{
CompressOptions,
ctx::MinifierState,
peephole::{
DeadCodeElimination, LatePeepholeOptimizations, Normalize, NormalizeOptions,
PeepholeOptimizations,
},
state::MinifierState,
};

pub struct Compressor<'a> {
Expand Down
27 changes: 3 additions & 24 deletions crates/oxc_minifier/src/ctx.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
use std::{
ops::{Deref, DerefMut},
rc::Rc,
};

use rustc_hash::FxHashMap;
use std::ops::{Deref, DerefMut};

use oxc_ast::{AstBuilder, ast::*};
use oxc_ecmascript::{
Expand All @@ -12,27 +7,11 @@ use oxc_ecmascript::{
},
side_effects::{MayHaveSideEffects, PropertyReadSideEffects},
};
use oxc_semantic::{IsGlobalReference, Scoping, SymbolId};
use oxc_semantic::{IsGlobalReference, Scoping};
use oxc_span::format_atom;
use oxc_syntax::reference::ReferenceId;

use crate::CompressOptions;

pub struct MinifierState<'a> {
pub options: Rc<CompressOptions>,

/// Constant values evaluated from expressions.
///
/// Values are saved during constant evaluation phase.
/// Values are read during [oxc_ecmascript::is_global_reference::IsGlobalReference::get_constant_value_for_reference_id].
pub constant_values: FxHashMap<SymbolId, ConstantValue<'a>>,
}

impl MinifierState<'_> {
pub fn new(options: Rc<CompressOptions>) -> Self {
Self { options, constant_values: FxHashMap::default() }
}
}
use crate::state::MinifierState;

pub type TraverseCtx<'a> = oxc_traverse::TraverseCtx<'a, MinifierState<'a>>;

Expand Down
1 change: 1 addition & 0 deletions crates/oxc_minifier/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod ctx;
mod keep_var;
mod options;
mod peephole;
mod state;

#[cfg(test)]
mod tester;
Expand Down
3 changes: 2 additions & 1 deletion crates/oxc_minifier/src/peephole/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ use oxc_syntax::{es_target::ESTarget, scope::ScopeId};
use oxc_traverse::{ReusableTraverseCtx, Traverse, traverse_mut_with_ctx};

use crate::{
ctx::{Ctx, MinifierState, TraverseCtx},
ctx::{Ctx, TraverseCtx},
options::CompressOptionsKeepNames,
state::MinifierState,
};

pub use self::normalize::{Normalize, NormalizeOptions};
Expand Down
5 changes: 4 additions & 1 deletion crates/oxc_minifier/src/peephole/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use oxc_span::GetSpan;
use oxc_syntax::scope::ScopeFlags;
use oxc_traverse::{Ancestor, ReusableTraverseCtx, Traverse, traverse_mut_with_ctx};

use crate::ctx::{Ctx, MinifierState, TraverseCtx};
use crate::{
ctx::{Ctx, TraverseCtx},
state::MinifierState,
};

#[derive(Default)]
pub struct NormalizeOptions {
Expand Down
24 changes: 24 additions & 0 deletions crates/oxc_minifier/src/state.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use std::rc::Rc;

use rustc_hash::FxHashMap;

use oxc_ecmascript::constant_evaluation::ConstantValue;
use oxc_semantic::SymbolId;

use crate::CompressOptions;

pub struct MinifierState<'a> {
pub options: Rc<CompressOptions>,

/// Constant values evaluated from expressions.
///
/// Values are saved during constant evaluation phase.
/// Values are read during [oxc_ecmascript::is_global_reference::IsGlobalReference::get_constant_value_for_reference_id].
pub constant_values: FxHashMap<SymbolId, ConstantValue<'a>>,
}

impl MinifierState<'_> {
pub fn new(options: Rc<CompressOptions>) -> Self {
Self { options, constant_values: FxHashMap::default() }
}
}
Loading