Skip to content

Commit

Permalink
refactor(minifier): move tests to their src files (#5912)
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Sep 20, 2024
1 parent cbaeea6 commit 943bd76
Show file tree
Hide file tree
Showing 20 changed files with 1,969 additions and 1,982 deletions.
2 changes: 1 addition & 1 deletion crates/oxc_minifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ description.workspace = true
workspace = true

[lib]
test = false
test = true
doctest = false

[dependencies]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,34 @@ impl<'a> CollapseVariableDeclarations {
*stmts = new_stmts;
}
}

/// <https://github.com/google/closure-compiler/blob/master/test/com/google/javascript/jscomp/CollapseVariableDeclarations.java>
#[cfg(test)]
mod test {
use oxc_allocator::Allocator;

use crate::{tester, CompressOptions};

fn test(source_text: &str, expected: &str) {
let allocator = Allocator::default();
let mut pass = super::CollapseVariableDeclarations::new(CompressOptions::default());
tester::test(&allocator, source_text, expected, &mut pass);
}

fn test_same(source_text: &str) {
test(source_text, source_text);
}

#[test]
fn cjs() {
// Do not join `require` calls for cjs-module-lexer.
test_same(
"
Object.defineProperty(exports, '__esModule', { value: true });
var compilerDom = require('@vue/compiler-dom');
var runtimeDom = require('@vue/runtime-dom');
var shared = require('@vue/shared');
",
);
}
}
2 changes: 1 addition & 1 deletion crates/oxc_minifier/src/ast_passes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl<'a> NodeUtil for TraverseCtx<'a> {
}
}

pub trait CompressorPass<'a> {
pub trait CompressorPass<'a>: Traverse<'a> {
fn build(&mut self, program: &mut Program<'a>, ctx: &mut TraverseCtx<'a>)
where
Self: Traverse<'a>,
Expand Down
Loading

0 comments on commit 943bd76

Please sign in to comment.