Skip to content

Commit

Permalink
refactor(minifier): move tests and files around
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Aug 7, 2024
1 parent c296373 commit 17602db
Show file tree
Hide file tree
Showing 26 changed files with 44 additions and 1,120 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion crates/oxc_minifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,4 @@ num-traits = { workspace = true }
oxc_parser = { workspace = true }

insta = { workspace = true }
walkdir = { workspace = true }
pico-args = { workspace = true }
4 changes: 0 additions & 4 deletions crates/oxc_minifier/src/ast_passes/mod.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
#![allow(clippy::wildcard_imports)]

mod collapse;
mod fold_constants;
mod remove_dead_code;
mod remove_syntax;
mod replace_global_defines;
mod substitute_alternate_syntax;

pub use collapse::Collapse;
pub use fold_constants::FoldConstants;
pub use remove_dead_code::RemoveDeadCode;
pub use remove_syntax::RemoveSyntax;
pub use replace_global_defines::{ReplaceGlobalDefines, ReplaceGlobalDefinesConfig};
pub use substitute_alternate_syntax::SubstituteAlternateSyntax;
1 change: 0 additions & 1 deletion crates/oxc_minifier/src/compressor.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use oxc_allocator::Allocator;
#[allow(clippy::wildcard_imports)]
use oxc_ast::{ast::*, AstBuilder};

use crate::{
Expand Down
1 change: 0 additions & 1 deletion crates/oxc_minifier/src/keep_var.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#[allow(clippy::wildcard_imports)]
use oxc_ast::{ast::*, syntax_directed_operations::BoundNames, AstBuilder, Visit};
use oxc_span::{Atom, Span, SPAN};

Expand Down
6 changes: 5 additions & 1 deletion crates/oxc_minifier/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#![allow(clippy::wildcard_imports)]

//! ECMAScript Minifier
mod ast_passes;
mod ast_util;
mod compressor;
mod keep_var;
mod options;
mod plugins;
mod tri;
mod ty;

Expand All @@ -13,9 +16,10 @@ use oxc_ast::ast::Program;
use oxc_mangler::{Mangler, ManglerBuilder};

pub use crate::{
ast_passes::{RemoveDeadCode, RemoveSyntax, ReplaceGlobalDefines, ReplaceGlobalDefinesConfig},
ast_passes::{RemoveDeadCode, RemoveSyntax},
compressor::Compressor,
options::CompressOptions,
plugins::{ReplaceGlobalDefines, ReplaceGlobalDefinesConfig},
};

#[derive(Debug, Clone, Copy)]
Expand Down
3 changes: 3 additions & 0 deletions crates/oxc_minifier/src/plugins/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod replace_global_defines;

pub use replace_global_defines::{ReplaceGlobalDefines, ReplaceGlobalDefinesConfig};
1 change: 0 additions & 1 deletion crates/oxc_minifier/src/ty.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#[allow(clippy::wildcard_imports)]
use oxc_ast::ast::*;
use oxc_syntax::operator::{BinaryOperator, UnaryOperator};

Expand Down
1 change: 0 additions & 1 deletion crates/oxc_minifier/tests/.gitignore

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::CompressOptions;
use oxc_minifier::CompressOptions;

fn test(source_text: &str, expected: &str) {
let options = CompressOptions::all_true();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,38 @@
//! <https://github.com/google/closure-compiler/blob/master/test/com/google/javascript/jscomp/PeepholeFoldConstantsTest.java>
use oxc_minifier::CompressOptions;

use crate::test_with_options;
use crate::CompressOptions;

fn test(source_text: &str, expected: &str) {
let options = CompressOptions { fold_constants: true, ..CompressOptions::all_false() };
test_with_options(source_text, expected, options);
let options = CompressOptions {
remove_syntax: true,
fold_constants: true,
..CompressOptions::all_false()
};
crate::test(source_text, expected, options);
}

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

// Oxc

#[test]
fn cjs() {
// Export is undefined when `enumerable` is "!0".
// https://github.com/nodejs/cjs-module-lexer/issues/64
test_same(
"Object.defineProperty(exports, 'ConnectableObservable', {
enumerable: true,
get: function() {
return ConnectableObservable_1.ConnectableObservable;
}
});",
);
}

// Google Closure Compiler

#[test]
fn undefined_comparison1() {
test("undefined == undefined", "true");
Expand Down Expand Up @@ -277,6 +297,7 @@ fn test_string_boolean_comparison() {
}

#[test]
#[ignore]
fn test_string_string_comparison() {
test("'a' < 'b'", "true");
test("'a' <= 'b'", "true");
Expand Down Expand Up @@ -450,6 +471,7 @@ fn test_nan_comparison() {
}

#[test]
#[ignore]
fn js_typeof() {
test("x = typeof 1", "x='number'");
test("x = typeof 'foo'", "x='string'");
Expand All @@ -469,6 +491,7 @@ fn js_typeof() {
}

#[test]
#[ignore]
fn unary_ops() {
// TODO: need to port
// These cases are handled by PeepholeRemoveDeadCode in closure-compiler.
Expand Down Expand Up @@ -517,6 +540,7 @@ fn unary_with_big_int() {
}

#[test]
#[ignore]
fn test_unary_ops_string_compare() {
test_same("a = -1");
test("a = ~0", "a = -1");
Expand Down Expand Up @@ -600,6 +624,7 @@ fn test_fold_logical_op2() {
}

#[test]
#[ignore]
fn test_fold_void() {
test_same("void 0");
test("void 1", "void 0");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod fold_conditions;
// mod fold_constants;
mod fold_constants;
mod remove_dead_code;
mod reorder_constant_expression;
mod substitute_alternate_syntax;
10 changes: 2 additions & 8 deletions crates/oxc_minifier/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
mod closure;
mod ast_passes;
mod mangler;
mod oxc;
// mod tdewolff;
// mod terser;
mod plugins;

use oxc_allocator::Allocator;
use oxc_codegen::{CodeGenerator, CodegenOptions};
use oxc_minifier::{CompressOptions, Compressor};
use oxc_parser::Parser;
use oxc_span::SourceType;

pub(crate) fn test_same(source_text: &str, options: CompressOptions) {
test(source_text, source_text, options);
}

pub(crate) fn test(source_text: &str, expected: &str, options: CompressOptions) {
let source_type = SourceType::default();
let result = run(source_text, source_type, Some(options));
Expand Down
20 changes: 0 additions & 20 deletions crates/oxc_minifier/tests/oxc/booleans.rs

This file was deleted.

37 changes: 0 additions & 37 deletions crates/oxc_minifier/tests/oxc/code_removal.rs

This file was deleted.

30 changes: 0 additions & 30 deletions crates/oxc_minifier/tests/oxc/folding.rs

This file was deleted.

5 changes: 0 additions & 5 deletions crates/oxc_minifier/tests/oxc/mod.rs

This file was deleted.

1 change: 1 addition & 0 deletions crates/oxc_minifier/tests/plugins/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod replace_global_defines;
Loading

0 comments on commit 17602db

Please sign in to comment.