diff --git a/crates/oxc_minifier/src/peephole/minimize_conditions.rs b/crates/oxc_minifier/src/peephole/minimize_conditions.rs index efb8ae4f6f4dcf..9512a2d5af6e80 100644 --- a/crates/oxc_minifier/src/peephole/minimize_conditions.rs +++ b/crates/oxc_minifier/src/peephole/minimize_conditions.rs @@ -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;}"); @@ -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] @@ -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)"); @@ -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!( @@ -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 }" ), ); } @@ -2100,8 +2076,8 @@ mod test { ); } + /// https://blickly.github.io/closure-compiler-issues/#925 #[test] - #[ignore] fn test_issue925() { test( concat!( @@ -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] @@ -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(