-
-
Notifications
You must be signed in to change notification settings - Fork 454
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: fix cyclic dependencies by moving mangler tests to
oxc_minifier
- Loading branch information
Showing
7 changed files
with
37 additions
and
49 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use std::fmt::Write; | ||
|
||
use oxc_allocator::Allocator; | ||
use oxc_codegen::{CodeGenerator, CodegenOptions}; | ||
use oxc_mangler::ManglerBuilder; | ||
use oxc_minifier::{CompressOptions, Minifier, MinifierOptions}; | ||
use oxc_parser::Parser; | ||
use oxc_span::SourceType; | ||
|
||
fn mangle(source_text: &str) -> String { | ||
let allocator = Allocator::default(); | ||
let source_type = SourceType::default().with_module(true); | ||
let ret = Parser::new(&allocator, source_text, source_type).parse(); | ||
let program = ret.program; | ||
let mangler = ManglerBuilder::default().build(&program); | ||
CodeGenerator::new().with_mangler(Some(mangler)).build(&program).source_text | ||
} | ||
|
||
#[test] | ||
fn mangler() { | ||
let cases = [ | ||
"function foo(a) {a}", | ||
"function foo(a) { let _ = { x } }", | ||
"function foo(a) { let { x } = y }", | ||
"var x; function foo(a) { ({ x } = y) }", | ||
]; | ||
|
||
let snapshot = cases.into_iter().fold(String::new(), |mut w, case| { | ||
write!(w, "{case}\n{}\n", mangle(case)).unwrap(); | ||
w | ||
}); | ||
|
||
insta::with_settings!({ prepend_module_to_snapshot => false, omit_expression => true }, { | ||
insta::assert_snapshot!("mangler", snapshot); | ||
}); | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
#![allow(unused)] | ||
// mod closure; | ||
// mod esbuild; | ||
mod mangler; | ||
mod oxc; | ||
// mod tdewolff; | ||
// mod terser; | ||
|