Skip to main content

Compressor

Struct Compressor 

Source
pub struct Compressor<'a> { /* private fields */ }

Implementations§

Source§

impl<'a> Compressor<'a>

Source

pub fn new(allocator: &'a Allocator) -> Self

Source

pub fn build(self, program: &mut Program<'a>, options: CompressOptions)

Full minify: removes dead code and applies size-reducing transforms. For tree-shaking only, see Self::dead_code_elimination.

Source

pub fn build_with_scoping( self, program: &mut Program<'a>, scoping: Scoping, options: CompressOptions, ) -> u8

Returns total number of iterations ran.

§Precondition

scoping must be consistent with program in the resolved-reference domain: every resolved IdentifierReference in program must be present in its symbol’s resolved-references list, and no list may contain a ReferenceId whose node is absent from program. The compressor refreshes scoping incrementally — it only prunes references for nodes it drops, and no longer rebuilds liveness from scratch each pass — so a caller that mutated program after building scoping must reflect those edits in scoping. Stale extra references cause missed optimizations (output stays correct); an added reference that was never recorded can cause incorrect output. In-repo callers satisfy this by rebuilding a fresh Scoping immediately before calling this — e.g. crates/oxc/src/compiler.rs rebuilds scoping before compress/DCE whenever ReplaceGlobalDefines reports a change.

Source

pub fn dead_code_elimination( self, program: &mut Program<'a>, options: CompressOptions, ) -> u8

Tree-shaking only: removes dead and unused code, but does not otherwise shrink the output like Self::build. Rolldown runs this on its own.

Source

pub fn dead_code_elimination_with_scoping( self, program: &mut Program<'a>, scoping: Scoping, options: CompressOptions, ) -> u8

Returns total number of iterations ran.

§Precondition

Same incoming-scoping consistency requirement as Self::build_with_scoping — see its docs.

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for Compressor<'a>

§

impl<'a> !Send for Compressor<'a>

§

impl<'a> !Sync for Compressor<'a>

§

impl<'a> !UnwindSafe for Compressor<'a>

§

impl<'a> Freeze for Compressor<'a>

§

impl<'a> Unpin for Compressor<'a>

§

impl<'a> UnsafeUnpin for Compressor<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<'a, T> FromIn<'a, T> for T

Source§

fn from_in(t: T, _: &'a Allocator) -> T

Converts to this type from the input type within the given allocator.
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<'a, T, U> IntoIn<'a, U> for T
where U: FromIn<'a, T>,

Source§

fn into_in(self, allocator: &'a Allocator) -> U

Converts this type into the (usually inferred) input type within the given allocator.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.