Skip to content

Commit

Permalink
feat(transformer,minifier)!: move define and inject plugin from minif…
Browse files Browse the repository at this point in the history
…ier to transformer (#6199)
  • Loading branch information
Boshen committed Oct 1, 2024
1 parent 51a78d5 commit 82ab689
Show file tree
Hide file tree
Showing 14 changed files with 32 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

4 changes: 1 addition & 3 deletions crates/oxc_minifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,22 @@ 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 }
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 }
5 changes: 1 addition & 4 deletions crates/oxc_minifier/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ mod compressor;
mod keep_var;
mod node_util;
mod options;
mod plugins;
mod tri;
mod ty;

Expand All @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion crates/oxc_minifier/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
mod ast_passes;
mod mangler;
mod plugins;

use oxc_allocator::Allocator;
use oxc_codegen::{CodeGenerator, CodegenOptions};
Expand Down
2 changes: 0 additions & 2 deletions crates/oxc_minifier/tests/plugins/mod.rs

This file was deleted.

2 changes: 2 additions & 0 deletions crates/oxc_transformer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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 }
Expand Down
3 changes: 3 additions & 0 deletions crates/oxc_transformer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ mod react;
mod regexp;
mod typescript;

mod plugins;

mod helpers {
pub mod bindings;
pub mod module_imports;
Expand Down Expand Up @@ -52,6 +54,7 @@ pub use crate::{
env::{EnvOptions, Targets},
es2015::{ArrowFunctionsOptions, ES2015Options},
options::{BabelOptions, TransformOptions},
plugins::*,
react::{JsxOptions, JsxRuntime, ReactRefreshOptions},
typescript::{RewriteExtensionsMode, TypeScriptOptions},
};
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions crates/oxc_transformer/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod plugins;
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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}");
}

Expand Down
17 changes: 17 additions & 0 deletions crates/oxc_transformer/tests/plugins/mod.rs
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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}");
}

Expand Down

0 comments on commit 82ab689

Please sign in to comment.