diff --git a/Cargo.lock b/Cargo.lock index 6fb4373841743..4e831176de0d1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1706,7 +1706,6 @@ dependencies = [ "oxc_allocator", "oxc_ast", "oxc_codegen", - "oxc_diagnostics", "oxc_mangler", "oxc_parser", "oxc_semantic", @@ -1988,6 +1987,7 @@ version = "0.30.5" dependencies = [ "assert-unchecked", "base64", + "cow-utils", "dashmap 6.0.1", "indexmap", "oxc-browserslist", diff --git a/crates/oxc_minifier/Cargo.toml b/crates/oxc_minifier/Cargo.toml index 9eb6e50b761e8..a868ebaf4c7ee 100644 --- a/crates/oxc_minifier/Cargo.toml +++ b/crates/oxc_minifier/Cargo.toml @@ -21,11 +21,9 @@ test = true doctest = false [dependencies] -cow-utils = { workspace = true } oxc_allocator = { workspace = true } oxc_ast = { workspace = true } oxc_codegen = { workspace = true } -oxc_diagnostics = { workspace = true } oxc_mangler = { workspace = true } oxc_parser = { workspace = true } oxc_semantic = { workspace = true } @@ -33,12 +31,12 @@ oxc_span = { workspace = true } oxc_syntax = { workspace = true } oxc_traverse = { workspace = true } +cow-utils = { workspace = true } num-bigint = { workspace = true } num-traits = { workspace = true } [dev-dependencies] oxc_parser = { workspace = true } -cow-utils = { workspace = true } insta = { workspace = true } pico-args = { workspace = true } diff --git a/crates/oxc_minifier/src/lib.rs b/crates/oxc_minifier/src/lib.rs index 2715235572897..9fad23f4f3b00 100644 --- a/crates/oxc_minifier/src/lib.rs +++ b/crates/oxc_minifier/src/lib.rs @@ -7,7 +7,6 @@ mod compressor; mod keep_var; mod node_util; mod options; -mod plugins; mod tri; mod ty; @@ -18,9 +17,7 @@ use oxc_allocator::Allocator; use oxc_ast::ast::Program; use oxc_mangler::Mangler; -pub use crate::{ - ast_passes::CompressorPass, compressor::Compressor, options::CompressOptions, plugins::*, -}; +pub use crate::{ast_passes::CompressorPass, compressor::Compressor, options::CompressOptions}; #[derive(Debug, Clone, Copy)] pub struct MinifierOptions { diff --git a/crates/oxc_minifier/tests/mod.rs b/crates/oxc_minifier/tests/mod.rs index a09c3043bacfd..2b6812d0d6be5 100644 --- a/crates/oxc_minifier/tests/mod.rs +++ b/crates/oxc_minifier/tests/mod.rs @@ -1,6 +1,5 @@ mod ast_passes; mod mangler; -mod plugins; use oxc_allocator::Allocator; use oxc_codegen::{CodeGenerator, CodegenOptions}; diff --git a/crates/oxc_minifier/tests/plugins/mod.rs b/crates/oxc_minifier/tests/plugins/mod.rs deleted file mode 100644 index f43e90253926e..0000000000000 --- a/crates/oxc_minifier/tests/plugins/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -mod inject_global_variables; -mod replace_global_defines; diff --git a/crates/oxc_transformer/Cargo.toml b/crates/oxc_transformer/Cargo.toml index 57f3133dad2b9..fb86c6971aed5 100644 --- a/crates/oxc_transformer/Cargo.toml +++ b/crates/oxc_transformer/Cargo.toml @@ -24,6 +24,7 @@ doctest = false oxc_allocator = { workspace = true } oxc_ast = { workspace = true } oxc_diagnostics = { workspace = true } +oxc_parser = { workspace = true } oxc_regular_expression = { workspace = true } oxc_semantic = { workspace = true } oxc_span = { workspace = true } @@ -32,6 +33,7 @@ oxc_traverse = { workspace = true } assert-unchecked = { workspace = true } base64 = { workspace = true } +cow-utils = { workspace = true } dashmap = { workspace = true } indexmap = { workspace = true } oxc-browserslist = { workspace = true } diff --git a/crates/oxc_transformer/src/lib.rs b/crates/oxc_transformer/src/lib.rs index 2002b1c731f85..c98189dcd885f 100644 --- a/crates/oxc_transformer/src/lib.rs +++ b/crates/oxc_transformer/src/lib.rs @@ -25,6 +25,8 @@ mod react; mod regexp; mod typescript; +mod plugins; + mod helpers { pub mod bindings; pub mod module_imports; @@ -52,6 +54,7 @@ pub use crate::{ env::{EnvOptions, Targets}, es2015::{ArrowFunctionsOptions, ES2015Options}, options::{BabelOptions, TransformOptions}, + plugins::*, react::{JsxOptions, JsxRuntime, ReactRefreshOptions}, typescript::{RewriteExtensionsMode, TypeScriptOptions}, }; diff --git a/crates/oxc_minifier/src/plugins/inject_global_variables.rs b/crates/oxc_transformer/src/plugins/inject_global_variables.rs similarity index 100% rename from crates/oxc_minifier/src/plugins/inject_global_variables.rs rename to crates/oxc_transformer/src/plugins/inject_global_variables.rs diff --git a/crates/oxc_minifier/src/plugins/mod.rs b/crates/oxc_transformer/src/plugins/mod.rs similarity index 100% rename from crates/oxc_minifier/src/plugins/mod.rs rename to crates/oxc_transformer/src/plugins/mod.rs diff --git a/crates/oxc_minifier/src/plugins/replace_global_defines.rs b/crates/oxc_transformer/src/plugins/replace_global_defines.rs similarity index 100% rename from crates/oxc_minifier/src/plugins/replace_global_defines.rs rename to crates/oxc_transformer/src/plugins/replace_global_defines.rs diff --git a/crates/oxc_transformer/tests/mod.rs b/crates/oxc_transformer/tests/mod.rs new file mode 100644 index 0000000000000..85cf1a563a20d --- /dev/null +++ b/crates/oxc_transformer/tests/mod.rs @@ -0,0 +1 @@ +mod plugins; diff --git a/crates/oxc_minifier/tests/plugins/inject_global_variables.rs b/crates/oxc_transformer/tests/plugins/inject_global_variables.rs similarity index 98% rename from crates/oxc_minifier/tests/plugins/inject_global_variables.rs rename to crates/oxc_transformer/tests/plugins/inject_global_variables.rs index 6793093b45f32..fb94828446cdd 100644 --- a/crates/oxc_minifier/tests/plugins/inject_global_variables.rs +++ b/crates/oxc_transformer/tests/plugins/inject_global_variables.rs @@ -4,12 +4,12 @@ use oxc_allocator::Allocator; use oxc_codegen::{CodeGenerator, CodegenOptions}; -use oxc_minifier::{InjectGlobalVariables, InjectGlobalVariablesConfig, InjectImport}; use oxc_parser::Parser; use oxc_semantic::SemanticBuilder; use oxc_span::SourceType; +use oxc_transformer::{InjectGlobalVariables, InjectGlobalVariablesConfig, InjectImport}; -use crate::run; +use super::run; pub(crate) fn test(source_text: &str, expected: &str, config: InjectGlobalVariablesConfig) { let source_type = SourceType::default(); @@ -25,7 +25,7 @@ pub(crate) fn test(source_text: &str, expected: &str, config: InjectGlobalVariab .with_options(CodegenOptions { single_quote: true, ..CodegenOptions::default() }) .build(program) .source_text; - let expected = run(expected, source_type, None); + let expected = run(expected, source_type); assert_eq!(result, expected, "for source {source_text}"); } diff --git a/crates/oxc_transformer/tests/plugins/mod.rs b/crates/oxc_transformer/tests/plugins/mod.rs new file mode 100644 index 0000000000000..8c72a1f7fd7bc --- /dev/null +++ b/crates/oxc_transformer/tests/plugins/mod.rs @@ -0,0 +1,17 @@ +mod inject_global_variables; +mod replace_global_defines; + +use oxc_allocator::Allocator; +use oxc_codegen::{CodeGenerator, CodegenOptions}; +use oxc_parser::Parser; +use oxc_span::SourceType; + +fn run(source_text: &str, source_type: SourceType) -> String { + let allocator = Allocator::default(); + let ret = Parser::new(&allocator, source_text, source_type).parse(); + let program = allocator.alloc(ret.program); + CodeGenerator::new() + .with_options(CodegenOptions { single_quote: true, ..CodegenOptions::default() }) + .build(program) + .source_text +} diff --git a/crates/oxc_minifier/tests/plugins/replace_global_defines.rs b/crates/oxc_transformer/tests/plugins/replace_global_defines.rs similarity index 95% rename from crates/oxc_minifier/tests/plugins/replace_global_defines.rs rename to crates/oxc_transformer/tests/plugins/replace_global_defines.rs index 1755855e197c9..feee297338fad 100644 --- a/crates/oxc_minifier/tests/plugins/replace_global_defines.rs +++ b/crates/oxc_transformer/tests/plugins/replace_global_defines.rs @@ -1,11 +1,11 @@ use oxc_allocator::Allocator; use oxc_codegen::{CodeGenerator, CodegenOptions}; -use oxc_minifier::{ReplaceGlobalDefines, ReplaceGlobalDefinesConfig}; use oxc_parser::Parser; use oxc_semantic::SemanticBuilder; use oxc_span::SourceType; +use oxc_transformer::{ReplaceGlobalDefines, ReplaceGlobalDefinesConfig}; -use crate::run; +use super::run; pub(crate) fn test(source_text: &str, expected: &str, config: ReplaceGlobalDefinesConfig) { let source_type = SourceType::default(); @@ -21,7 +21,7 @@ pub(crate) fn test(source_text: &str, expected: &str, config: ReplaceGlobalDefin .with_options(CodegenOptions { single_quote: true, ..CodegenOptions::default() }) .build(program) .source_text; - let expected = run(expected, source_type, None); + let expected = run(expected, source_type); assert_eq!(result, expected, "for source {source_text}"); }