Add test cases for static blocks to verify vars initially defined in static blocks are not in global namespace and check if adding property to a global object in a class static block is a global name
@@ -739,6 +739,28 @@ public final class GlobalNamespaceTest {
assertThat(cDotX.getParent()).isEqualTo(c);
}
+ @Test
+ public void testLocalVarsDefinedinStaticBlocks() {
+ GlobalNamespace namespace = parse("class C{ static{ var x; }}");
+ assertThat(namespace.getSlot("x")).isNull();
+ }
+
+ @Test
+ public void testAddPropertytoGlobalObjectinClassStaticBlock() {
+ GlobalNamespace namespace = parse("const a = {}; class C{ static { a.b = 1;}}");
+
+ Name a = namespace.getSlot("a");
+
+ assertThat(a.getGlobalSets()).isEqualTo(1);
+ assertThat(a.getTotalSets()).isEqualTo(1);
+
+ Name ab = namespace.getSlot("a.b");
+
+ assertThat(ab.getParent()).isEqualTo(a);
+ assertThat(ab.getGlobalSets()).isEqualTo(0);
+ assertThat(ab.getLocalSets()).isEqualTo(1);
+ }
+
@Test
public void testDirectGets() {
// None of the symbol uses here should be considered aliasing gets.
