File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed
test/com/google/javascript/jscomp Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change @@ -97,6 +97,57 @@ public void testObjectRest_declaration() {
97
97
});
98
98
}
99
99
100
+ @ Test
101
+ public void testClass () {
102
+ testBehavior (
103
+ """
104
+ class Foo {}
105
+ """ ,
106
+ (NodeTraversal t , ReferenceMap rm ) -> {
107
+ if (t .getScope ().isGlobal ()) {
108
+ ReferenceCollection x = rm .getReferences (t .getScope ().getVar ("Foo" ));
109
+
110
+ assertThat (x .isAssignedOnceInLifetime ()).isTrue ();
111
+ assertThat (x .isWellDefined ()).isTrue ();
112
+ assertThat (x ).comparingElementsUsing (IS_DECLARATION ).containsExactly (true ).inOrder ();
113
+ }
114
+ });
115
+ }
116
+
117
+ @ Test
118
+ public void testClass_withPrototype () {
119
+ testBehavior (
120
+ """
121
+ class Foo {}
122
+ Foo.prototype.bar = 1;
123
+ """ ,
124
+ (NodeTraversal t , ReferenceMap rm ) -> {
125
+ if (t .getScope ().isGlobal ()) {
126
+ ReferenceCollection x = rm .getReferences (t .getScope ().getVar ("Foo" ));
127
+
128
+ assertThat (x .isAssignedOnceInLifetime ()).isTrue ();
129
+ assertThat (x .isWellDefined ()).isFalse (); // TODO(b/435019132): Should be true.
130
+ }
131
+ });
132
+ }
133
+
134
+ @ Test
135
+ public void testClass_referencedAfterDeclaration () {
136
+ testBehavior (
137
+ """
138
+ class Foo {}
139
+ const x = Foo;
140
+ """ ,
141
+ (NodeTraversal t , ReferenceMap rm ) -> {
142
+ if (t .getScope ().isGlobal ()) {
143
+ ReferenceCollection x = rm .getReferences (t .getScope ().getVar ("Foo" ));
144
+
145
+ assertThat (x .isAssignedOnceInLifetime ()).isTrue ();
146
+ assertThat (x .isWellDefined ()).isFalse (); // TODO(b/435019132): Should be true.
147
+ }
148
+ });
149
+ }
150
+
100
151
@ Test
101
152
public void testImport1 () {
102
153
testBehavior (
You can’t perform that action at this time.
0 commit comments