Skip to content

Commit

Permalink
test(minifier): cleanup some tests in minimize_conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Jan 27, 2025
1 parent 0fcff20 commit d88552f
Showing 1 changed file with 13 additions and 39 deletions.
52 changes: 13 additions & 39 deletions crates/oxc_minifier/src/peephole/minimize_conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1456,15 +1456,13 @@ mod test {
}

#[test]
#[ignore]
fn test_fold_logical_op_string_compare() {
// side-effects
// There is two way to parse two &&'s and both are correct.
test("if (foo() && false) z()", "(foo(), 0) && z()");
test("if (foo() && false) z()", "foo() && !1");
}

#[test]
#[ignore]
fn test_fold_not() {
test("while(!(x==y)){a=b;}", "while(x!=y){a=b;}");
test("while(!(x!=y)){a=b;}", "while(x==y){a=b;}");
Expand Down Expand Up @@ -1635,10 +1633,9 @@ mod test {
}

#[test]
#[ignore]
fn test_minimize_comma() {
test("while(!(inc(), test())) foo();", "while(inc(), !test()) foo();");
test("(inc(), !test()) ? foo() : bar()", "(inc(), test()) ? bar() : foo()");
test("while(!(inc(), test())) foo();", "for(;inc(), !test();) foo();");
test("(inc(), !test()) ? foo() : bar()", "inc(), test() ? bar() : foo()");
}

#[test]
Expand Down Expand Up @@ -1734,7 +1731,6 @@ mod test {
}

#[test]
#[ignore]
fn test_fold_if_with_lower_operators_inside() {
test("if (x + (y=5)) z && (w,z);", "x + (y=5) && (z && (w,z))");
test("if (!(x+(y=5))) z && (w,z);", "x + (y=5) || z && (w,z)");
Expand Down Expand Up @@ -2015,35 +2011,15 @@ mod test {
}

#[test]
#[ignore]
fn test_nested_if_combine() {
test("if(x)if(y){while(1){}}", "if(x&&y){while(1){}}");
test("if(x||z)if(y){while(1){}}", "if((x||z)&&y){while(1){}}");
test("if(x)if(y||z){while(1){}}", "if((x)&&(y||z)){while(1){}}");
test_same("if(x||z)if(y||z){while(1){}}");
test("if(x)if(y){if(z){while(1){}}}", "if(x&&(y&&z)){while(1){}}");
test("if(x)if(y){for(;;);}", "if(x&&y) for(;;);");
test("if(x||z)if(y){for(;;);}", "if((x||z)&&y) for(;;);");
test("if(x)if(y||z){for(;;);}", "if((x)&&(y||z)) for(;;);");
test("if(x||z)if(y||z){for(;;);}", "if((x||z)&&(y||z)) for(;;);"); // TODO: `if(x||z)if(y||z)for(;;);` is shorter
test("if(x)if(y){if(z){for(;;);}}", "if(x&&(y&&z)) for(;;);");
}

// See: http://blickly.github.io/closure-compiler-issues/#291
#[test]
#[ignore]
fn test_issue291() {
test("if (true) { f.onchange(); }", "if (1) f.onchange();");
test_same("if (f) { f.onchange(); }");
test_same("if (f) { f.bar(); } else { f.onchange(); }");
test("if (f) { f.bonchange(); }", "f && f.bonchange();");
test_same("if (f) { f['x'](); }");

// optional versions
test("if (true) { f?.onchange(); }", "if (1) f?.onchange();");
test_same("if (f) { f?.onchange(); }");
test_same("if (f) { f?.bar(); } else { f?.onchange(); }");
test("if (f) { f?.bonchange(); }", "f && f?.bonchange();");
test_same("if (f) { f?.['x'](); }");
}

#[test]
#[ignore]
fn test_remove_else_cause() {
test(
concat!(
Expand All @@ -2053,10 +2029,10 @@ mod test {
" else if(x) return 3 }"
),
concat!(
"function f() {",
"function f() {", //
" if(x) return 1;",
"{ if(x) return 2;",
"{ if(x) return 3 } } }"
" if(x) return 2;",
" if(x) return 3 }"
),
);
}
Expand Down Expand Up @@ -2100,8 +2076,8 @@ mod test {
);
}

/// https://blickly.github.io/closure-compiler-issues/#925
#[test]
#[ignore]
fn test_issue925() {
test(
concat!(
Expand Down Expand Up @@ -2131,8 +2107,7 @@ mod test {
);

test("if (x++) { x += 2 } else { x += 3 }", "x++ ? x += 2 : x += 3");

test("if (x++) { x = x + 2 } else { x = x + 3 }", "x = x++ ? x + 2 : x + 3");
test("if (x++) { x = x + 2 } else { x = x + 3 }", "x++ ? x += 2 : x += 3");
}

#[test]
Expand Down Expand Up @@ -2242,7 +2217,6 @@ mod test {
}

#[test]
#[ignore]
fn test_minimize_if_with_new_target_condition() {
// Related to https://github.com/google/closure-compiler/issues/3097
test(
Expand Down

0 comments on commit d88552f

Please sign in to comment.