mirror of
https://github.com/danbulant/oxc
synced 2026-05-22 13:48:55 +00:00
Pure refactor. Re-order imports for clarity: 1. `std` 2. External crates 3. `oxc_*` crates 4. Current crate `use crate::...` 5. Super `use super::...` 6. Local modules This order is from "furthest away" to "closest". This makes it clearer to see what is coming from where. `cargo +nightly fmt` (#7877) did a lot of the work, but unfortunately `rustfmt` does not have an option to (a) put workspace crates in a separate block from external crates and (b) move `mod` statements to after `use` statements.
27 lines
914 B
Rust
27 lines
914 B
Rust
use napi_derive::napi;
|
|
|
|
use oxc_allocator::Allocator;
|
|
use oxc_codegen::{Codegen, CodegenOptions};
|
|
use oxc_minifier::{CompressOptions, Minifier, MinifierOptions};
|
|
use oxc_parser::Parser;
|
|
use oxc_span::SourceType;
|
|
|
|
#[allow(clippy::needless_pass_by_value)]
|
|
#[napi]
|
|
pub fn minify(filename: String, source_text: String) -> String {
|
|
let allocator = Allocator::default();
|
|
let source_type = SourceType::from_path(&filename).unwrap_or_default().with_typescript(true);
|
|
|
|
let mut program = Parser::new(&allocator, &source_text, source_type).parse().program;
|
|
|
|
let mangler =
|
|
Minifier::new(MinifierOptions { mangle: true, compress: CompressOptions::default() })
|
|
.build(&allocator, &mut program)
|
|
.mangler;
|
|
|
|
Codegen::new()
|
|
.with_options(CodegenOptions { minify: true, ..CodegenOptions::default() })
|
|
.with_mangler(mangler)
|
|
.build(&program)
|
|
.code
|
|
}
|