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
16 changes: 13 additions & 3 deletions crates/oxc_mangler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,19 @@ impl Mangler {
}

#[must_use]
pub fn build<'a>(mut self, program: &'a Program<'a>) -> Mangler {
pub fn build(self, program: &Program<'_>) -> Mangler {
let semantic = SemanticBuilder::new().build(program).semantic;
let (symbol_table, scope_tree) = semantic.into_symbol_table_and_scope_tree();
self.build_with_symbols_and_scopes(symbol_table, &scope_tree, program)
}

#[must_use]
pub fn build_with_symbols_and_scopes(
mut self,
symbol_table: SymbolTable,
scope_tree: &ScopeTree,
program: &Program<'_>,
) -> Mangler {
let (exported_names, exported_symbols) = if self.options.top_level {
Mangler::collect_exported_symbols(program)
} else {
Expand All @@ -94,7 +104,7 @@ impl Mangler {

// Mangle the symbol table by computing slots from the scope tree.
// A slot is the occurrence index of a binding identifier inside a scope.
let (mut symbol_table, scope_tree) = semantic.into_symbol_table_and_scope_tree();
let mut symbol_table = symbol_table;

// Total number of slots for all scopes
let mut total_number_of_slots: Slot = 0;
Expand Down Expand Up @@ -136,7 +146,7 @@ impl Mangler {
let frequencies = self.tally_slot_frequencies(
&symbol_table,
&exported_symbols,
&scope_tree,
scope_tree,
total_number_of_slots,
&slots,
);
Expand Down
18 changes: 13 additions & 5 deletions crates/oxc_minifier/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mod tester;
use oxc_allocator::Allocator;
use oxc_ast::ast::Program;
use oxc_mangler::Mangler;
use oxc_semantic::SemanticBuilder;

pub use oxc_mangler::MangleOptions;

Expand Down Expand Up @@ -43,11 +44,18 @@ impl Minifier {
}

pub fn build<'a>(self, allocator: &'a Allocator, program: &mut Program<'a>) -> MinifierReturn {
Compressor::new(allocator, self.options.compress).build(program);
let mangler = self
.options
.mangle
.map(|options| Mangler::default().with_options(options).build(program));
let semantic = SemanticBuilder::new().build(program).semantic;
let stats = semantic.stats();
let (symbols, scopes) = semantic.into_symbol_table_and_scope_tree();
Compressor::new(allocator, self.options.compress)
.build_with_symbols_and_scopes(symbols, scopes, program);
let mangler = self.options.mangle.map(|options| {
let semantic = SemanticBuilder::new().with_stats(stats).build(program).semantic;
let (symbols, scopes) = semantic.into_symbol_table_and_scope_tree();
Mangler::default()
.with_options(options)
.build_with_symbols_and_scopes(symbols, &scopes, program)
});
MinifierReturn { mangler }
}
}
Loading