Skip to content

Commit

Permalink
Add tests for PeepholeCollectPropertyAssignments covering object an…
Browse files Browse the repository at this point in the history
…d array spread.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=236004637
  • Loading branch information
nreid260 authored and brad4d committed Feb 28, 2019
1 parent 5c82589 commit fa5eceb
Showing 1 changed file with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ public void testArrayOptimization1() {
"var a = [1, 2, 3];");
}

@Test
public void testArray_nonConsecutiveAssignments() {
test(
"var a = []; a[2] = 1; a[0] = 2; a[1] = 3;", //
"var a = [2, 3, 1];");
}

@Test
public void testArrayOptimization2() {
test("var a; a = []; a[0] = 1; a[1] = 2; a[2] = 3;",
Expand Down Expand Up @@ -220,6 +227,22 @@ public void testForwardReference2() {
"var a; a = [1]; a[1] = a;");
}

@Test
public void testArray_usingSpread_diablesOptimization_leadingSpread() {
// TODO(nickreid): A future improvement could generate `var a = [3, ...b, 2];`
testSame("var a = [1, ...b, 2]; a[0] = 3;");
}

@Test
public void testArray_usingSpread_diablesOptimization_withinSpread() {
testSame("var a = [1, ...b, 2]; a[1] = 3;");
}

@Test
public void testArray_usingSpread_diablesOptimization_followingSpread() {
testSame("var a = [1, ...b, 2]; a[2] = 3;");
}

@Test
public void testObjectOptimization1() {
test("var o = {}; o.x = 0; o['y'] = 1; o[2] = 2;",
Expand Down Expand Up @@ -325,6 +348,23 @@ public void testObjectPropertyReassigned4() {
"a.b = x+10;");
}

@Test
public void testObject_usingSpread_diablesOptimization_leadingSpread() {
test(
"var a = {a: 1, ...b, c: 2}; a.a = 3;", //
"var a = {...b, c: 2, a: 3};");
}

@Test
public void testObject_usingSpread_diablesOptimization_withinSpread() {
testSame("var a = {a: 1, ...b, c: 2, b: 3};");
}

@Test
public void testObject_usingSpread_diablesOptimization_followingSpread() {
testSame("var a = {a: 1, ...b, c: 3};");
}

@Test
public void testObjectComputedProp1() {
testSame(
Expand Down

0 comments on commit fa5eceb

Please sign in to comment.