Verify that logical assignment makes a variable not be inferred const in InferConsts.
@@ -63,6 +63,7 @@ public final class InferConstsTest extends CompilerTestCase {
assertConsts("var x = 3, y = 4;", inferred("x", "y"));
assertConsts("var x = 3, y;", inferred("x"), notInferred("y"));
assertConsts("var x = 3; function f(){x;}", inferred("x"));
+ assertConsts("var x = 3, y; y ||= 4;", inferred("x"), notInferred("y"));
}
@Test
@@ -73,6 +74,7 @@ public final class InferConstsTest extends CompilerTestCase {
assertConsts("let x = 3; let y = 4;", inferred("x", "y"));
assertConsts("let x = 3, y = 4; x++;", inferred("y"));
assertConsts("let x = 3; function f(){let x = 4;}", inferred("x"));
+ assertConsts("let x; x ||= 0;", notInferred("x"));
assertConsts("/** @const */ let x;", declared("x"), notInferred("x"));
assertConsts("const x = 1;", declared("x"), inferred("x"));
}
@@ -86,6 +88,7 @@ public final class InferConstsTest extends CompilerTestCase {
assertConsts("function f() { Foo; } class Foo {}", inferred("Foo"));
assertConsts("function f() { g; } function g() {}", inferred("g"));
assertConsts("function f([y = () => x], x) {}", inferred("x"));
+ assertConsts("function f() { x ||= 1; } let x = 0;", notInferred("x"));
}
@Test
@@ -97,6 +100,8 @@ public final class InferConstsTest extends CompilerTestCase {
assertNotConsts("let x = 3; x = 2;", "x", "y");
assertNotConsts("/** @const */let x; let y;", "y");
assertNotConsts("let x = 3; function f() {let x = 4; x++;} x++;", "x");
+ assertNotConsts("var x = 2; x ||= 1;", "x");
+ assertNotConsts("let x = 3; x ||= 1;", "x");
}
@Test
