Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions crates/oxc_minifier/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,16 @@ use oxc_span::SourceType;

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));
let first = run(source_text, source_type, Some(options));

let expected = run(expected, source_type, None);
assert_eq!(result, expected, "\nfor source\n{source_text}\nexpect\n{expected}\ngot\n{result}");
assert_eq!(first, expected, "\nfor source\n{source_text}\nexpect\n{expected}\ngot\n{first}");

let second = run(&first, source_type, Some(options));
assert_eq!(
first, second,
"\nidempotency for source\n{source_text}\ngot\n{first}\nthen\n{second}"
);
}

pub(crate) fn run(
Expand Down
30 changes: 0 additions & 30 deletions crates/oxc_minifier/tests/peephole/esbuild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2380,33 +2380,3 @@ fn test_ignored() {
test("using x = null, y = z", "using x = null, y = z;");
test("using x = z, y = undefined", "using x = z, y = void 0;");
}

#[test]
#[ignore]
fn js_printer_test() {
test("(1 ? eval : 2)(x)", "(0, eval)(x);");
test("(1 ? eval : 2)?.(x)", "eval?.(x);");
test("let x = '\n'", "let x = ``;");
test("let x = ``", "let x = ``;");
test("let x = '\n${}'", "let x = '\n${}';");
test("let x = `\\${}`", "let x = '\n${}';");
test("let x = `\\${}${y}\\${}`", "let x = `\\${}${y}\\${}`;");
test("true ** 2", "(!0) ** 2;");
test("false ** 2", "(!1) ** 2;");
test("x = '\n'", "x = ``;");
test("x = {'\n': 0}", "x = { '\n': 0 };");
test("x = class{'\n' = 0}", "x = class { '\n' = 0;};");
test("class Foo{'\n' = 0}", "class Foo { '\n' = 0;}");
test("x = Infinity", "x = 1 / 0;");
test("x = -Infinity", "x = -1 / 0;");
test("x = (Infinity).toString", "x = (1 / 0).toString;");
test("x = (-Infinity).toString", "x = (-1 / 0).toString;");
test("x = Infinity ** 2", "x = (1 / 0) ** 2;");
test("x = (-Infinity) ** 2", "x = (-1 / 0) ** 2;");
test("x = Infinity * y", "x = 1 / 0 * y;");
test("x = Infinity / y", "x = 1 / 0 / y;");
test("x = y * Infinity", "x = y * (1 / 0);");
test("x = y / Infinity", "x = y / (1 / 0);");
test("throw Infinity", "throw 1 / 0;");
test("x = (0, /*a*/ (0, /*b*/ (0, /*c*/ 1 == 2) + 3) * 4)", "x = /*a*//*b*/(/*c*/!1 + 3) * 4;");
}
14 changes: 2 additions & 12 deletions crates/oxc_minifier/tests/peephole/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ mod dead_code_elimination;
mod esbuild;

use oxc_minifier::CompressOptions;
use oxc_span::SourceType;

fn test(source_text: &str, expected: &str) {
let options = CompressOptions::default();
Expand All @@ -13,15 +12,6 @@ fn test_same(source_text: &str) {
test(source_text, source_text);
}

fn test_idempotent(source: &str, expected: &str) {
let expected = crate::run(expected, SourceType::default(), None);
let first = crate::run(source, SourceType::default(), Some(CompressOptions::default()));
let second = crate::run(&first, SourceType::default(), Some(CompressOptions::default()));

assert_eq!(second, expected, "\nfor source\n{source}\nexpect\n{expected}\ngot\n{second}");
assert_eq!(first, second);
}

// Oxc Integration Tests

#[test]
Expand All @@ -43,7 +33,7 @@ fn integration() {
// }",
// );

test_idempotent(
test(
"require('./index.js')(function (e, os) {
if (e) return console.log(e)
return console.log(JSON.stringify(os))
Expand All @@ -53,7 +43,7 @@ fn integration() {
});"#,
);

test_idempotent(
test(
"if (!(foo instanceof Var) || open) {
arg0 = null;
} else if (que || !(foo && bar)) {
Expand Down
Loading