oxc/napi/minify/src/lib.rs
overlookmotel 3858221f45 refactor(global): sort imports (#7883)
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.
2024-12-14 15:07:21 +00:00

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
}