Skip to content

Commit

Permalink
chore: fix cyclic dependencies by moving mangler tests to oxc_minifier
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Jul 23, 2024
1 parent 6beef74 commit fb15a19
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 49 deletions.
4 changes: 0 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 0 additions & 7 deletions crates/oxc_mangler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,3 @@ oxc_ast = { workspace = true }
oxc_semantic = { workspace = true }
oxc_index = { workspace = true }
itertools = { workspace = true }

[dev-dependencies]
oxc_codegen = { workspace = true }
oxc_parser = { workspace = true }
oxc_span = { workspace = true }
oxc_allocator = { workspace = true }
insta = { workspace = true }
24 changes: 0 additions & 24 deletions crates/oxc_mangler/tests/integration/main.rs

This file was deleted.

14 changes: 0 additions & 14 deletions crates/oxc_mangler/tests/integration/tester.rs

This file was deleted.

36 changes: 36 additions & 0 deletions crates/oxc_minifier/tests/mangler/mod.rs
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);
});
}
1 change: 1 addition & 0 deletions crates/oxc_minifier/tests/mod.rs
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;
Expand Down

0 comments on commit fb15a19

Please sign in to comment.