Skip to content

Commit

Permalink
Fix optimization tests
Browse files Browse the repository at this point in the history
  • Loading branch information
levi-nz committed May 12, 2024
1 parent 52869c4 commit aa42961
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions crates/swc_ecma_transforms_optimization/src/simplify/expr/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -974,15 +974,15 @@ fn test_fold_comparison4() {

#[test]
fn test_fold_get_elem1() {
fold("x = [,10][0]", "x = void 0;");
fold("x = [10, 20][0]", "x = 10;");
fold("x = [10, 20][1]", "x = 20;");
fold("x = [,10][0]", "x = (0, void 0);");
fold("x = [10, 20][0]", "x = (0, 10);");
fold("x = [10, 20][1]", "x = (0, 20);");

// fold("x = [10, 20][-1]", "x = void 0;");
// fold("x = [10, 20][2]", "x = void 0;");

fold("x = [foo(), 0][1]", "x = (foo(), 0);");
fold("x = [0, foo()][1]", "x = foo();");
fold("x = [0, foo()][1]", "x = (0, foo());");
// fold("x = [0, foo()][0]", "x = (foo(), 0)");
fold_same("for([1][0] in {});");
}
Expand All @@ -1005,11 +1005,11 @@ fn test_fold_get_elem2_2() {

#[test]
fn test_fold_array_lit_spread_get_elem() {
fold("x = [...[0 ]][0]", "x = 0;");
fold("x = [0, 1, ...[2, 3, 4]][3]", "x = 3;");
fold("x = [...[0, 1], 2, ...[3, 4]][3]", "x = 3;");
fold("x = [...[...[0, 1], 2, 3], 4][0]", "x = 0;");
fold("x = [...[...[0, 1], 2, 3], 4][3]", "x = 3;");
fold("x = [...[0 ]][0]", "x = (0, 0);");
fold("x = [0, 1, ...[2, 3, 4]][3]", "x = (0, 3);");
fold("x = [...[0, 1], 2, ...[3, 4]][3]", "x = (0, 3);");
fold("x = [...[...[0, 1], 2, 3], 4][0]", "x = (0, 0);");
fold("x = [...[...[0, 1], 2, 3], 4][3]", "x = (0, 3);");
// fold("x = [...[]][100]", "x = void 0;");
// fold("x = [...[0]][100]", "x = void 0;");
}
Expand Down Expand Up @@ -1594,7 +1594,7 @@ fn test_issue8747() {

// Index with an expression.
fold("'a'[0 + []]", "\"a\";");
fold("[1][0 + []]", "1");
fold("[1][0 + []]", "0, 1;");

// Don't replace if side effects exist.
fold_same("[f(), f()][0]");
Expand Down

0 comments on commit aa42961

Please sign in to comment.