Skip to content

Commit

Permalink
Adds tests for DeadAssignmentsElimination covering destructuring, r…
Browse files Browse the repository at this point in the history
…est, and spread.

Most of these tests are just confirming bad behaviour, but the incorrectness isn't dangerous.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=235835564
  • Loading branch information
nreid260 authored and brad4d committed Feb 27, 2019
1 parent 40f6700 commit ed691df
Showing 1 changed file with 91 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,97 @@ public void testObjectLiteralsComputedProperties() {
inFunction("let a; a = 2; let obj = {[a]: 3}; obj");
}

@Test
public void testSpread_consideredRead() {
inFunction(
lines(
"var a;", //
"a = [];", //
"[...a];"));

inFunction(
lines(
"var a;", //
"a = {};", //
"({...a});"));
}

@Test
public void testRest_notConsideredWrite() {
// TODO(b/126441776): The initial writes are dead. The pass should rewrite to the commented
// code.

inFunction(
lines(
"var a = 9;", //
"[...a] = itr;",
"return a;")
/** , lines( "var a;", // "[...a] = itr;", "return a;") */
);

inFunction(
lines(
"var a = 9;", //
"({...a} = obj);",
"return a;")
/** , lines( "var a;", // "({...a} = obj);", "return a;") */
);
}

@Test
public void testDestructuring_notConsideredWrite() {
// TODO(b/126441776): The initial writes are dead. The pass should rewrite to the commented
// code.

inFunction(
lines(
"var a = 9;", //
"[a] = itr;",
"return a;")
/** , lines( "var a;", // "[a] = itr;", "return a;") */
);

inFunction(
lines(
"var a = 9;", //
"({a} = obj);",
"return a;")
/** , lines( "var a;", // "({a} = obj);", "return a;") */
);
}

@Test
public void testRest_isNotRemovable() {
// TODO(b/126441776): Elimination is possible here under getter/setter assumptions. Determine if
// this is the correct behaviour.

inFunction(
lines(
"var a;", //
"[...a] = itr;"));

inFunction(
lines(
"var a;", //
"({...a} = obj);"));
}

@Test
public void testDestructuring_isNotRemovable() {
// TODO(b/126441776): Elimination is possible here under getter/setter assumptions. Determine if
// this is the correct behaviour.

inFunction(
lines(
"var a;", //
"[a] = itr;"));

inFunction(
lines(
"var a;", //
"({a} = obj);"));
}

@Test
public void testLet() {
inFunction("let a; a = 2;",
Expand Down

0 comments on commit ed691df

Please sign in to comment.