oxc/crates/oxc_minifier/tests/mod.rs
Boshen ce4d4698b4 feat(codegen)!: remove const generic MINIFY (#5001)
This is a premature optimization, makes the code complicated, and bloats the final binary size.

The minify option is moved to `CodegenOptions`
2024-08-20 08:13:27 +00:00

32 lines
1.1 KiB
Rust

mod ast_passes;
mod mangler;
mod plugins;
use oxc_allocator::Allocator;
use oxc_codegen::{CodeGenerator, CodegenOptions};
use oxc_minifier::{CompressOptions, Compressor};
use oxc_parser::Parser;
use oxc_span::SourceType;
pub(crate) fn test(source_text: &str, expected: &str, options: CompressOptions) {
let source_type = SourceType::default();
let result = run(source_text, source_type, Some(options));
let expected = run(expected, source_type, None);
assert_eq!(
result, expected,
"\nfor source {source_text:?}\nexpect {expected:?}\ngot {result:?}"
);
}
fn run(source_text: &str, source_type: SourceType, options: Option<CompressOptions>) -> String {
let allocator = Allocator::default();
let ret = Parser::new(&allocator, source_text, source_type).parse();
let program = allocator.alloc(ret.program);
if let Some(options) = options {
Compressor::new(&allocator, options).build(program);
}
CodeGenerator::new()
.with_options(CodegenOptions { single_quote: true, ..CodegenOptions::default() })
.build(program)
.source_text
}