Skip to content

Commit 43fc6f2

Browse files
Closure Teamcopybara-github
authored andcommitted
Add test-case showing current behavior of code referenced from public field initializers incorrectly being removed.
PiperOrigin-RevId: 789422018
1 parent 37bd1f5 commit 43fc6f2

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

test/com/google/javascript/jscomp/RemoveUnusedCodeClassPropertiesTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,4 +1072,34 @@ class C {
10721072
}
10731073
""");
10741074
}
1075+
1076+
@Test
1077+
public void testClassReferencedInFieldInitializer() {
1078+
this.keepLocals = false;
1079+
this.keepGlobals = false;
1080+
1081+
test(
1082+
"""
1083+
class One {
1084+
field = 1;
1085+
}
1086+
class Two {
1087+
field = new One();
1088+
}
1089+
const two = new Two();
1090+
alert(two);
1091+
alert(two.field);
1092+
alert(two.field.field);
1093+
""",
1094+
"""
1095+
// Note: class One is errantly removed here.
1096+
class Two {
1097+
field = new One();
1098+
}
1099+
const two = new Two();
1100+
alert(two);
1101+
alert(two.field);
1102+
alert(two.field.field);
1103+
""");
1104+
}
10751105
}

0 commit comments

Comments
 (0)