diff --git a/Cargo.lock b/Cargo.lock index 1c37b43f79237..a0122e94c9516 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1563,13 +1563,9 @@ dependencies = [ name = "oxc_mangler" version = "0.21.0" dependencies = [ - "insta", "itertools 0.13.0", - "oxc_allocator", "oxc_ast", - "oxc_codegen", "oxc_index", - "oxc_parser", "oxc_semantic", "oxc_span", ] diff --git a/crates/oxc_mangler/Cargo.toml b/crates/oxc_mangler/Cargo.toml index e5717b71d7068..3a8d3819cc8c2 100644 --- a/crates/oxc_mangler/Cargo.toml +++ b/crates/oxc_mangler/Cargo.toml @@ -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 } diff --git a/crates/oxc_mangler/tests/integration/main.rs b/crates/oxc_mangler/tests/integration/main.rs deleted file mode 100644 index c746940bf172b..0000000000000 --- a/crates/oxc_mangler/tests/integration/main.rs +++ /dev/null @@ -1,24 +0,0 @@ -mod tester; - -use std::fmt::Write; - -use tester::mangle; - -#[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); - }); -} diff --git a/crates/oxc_mangler/tests/integration/tester.rs b/crates/oxc_mangler/tests/integration/tester.rs deleted file mode 100644 index cdfdcc82cabce..0000000000000 --- a/crates/oxc_mangler/tests/integration/tester.rs +++ /dev/null @@ -1,14 +0,0 @@ -use oxc_allocator::Allocator; -use oxc_codegen::CodeGenerator; -use oxc_mangler::ManglerBuilder; -use oxc_parser::Parser; -use oxc_span::SourceType; - -pub 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 -} diff --git a/crates/oxc_minifier/tests/mangler/mod.rs b/crates/oxc_minifier/tests/mangler/mod.rs new file mode 100644 index 0000000000000..55728f1177414 --- /dev/null +++ b/crates/oxc_minifier/tests/mangler/mod.rs @@ -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); + }); +} diff --git a/crates/oxc_mangler/tests/integration/snapshots/mangler.snap b/crates/oxc_minifier/tests/mangler/snapshots/mangler.snap similarity index 100% rename from crates/oxc_mangler/tests/integration/snapshots/mangler.snap rename to crates/oxc_minifier/tests/mangler/snapshots/mangler.snap diff --git a/crates/oxc_minifier/tests/mod.rs b/crates/oxc_minifier/tests/mod.rs index 4eae2c93d970d..805ac7b9980d3 100644 --- a/crates/oxc_minifier/tests/mod.rs +++ b/crates/oxc_minifier/tests/mod.rs @@ -1,6 +1,7 @@ #![allow(unused)] // mod closure; // mod esbuild; +mod mangler; mod oxc; // mod tdewolff; // mod terser;