Add tests to shows current behavior of var replacement in CoalesceVariableNames for static blocks
@@ -371,6 +371,55 @@ public final class CoalesceVariableNamesTest extends CompilerTestCase {
inFunction("function x() {} var y = 1; y; x = 1; x");
}
+ @Test
+ public void testCoalesceVarinStaticBlock() {
+ // TODO(b/235871861): Wrong replacement of var names.
+ test(
+ lines(
+ "function foo() {",
+ " var x = 0;",
+ " var y = 2;",
+ " const C = class{",
+ " static{",
+ " print(x);",
+ " }",
+ " }",
+ "}"),
+ lines(
+ "function foo() {",
+ " var x = 0;",
+ " x = 2;",
+ " x = class{",
+ " static{",
+ " print(x);",
+ " }",
+ " }",
+ "}"));
+
+ // test var replacment for inner functions as comparison for class static blocks
+ test(
+ lines(
+ "function foo() {",
+ " var x = 0;",
+ " var y = 2;",
+ " const C = class {",
+ " function(){",
+ " print(x);",
+ " }",
+ " }",
+ "}"),
+ lines(
+ "function foo() {",
+ " var x = 0;",
+ " var y = 2;",
+ " y = class {",
+ " function(){",
+ " print(x);",
+ " }",
+ " }",
+ "}"));
+ }
+
@Test
public void testBug65688660() {
test(
@@ -996,7 +1045,8 @@ public final class CoalesceVariableNamesTest extends CompilerTestCase {
@Test
public void testUsePseudoNames() {
usePseudoName = true;
- inFunction("var x = 0; print(x ); var y = 1; print( y)",
+ inFunction(
+ "var x = 0; print(x ); var y = 1; print( y)",
"var x_y = 0; print(x_y); x_y = 1; print(x_y)");
inFunction(
