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
10 changes: 4 additions & 6 deletions crates/oxc_minifier/src/peephole/convert_to_dotted_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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() {}};");
Expand All @@ -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
Expand Down Expand Up @@ -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} = {};");
}
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_minifier/src/peephole/fold_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
42 changes: 17 additions & 25 deletions crates/oxc_minifier/src/peephole/minimize_conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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 } }");
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 0 additions & 2 deletions crates/oxc_minifier/src/peephole/remove_dead_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,6 @@ impl<'a, 'b> PeepholeOptimizations {
) -> Option<Statement<'a>> {
// 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;
Expand Down
3 changes: 0 additions & 3 deletions crates/oxc_minifier/src/peephole/replace_known_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,6 @@ mod test {
}

#[test]
#[ignore]
fn test_fold_math_functions_bug() {
test_same("Math[0]()");
}
Expand Down Expand Up @@ -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)");
}
Expand Down
48 changes: 9 additions & 39 deletions crates/oxc_minifier/src/peephole/substitute_alternate_syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);");
Expand All @@ -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]
Expand Down Expand Up @@ -1452,7 +1423,6 @@ mod test {
}

#[test]
#[ignore]
fn nullish_coalesce() {
test("a ?? (b ?? c);", "(a ?? b) ?? c");
}
Expand Down
Loading