diff --git a/crates/oxc_minifier/src/peephole/convert_to_dotted_properties.rs b/crates/oxc_minifier/src/peephole/convert_to_dotted_properties.rs index c12e58b4e696b..96735dee529b2 100644 --- a/crates/oxc_minifier/src/peephole/convert_to_dotted_properties.rs +++ b/crates/oxc_minifier/src/peephole/convert_to_dotted_properties.rs @@ -127,7 +127,6 @@ mod test { } #[test] - #[ignore] fn test_convert_to_dotted_properties_computed_property_or_field() { test("const test1 = {['prop1']:87};", "const test1 = {prop1:87};"); test( @@ -146,7 +145,7 @@ mod test { test("class C {'x' = 0; ['y'] = 1;}", "class C { x= 0;y= 1;}"); test("class C {'m'() {} }", "class C {m() {}}"); - test("const o = {'b'() {}, ['c']() {}};", "const o = {b: function() {}, c:function(){}};"); + test("const o = {'b'() {}, ['c']() {}};", "const o = {b() {}, c(){}};"); test("o = {['x']: () => this};", "o = {x: () => this};"); test("const o = {get ['d']() {}};", "const o = {get d() {}};"); @@ -161,7 +160,7 @@ mod test { ); test( "const o = {['a']: 1,'b'() {}, ['c']() {}, get ['d']() {}, set ['e'](x) {}};", - "const o = {a: 1,b: function() {}, c: function() {}, get d() {}, set e(x) {}};", + "const o = {a: 1,b() {}, c() {}, get d() {}, set e(x) {}};", ); // test static keyword @@ -215,14 +214,13 @@ mod test { ); test_same("const o = {[fn()]: 0}"); - test_same("const test1 = {[0]:87};"); - test_same("const test1 = {['default']:87};"); + test("const test1 = {[0]:87};", "const test1 = {0:87}"); + test("const test1 = {['default']:87};", "const test1 = {default:87};"); test_same("class C { ['constructor']() {} }"); test_same("class C { ['constructor'] = 0 }"); } #[test] - #[ignore] fn test_convert_to_dotted_properties_computed_property_with_default_value() { test("const {['o']: o = 0} = {};", "const {o:o = 0} = {};"); } diff --git a/crates/oxc_minifier/src/peephole/fold_constants.rs b/crates/oxc_minifier/src/peephole/fold_constants.rs index 594e7016dda9b..e3e79cf4e0122 100644 --- a/crates/oxc_minifier/src/peephole/fold_constants.rs +++ b/crates/oxc_minifier/src/peephole/fold_constants.rs @@ -1887,8 +1887,8 @@ mod test { fold("1n > -Infinity", "!0"); // null is interpreted as 0 when comparing with bigint - // test("1n < null", "!1"); - // test("1n > null", "!0"); + fold("1n < null", "!1"); + fold("1n > null", "!0"); } #[test] diff --git a/crates/oxc_minifier/src/peephole/minimize_conditions.rs b/crates/oxc_minifier/src/peephole/minimize_conditions.rs index 508a1a35926b7..0548030f65410 100644 --- a/crates/oxc_minifier/src/peephole/minimize_conditions.rs +++ b/crates/oxc_minifier/src/peephole/minimize_conditions.rs @@ -1391,8 +1391,6 @@ mod test { #[test] #[ignore] fn test_remove_duplicate_statements() { - // TODO(bradfordcsmith): Stop normalizing the expected output or document why it is necessary. - // enableNormalizeExpectedOutput(); test("if (a) { x = 1; x++ } else { x = 2; x++ }", "x=(a) ? 1 : 2; x++"); test( concat!( @@ -1532,26 +1530,26 @@ mod test { } #[test] - #[ignore] fn test_minimize_while_condition() { // This test uses constant folding logic, so is only here for completeness. - test("while(!!true) foo()", "while(1) foo()"); + test("while(!!true) foo()", "for(;;) foo()"); // These test tryMinimizeCondition - test("while(!!x) foo()", "while(x) foo()"); - test("while(!(!x&&!y)) foo()", "while(x||y) foo()"); - test("while(x||!!y) foo()", "while(x||y) foo()"); - test("while(!(!!x&&y)) foo()", "while(!x||!y) foo()"); - test("while(!(!x&&y)) foo()", "while(x||!y) foo()"); - test("while(!(x||!y)) foo()", "while(!x&&y) foo()"); - test("while(!(x||y)) foo()", "while(!x&&!y) foo()"); - test("while(!(!x||y-z)) foo()", "while(x&&!(y-z)) foo()"); - test("while(!(!(x/y)||z+w)) foo()", "while(x/y&&!(z+w)) foo()"); - test_same("while(!(x+y||z)) foo()"); - test_same("while(!(x&&y*z)) foo()"); - test("while(!(!!x&&y)) foo()", "while(!x||!y) foo()"); - test("while(x&&!0) foo()", "while(x) foo()"); - test("while(x||!1) foo()", "while(x) foo()"); - test("while(!((x,y)&&z)) foo()", "while((x,!y)||!z) foo()"); + test("while(!!x) foo()", "for(;x;) foo()"); + // test("while(!(!x&&!y)) foo()", "for(;x||y;) foo()"); + test("while(x||!!y) foo()", "for(;x||y;) foo()"); + // TODO + // test("while(!(!!x&&y)) foo()", "for(;!x||!y;) foo()"); + // test("while(!(!x&&y)) foo()", "for(;x||!y;) foo()"); + // test("while(!(x||!y)) foo()", "for(;!x&&y;) foo()"); + // test("while(!(x||y)) foo()", "for(;!x&&!y;) foo()"); + // test("while(!(!x||y-z)) foo()", "for(;x&&!(y-z;)) foo()"); + // test("while(!(!(x/y)||z+w)) foo()", "for(;x/y&&!(z+w;)) foo()"); + // test("while(!(x+y||z)) foo()", "for(;!(x+y||z);) foo()"); + // test("while(!(x&&y*z)) foo()", "for(;!(x+y||z);) foo()"); + // test("while(!(!!x&&y)) foo()", "for(;!x||!y;) foo()"); + // test("while(x&&!0) foo()", "for(;x;) foo()"); + // test("while(x||!1) foo()", "for(;x;) foo()"); + // test("while(!((x,y)&&z)) foo()", "for(;(x,!y)||!z;) foo()"); } #[test] @@ -1756,9 +1754,6 @@ mod test { #[test] #[ignore] fn test_substitute_return() { - // TODO(bradfordcsmith): Stop normalizing the expected output or document why it is necessary. - // enableNormalizeExpectedOutput(); - test("function f() { while(x) { return }}", "function f() { while(x) { break }}"); test_same("function f() { while(x) { return 5 } }"); @@ -1856,9 +1851,6 @@ mod test { #[test] #[ignore] fn test_substitute_break_for_throw() { - // TODO(bradfordcsmith): Stop normalizing the expected output or document why it is necessary. - // enableNormalizeExpectedOutput(); - test_same("function f() { while(x) { throw Error }}"); test( diff --git a/crates/oxc_minifier/src/peephole/remove_dead_code.rs b/crates/oxc_minifier/src/peephole/remove_dead_code.rs index ca01b23dd0ee3..6d3fa63c37cf8 100644 --- a/crates/oxc_minifier/src/peephole/remove_dead_code.rs +++ b/crates/oxc_minifier/src/peephole/remove_dead_code.rs @@ -309,8 +309,6 @@ impl<'a, 'b> PeepholeOptimizations { ) -> Option> { // We need to check if it is in arrow function with `expression: true`. // This is the only scenario where we can't remove it even if `ExpressionStatement`. - // TODO find a better way to handle this. - if let Ancestor::ArrowFunctionExpressionBody(body) = ctx.ancestry.ancestor(1) { if *body.expression() { return None; diff --git a/crates/oxc_minifier/src/peephole/replace_known_methods.rs b/crates/oxc_minifier/src/peephole/replace_known_methods.rs index 4fb7259cb2a8a..5f004ff296b2e 100644 --- a/crates/oxc_minifier/src/peephole/replace_known_methods.rs +++ b/crates/oxc_minifier/src/peephole/replace_known_methods.rs @@ -1103,7 +1103,6 @@ mod test { } #[test] - #[ignore] fn test_fold_math_functions_bug() { test_same("Math[0]()"); } @@ -1173,8 +1172,6 @@ mod test { } #[test] - #[ignore] - // @GwtIncompatible // TODO(b/155511629): Enable this test for J2CL fn test_fold_math_functions_fround_j2cl() { test_same("Math.fround(1.2)"); } diff --git a/crates/oxc_minifier/src/peephole/substitute_alternate_syntax.rs b/crates/oxc_minifier/src/peephole/substitute_alternate_syntax.rs index 1204f02537098..4fb3f7f954ddb 100644 --- a/crates/oxc_minifier/src/peephole/substitute_alternate_syntax.rs +++ b/crates/oxc_minifier/src/peephole/substitute_alternate_syntax.rs @@ -1235,7 +1235,6 @@ mod test { #[test] #[ignore] fn test_split_comma_expressions() { - // late = false; // Don't try to split in expressions. test_same("while (foo(), !0) boo()"); test_same("var a = (foo(), !0);"); @@ -1258,60 +1257,32 @@ mod test { } #[test] - #[ignore] fn test_comma1() { - // late = false; - test("1, 2", "1; 2"); - // late = true; - // test_same("1, 2"); + test_same("x, y"); } #[test] - #[ignore] fn test_comma2() { - // late = false; - test("1, a()", "1; a()"); - test("1, a?.()", "1; a?.()"); - - // late = true; - // test_same("1, a()"); - // test_same("1, a?.()"); + test("a, a()", "a, a()"); + test("a, a?.()", "a, a?.()"); } #[test] - #[ignore] fn test_comma3() { - // late = false; - test("1, a(), b()", "1; a(); b()"); - test("1, a?.(), b?.()", "1; a?.(); b?.()"); - - // late = true; - // test_same("1, a(), b()"); - // test_same("1, a?.(), b?.()"); + test("x, a(), b()", "x, a(), b()"); + test("x, a?.(), b?.()", "x, a?.(), b?.()"); } #[test] - #[ignore] fn test_comma4() { - // late = false; - test("a(), b()", "a();b()"); - test("a?.(), b?.()", "a?.();b?.()"); - - // late = true; - // test_same("a(), b()"); - // test_same("a?.(), b?.()"); + test("a(), b()", "a(), b()"); + test("a?.(), b?.()", "a?.(), b?.()"); } #[test] - #[ignore] fn test_comma5() { - // late = false; - test("a(), b(), 1", "a(); b(); 1"); - test("a?.(), b?.(), 1", "a?.(); b?.(); 1"); - - // late = true; - // test_same("a(), b(), 1"); - // test_same("a?.(), b?.(), 1"); + test("a(), b(), 1", "a(), b(), 1"); + test("a?.(), b?.(), 1", "a?.(), b?.(), 1"); } #[test] @@ -1452,7 +1423,6 @@ mod test { } #[test] - #[ignore] fn nullish_coalesce() { test("a ?? (b ?? c);", "(a ?? b) ?? c"); }