@@ -8,7 +8,7 @@ import espree from "./util/espree.js";
8
8
import { analyze } from "../lib/index.js" ;
9
9
10
10
describe ( "ScopeManager#addGlobals" , ( ) => {
11
- it ( "adds variables to the global scope and closes references from the global scope" , ( ) => {
11
+ it ( "adds variables to the global scope and resolves references from the global scope" , ( ) => {
12
12
const ast = espree ( `
13
13
foo = bar + bar;
14
14
` ) ;
@@ -25,10 +25,13 @@ describe("ScopeManager#addGlobals", () => {
25
25
expect ( globalScope . set . size ) . to . be . equal ( 0 ) ;
26
26
expect ( globalScope . references ) . to . have . length ( 3 ) ;
27
27
expect ( globalScope . references [ 0 ] . identifier . name ) . to . be . equal ( "foo" ) ;
28
+ expect ( globalScope . references [ 0 ] . from ) . to . be . equal ( globalScope ) ;
28
29
expect ( globalScope . references [ 0 ] . resolved ) . to . be . null ;
29
30
expect ( globalScope . references [ 1 ] . identifier . name ) . to . be . equal ( "bar" ) ;
31
+ expect ( globalScope . references [ 1 ] . from ) . to . be . equal ( globalScope ) ;
30
32
expect ( globalScope . references [ 1 ] . resolved ) . to . be . null ;
31
33
expect ( globalScope . references [ 2 ] . identifier . name ) . to . be . equal ( "bar" ) ;
34
+ expect ( globalScope . references [ 2 ] . from ) . to . be . equal ( globalScope ) ;
32
35
expect ( globalScope . references [ 2 ] . resolved ) . to . be . null ;
33
36
expect ( globalScope . references [ 1 ] ) . to . not . be . equal ( globalScope . references [ 2 ] ) ;
34
37
expect ( globalScope . through ) . to . have . length ( 3 ) ;
@@ -37,6 +40,9 @@ describe("ScopeManager#addGlobals", () => {
37
40
expect ( globalScope . through [ 2 ] ) . to . be . equal ( globalScope . references [ 2 ] ) ;
38
41
expect ( globalScope . implicit . variables ) . to . have . length ( 1 ) ;
39
42
expect ( globalScope . implicit . variables [ 0 ] . name ) . to . be . equal ( "foo" ) ;
43
+ expect ( globalScope . implicit . variables [ 0 ] . references ) . to . have . length ( 0 ) ;
44
+ expect ( globalScope . implicit . variables [ 0 ] . defs ) . to . have . length ( 1 ) ;
45
+ expect ( globalScope . implicit . variables [ 0 ] . identifiers ) . to . have . length ( 1 ) ;
40
46
expect ( globalScope . implicit . set . size ) . to . be . equal ( 1 ) ;
41
47
expect ( globalScope . implicit . set . get ( "foo" ) ) . to . be . equal ( globalScope . implicit . variables [ 0 ] ) ;
42
48
expect ( globalScope . implicit . left ) . to . have . length ( 3 ) ;
@@ -60,12 +66,278 @@ describe("ScopeManager#addGlobals", () => {
60
66
expect ( globalScope . set . get ( "bar" ) ) . to . be . equal ( globalScope . variables [ 1 ] ) ;
61
67
expect ( globalScope . references ) . to . have . length ( 3 ) ;
62
68
expect ( globalScope . references [ 0 ] . identifier . name ) . to . be . equal ( "foo" ) ;
69
+ expect ( globalScope . references [ 0 ] . from ) . to . be . equal ( globalScope ) ;
63
70
expect ( globalScope . references [ 0 ] . resolved ) . to . be . equal ( globalScope . variables [ 0 ] ) ;
64
71
expect ( globalScope . variables [ 0 ] . references ) . to . have . length ( 1 ) ;
65
72
expect ( globalScope . variables [ 0 ] . references [ 0 ] ) . to . be . equal ( globalScope . references [ 0 ] ) ;
66
73
expect ( globalScope . references [ 1 ] . identifier . name ) . to . be . equal ( "bar" ) ;
74
+ expect ( globalScope . references [ 1 ] . from ) . to . be . equal ( globalScope ) ;
67
75
expect ( globalScope . references [ 1 ] . resolved ) . to . be . equal ( globalScope . variables [ 1 ] ) ;
68
76
expect ( globalScope . references [ 2 ] . identifier . name ) . to . be . equal ( "bar" ) ;
77
+ expect ( globalScope . references [ 2 ] . from ) . to . be . equal ( globalScope ) ;
78
+ expect ( globalScope . references [ 2 ] . resolved ) . to . be . equal ( globalScope . variables [ 1 ] ) ;
79
+ expect ( globalScope . variables [ 1 ] . references ) . to . have . length ( 2 ) ;
80
+ expect ( globalScope . variables [ 1 ] . references [ 0 ] ) . to . be . equal ( globalScope . references [ 1 ] ) ;
81
+ expect ( globalScope . variables [ 1 ] . references [ 1 ] ) . to . be . equal ( globalScope . references [ 2 ] ) ;
82
+ expect ( globalScope . through ) . to . have . length ( 0 ) ;
83
+ expect ( globalScope . implicit . variables ) . to . have . length ( 0 ) ;
84
+ expect ( globalScope . implicit . set . size ) . to . be . equal ( 0 ) ;
85
+ expect ( globalScope . implicit . left ) . to . have . length ( 0 ) ;
86
+ } ) ;
87
+
88
+ it ( "adds variables to the global scope and resolves references from inner scopes" , ( ) => {
89
+ const ast = espree ( `
90
+ () => foo = bar + bar;
91
+ ` ) ;
92
+
93
+ const scopeManager = analyze ( ast ) ;
94
+
95
+ expect ( scopeManager . scopes ) . to . have . length ( 2 ) ;
96
+
97
+ const globalScope = scopeManager . scopes [ 0 ] ;
98
+
99
+ expect ( globalScope . type ) . to . be . equal ( "global" ) ;
100
+
101
+ const functionScope = scopeManager . scopes [ 1 ] ;
102
+
103
+ expect ( functionScope . type ) . to . be . equal ( "function" ) ;
104
+
105
+ expect ( functionScope . variables ) . to . have . length ( 0 ) ;
106
+ expect ( functionScope . set . size ) . to . be . equal ( 0 ) ;
107
+ expect ( functionScope . references ) . to . have . length ( 3 ) ;
108
+ expect ( functionScope . references [ 0 ] . identifier . name ) . to . be . equal ( "foo" ) ;
109
+ expect ( functionScope . references [ 0 ] . from ) . to . be . equal ( functionScope ) ;
110
+ expect ( functionScope . references [ 0 ] . resolved ) . to . be . null ;
111
+ expect ( functionScope . references [ 1 ] . identifier . name ) . to . be . equal ( "bar" ) ;
112
+ expect ( functionScope . references [ 1 ] . from ) . to . be . equal ( functionScope ) ;
113
+ expect ( functionScope . references [ 1 ] . resolved ) . to . be . null ;
114
+ expect ( functionScope . references [ 2 ] . identifier . name ) . to . be . equal ( "bar" ) ;
115
+ expect ( functionScope . references [ 2 ] . from ) . to . be . equal ( functionScope ) ;
116
+ expect ( functionScope . references [ 2 ] . resolved ) . to . be . null ;
117
+ expect ( functionScope . references [ 1 ] ) . to . not . be . equal ( functionScope . references [ 2 ] ) ;
118
+ expect ( functionScope . through ) . to . have . length ( 3 ) ;
119
+ expect ( functionScope . through [ 0 ] ) . to . be . equal ( functionScope . references [ 0 ] ) ;
120
+ expect ( functionScope . through [ 1 ] ) . to . be . equal ( functionScope . references [ 1 ] ) ;
121
+ expect ( functionScope . through [ 2 ] ) . to . be . equal ( functionScope . references [ 2 ] ) ;
122
+ expect ( globalScope . variables ) . to . have . length ( 0 ) ;
123
+ expect ( globalScope . set . size ) . to . be . equal ( 0 ) ;
124
+ expect ( globalScope . references ) . to . have . length ( 0 ) ;
125
+ expect ( globalScope . through ) . to . have . length ( 3 ) ;
126
+ expect ( globalScope . through [ 0 ] ) . to . be . equal ( functionScope . references [ 0 ] ) ;
127
+ expect ( globalScope . through [ 1 ] ) . to . be . equal ( functionScope . references [ 1 ] ) ;
128
+ expect ( globalScope . through [ 2 ] ) . to . be . equal ( functionScope . references [ 2 ] ) ;
129
+ expect ( globalScope . implicit . variables ) . to . have . length ( 1 ) ;
130
+ expect ( globalScope . implicit . variables [ 0 ] . name ) . to . be . equal ( "foo" ) ;
131
+ expect ( globalScope . implicit . variables [ 0 ] . references ) . to . have . length ( 0 ) ;
132
+ expect ( globalScope . implicit . variables [ 0 ] . defs ) . to . have . length ( 1 ) ;
133
+ expect ( globalScope . implicit . variables [ 0 ] . identifiers ) . to . have . length ( 1 ) ;
134
+ expect ( globalScope . implicit . set . size ) . to . be . equal ( 1 ) ;
135
+ expect ( globalScope . implicit . set . get ( "foo" ) ) . to . be . equal ( globalScope . implicit . variables [ 0 ] ) ;
136
+ expect ( globalScope . implicit . left ) . to . have . length ( 3 ) ;
137
+ expect ( globalScope . implicit . left [ 0 ] ) . to . be . equal ( functionScope . references [ 0 ] ) ;
138
+ expect ( globalScope . implicit . left [ 1 ] ) . to . be . equal ( functionScope . references [ 1 ] ) ;
139
+ expect ( globalScope . implicit . left [ 2 ] ) . to . be . equal ( functionScope . references [ 2 ] ) ;
140
+
141
+ scopeManager . addGlobals ( [ "foo" , "bar" ] ) ;
142
+
143
+ expect ( globalScope . variables ) . to . have . length ( 2 ) ;
144
+ expect ( globalScope . variables [ 0 ] . name ) . to . be . equal ( "foo" ) ;
145
+ expect ( globalScope . variables [ 0 ] . scope ) . to . be . equal ( globalScope ) ;
146
+ expect ( globalScope . variables [ 0 ] . defs ) . to . have . length ( 0 ) ;
147
+ expect ( globalScope . variables [ 0 ] . identifiers ) . to . have . length ( 0 ) ;
148
+ expect ( globalScope . variables [ 1 ] . name ) . to . be . equal ( "bar" ) ;
149
+ expect ( globalScope . variables [ 1 ] . scope ) . to . be . equal ( globalScope ) ;
150
+ expect ( globalScope . variables [ 1 ] . defs ) . to . have . length ( 0 ) ;
151
+ expect ( globalScope . variables [ 1 ] . identifiers ) . to . have . length ( 0 ) ;
152
+ expect ( globalScope . set . size ) . to . be . equal ( 2 ) ;
153
+ expect ( globalScope . set . get ( "foo" ) ) . to . be . equal ( globalScope . variables [ 0 ] ) ;
154
+ expect ( globalScope . set . get ( "bar" ) ) . to . be . equal ( globalScope . variables [ 1 ] ) ;
155
+ expect ( functionScope . variables ) . to . have . length ( 0 ) ;
156
+ expect ( functionScope . set . size ) . to . be . equal ( 0 ) ;
157
+ expect ( functionScope . references ) . to . have . length ( 3 ) ;
158
+ expect ( functionScope . references [ 0 ] . identifier . name ) . to . be . equal ( "foo" ) ;
159
+ expect ( functionScope . references [ 0 ] . from ) . to . be . equal ( functionScope ) ;
160
+ expect ( functionScope . references [ 0 ] . resolved ) . to . be . equal ( globalScope . variables [ 0 ] ) ;
161
+ expect ( globalScope . variables [ 0 ] . references ) . to . have . length ( 1 ) ;
162
+ expect ( globalScope . variables [ 0 ] . references [ 0 ] ) . to . be . equal ( functionScope . references [ 0 ] ) ;
163
+ expect ( functionScope . references [ 1 ] . identifier . name ) . to . be . equal ( "bar" ) ;
164
+ expect ( functionScope . references [ 1 ] . from ) . to . be . equal ( functionScope ) ;
165
+ expect ( functionScope . references [ 1 ] . resolved ) . to . be . equal ( globalScope . variables [ 1 ] ) ;
166
+ expect ( functionScope . references [ 2 ] . identifier . name ) . to . be . equal ( "bar" ) ;
167
+ expect ( functionScope . references [ 2 ] . from ) . to . be . equal ( functionScope ) ;
168
+ expect ( functionScope . references [ 2 ] . resolved ) . to . be . equal ( globalScope . variables [ 1 ] ) ;
169
+ expect ( functionScope . references [ 1 ] ) . to . not . be . equal ( functionScope . references [ 2 ] ) ;
170
+ expect ( globalScope . variables [ 1 ] . references ) . to . have . length ( 2 ) ;
171
+ expect ( globalScope . variables [ 1 ] . references [ 0 ] ) . to . be . equal ( functionScope . references [ 1 ] ) ;
172
+ expect ( globalScope . variables [ 1 ] . references [ 1 ] ) . to . be . equal ( functionScope . references [ 2 ] ) ;
173
+ expect ( functionScope . through ) . to . have . length ( 3 ) ;
174
+ expect ( functionScope . through [ 0 ] ) . to . be . equal ( functionScope . references [ 0 ] ) ;
175
+ expect ( functionScope . through [ 1 ] ) . to . be . equal ( functionScope . references [ 1 ] ) ;
176
+ expect ( functionScope . through [ 2 ] ) . to . be . equal ( functionScope . references [ 2 ] ) ;
177
+ expect ( globalScope . references ) . to . have . length ( 0 ) ;
178
+ expect ( globalScope . through ) . to . have . length ( 0 ) ;
179
+ expect ( globalScope . implicit . variables ) . to . have . length ( 0 ) ;
180
+ expect ( globalScope . implicit . set . size ) . to . be . equal ( 0 ) ;
181
+ expect ( globalScope . implicit . left ) . to . have . length ( 0 ) ;
182
+ } ) ;
183
+
184
+ it ( "adds variables to the global scope and doesn't affect unrelated references" , ( ) => {
185
+ const ast = espree ( `
186
+ foo = bar + bar;
187
+ ` ) ;
188
+
189
+ const scopeManager = analyze ( ast ) ;
190
+
191
+ expect ( scopeManager . scopes ) . to . have . length ( 1 ) ;
192
+
193
+ const globalScope = scopeManager . scopes [ 0 ] ;
194
+
195
+ expect ( globalScope . type ) . to . be . equal ( "global" ) ;
196
+
197
+ expect ( globalScope . variables ) . to . have . length ( 0 ) ;
198
+ expect ( globalScope . set . size ) . to . be . equal ( 0 ) ;
199
+ expect ( globalScope . references ) . to . have . length ( 3 ) ;
200
+ expect ( globalScope . references [ 0 ] . identifier . name ) . to . be . equal ( "foo" ) ;
201
+ expect ( globalScope . references [ 0 ] . from ) . to . be . equal ( globalScope ) ;
202
+ expect ( globalScope . references [ 0 ] . resolved ) . to . be . null ;
203
+ expect ( globalScope . references [ 1 ] . identifier . name ) . to . be . equal ( "bar" ) ;
204
+ expect ( globalScope . references [ 1 ] . from ) . to . be . equal ( globalScope ) ;
205
+ expect ( globalScope . references [ 1 ] . resolved ) . to . be . null ;
206
+ expect ( globalScope . references [ 2 ] . identifier . name ) . to . be . equal ( "bar" ) ;
207
+ expect ( globalScope . references [ 2 ] . from ) . to . be . equal ( globalScope ) ;
208
+ expect ( globalScope . references [ 2 ] . resolved ) . to . be . null ;
209
+ expect ( globalScope . references [ 1 ] ) . to . not . be . equal ( globalScope . references [ 2 ] ) ;
210
+ expect ( globalScope . through ) . to . have . length ( 3 ) ;
211
+ expect ( globalScope . through [ 0 ] ) . to . be . equal ( globalScope . references [ 0 ] ) ;
212
+ expect ( globalScope . through [ 1 ] ) . to . be . equal ( globalScope . references [ 1 ] ) ;
213
+ expect ( globalScope . through [ 2 ] ) . to . be . equal ( globalScope . references [ 2 ] ) ;
214
+ expect ( globalScope . implicit . variables ) . to . have . length ( 1 ) ;
215
+ expect ( globalScope . implicit . variables [ 0 ] . name ) . to . be . equal ( "foo" ) ;
216
+ expect ( globalScope . implicit . variables [ 0 ] . references ) . to . have . length ( 0 ) ;
217
+ expect ( globalScope . implicit . variables [ 0 ] . defs ) . to . have . length ( 1 ) ;
218
+ expect ( globalScope . implicit . variables [ 0 ] . identifiers ) . to . have . length ( 1 ) ;
219
+ expect ( globalScope . implicit . set . size ) . to . be . equal ( 1 ) ;
220
+ expect ( globalScope . implicit . set . get ( "foo" ) ) . to . be . equal ( globalScope . implicit . variables [ 0 ] ) ;
221
+ expect ( globalScope . implicit . left ) . to . have . length ( 3 ) ;
222
+ expect ( globalScope . implicit . left [ 0 ] ) . to . be . equal ( globalScope . references [ 0 ] ) ;
223
+ expect ( globalScope . implicit . left [ 1 ] ) . to . be . equal ( globalScope . references [ 1 ] ) ;
224
+ expect ( globalScope . implicit . left [ 2 ] ) . to . be . equal ( globalScope . references [ 2 ] ) ;
225
+
226
+ scopeManager . addGlobals ( [ "baz" , "qux" ] ) ;
227
+
228
+ expect ( globalScope . variables ) . to . have . length ( 2 ) ;
229
+ expect ( globalScope . variables [ 0 ] . name ) . to . be . equal ( "baz" ) ;
230
+ expect ( globalScope . variables [ 0 ] . scope ) . to . be . equal ( globalScope ) ;
231
+ expect ( globalScope . variables [ 0 ] . defs ) . to . have . length ( 0 ) ;
232
+ expect ( globalScope . variables [ 0 ] . identifiers ) . to . have . length ( 0 ) ;
233
+ expect ( globalScope . variables [ 0 ] . references ) . to . have . length ( 0 ) ;
234
+ expect ( globalScope . variables [ 1 ] . name ) . to . be . equal ( "qux" ) ;
235
+ expect ( globalScope . variables [ 1 ] . scope ) . to . be . equal ( globalScope ) ;
236
+ expect ( globalScope . variables [ 1 ] . defs ) . to . have . length ( 0 ) ;
237
+ expect ( globalScope . variables [ 1 ] . identifiers ) . to . have . length ( 0 ) ;
238
+ expect ( globalScope . variables [ 1 ] . references ) . to . have . length ( 0 ) ;
239
+ expect ( globalScope . set . size ) . to . be . equal ( 2 ) ;
240
+ expect ( globalScope . set . get ( "baz" ) ) . to . be . equal ( globalScope . variables [ 0 ] ) ;
241
+ expect ( globalScope . set . get ( "qux" ) ) . to . be . equal ( globalScope . variables [ 1 ] ) ;
242
+ expect ( globalScope . references ) . to . have . length ( 3 ) ;
243
+ expect ( globalScope . references [ 0 ] . identifier . name ) . to . be . equal ( "foo" ) ;
244
+ expect ( globalScope . references [ 0 ] . from ) . to . be . equal ( globalScope ) ;
245
+ expect ( globalScope . references [ 0 ] . resolved ) . to . be . null ;
246
+ expect ( globalScope . references [ 1 ] . identifier . name ) . to . be . equal ( "bar" ) ;
247
+ expect ( globalScope . references [ 1 ] . from ) . to . be . equal ( globalScope ) ;
248
+ expect ( globalScope . references [ 1 ] . resolved ) . to . be . null ;
249
+ expect ( globalScope . references [ 2 ] . identifier . name ) . to . be . equal ( "bar" ) ;
250
+ expect ( globalScope . references [ 2 ] . from ) . to . be . equal ( globalScope ) ;
251
+ expect ( globalScope . references [ 2 ] . resolved ) . to . be . null ;
252
+ expect ( globalScope . references [ 1 ] ) . to . not . be . equal ( globalScope . references [ 2 ] ) ;
253
+ expect ( globalScope . through ) . to . have . length ( 3 ) ;
254
+ expect ( globalScope . through [ 0 ] ) . to . be . equal ( globalScope . references [ 0 ] ) ;
255
+ expect ( globalScope . through [ 1 ] ) . to . be . equal ( globalScope . references [ 1 ] ) ;
256
+ expect ( globalScope . through [ 2 ] ) . to . be . equal ( globalScope . references [ 2 ] ) ;
257
+ expect ( globalScope . implicit . variables ) . to . have . length ( 1 ) ;
258
+ expect ( globalScope . implicit . variables [ 0 ] . name ) . to . be . equal ( "foo" ) ;
259
+ expect ( globalScope . implicit . variables [ 0 ] . references ) . to . have . length ( 0 ) ;
260
+ expect ( globalScope . implicit . variables [ 0 ] . defs ) . to . have . length ( 1 ) ;
261
+ expect ( globalScope . implicit . variables [ 0 ] . identifiers ) . to . have . length ( 1 ) ;
262
+ expect ( globalScope . implicit . set . size ) . to . be . equal ( 1 ) ;
263
+ expect ( globalScope . implicit . set . get ( "foo" ) ) . to . be . equal ( globalScope . implicit . variables [ 0 ] ) ;
264
+ expect ( globalScope . implicit . left ) . to . have . length ( 3 ) ;
265
+ expect ( globalScope . implicit . left [ 0 ] ) . to . be . equal ( globalScope . references [ 0 ] ) ;
266
+ expect ( globalScope . implicit . left [ 1 ] ) . to . be . equal ( globalScope . references [ 1 ] ) ;
267
+ expect ( globalScope . implicit . left [ 2 ] ) . to . be . equal ( globalScope . references [ 2 ] ) ;
268
+ } ) ;
269
+
270
+ it ( "doesn't affect already declared global variables" , ( ) => {
271
+ const ast = espree ( `
272
+ let foo = bar + bar;
273
+ var bar;
274
+ ` ) ;
275
+
276
+ const scopeManager = analyze ( ast ) ;
277
+
278
+ expect ( scopeManager . scopes ) . to . have . length ( 1 ) ;
279
+
280
+ const globalScope = scopeManager . scopes [ 0 ] ;
281
+
282
+ expect ( globalScope . type ) . to . be . equal ( "global" ) ;
283
+
284
+ expect ( globalScope . variables ) . to . have . length ( 2 ) ;
285
+ expect ( globalScope . variables [ 0 ] . name ) . to . be . equal ( "foo" ) ;
286
+ expect ( globalScope . variables [ 0 ] . scope ) . to . be . equal ( globalScope ) ;
287
+ expect ( globalScope . variables [ 0 ] . defs ) . to . have . length ( 1 ) ;
288
+ expect ( globalScope . variables [ 0 ] . identifiers ) . to . have . length ( 1 ) ;
289
+ expect ( globalScope . variables [ 1 ] . name ) . to . be . equal ( "bar" ) ;
290
+ expect ( globalScope . variables [ 1 ] . scope ) . to . be . equal ( globalScope ) ;
291
+ expect ( globalScope . variables [ 1 ] . defs ) . to . have . length ( 1 ) ;
292
+ expect ( globalScope . variables [ 1 ] . identifiers ) . to . have . length ( 1 ) ;
293
+ expect ( globalScope . set . size ) . to . be . equal ( 2 ) ;
294
+ expect ( globalScope . set . get ( "foo" ) ) . to . be . equal ( globalScope . variables [ 0 ] ) ;
295
+ expect ( globalScope . set . get ( "bar" ) ) . to . be . equal ( globalScope . variables [ 1 ] ) ;
296
+ expect ( globalScope . references ) . to . have . length ( 3 ) ;
297
+ expect ( globalScope . references [ 0 ] . identifier . name ) . to . be . equal ( "foo" ) ;
298
+ expect ( globalScope . references [ 0 ] . from ) . to . be . equal ( globalScope ) ;
299
+ expect ( globalScope . references [ 0 ] . resolved ) . to . be . equal ( globalScope . variables [ 0 ] ) ;
300
+ expect ( globalScope . variables [ 0 ] . references ) . to . have . length ( 1 ) ;
301
+ expect ( globalScope . variables [ 0 ] . references [ 0 ] ) . to . be . equal ( globalScope . references [ 0 ] ) ;
302
+ expect ( globalScope . references [ 1 ] . identifier . name ) . to . be . equal ( "bar" ) ;
303
+ expect ( globalScope . references [ 1 ] . from ) . to . be . equal ( globalScope ) ;
304
+ expect ( globalScope . references [ 1 ] . resolved ) . to . be . equal ( globalScope . variables [ 1 ] ) ;
305
+ expect ( globalScope . references [ 2 ] . identifier . name ) . to . be . equal ( "bar" ) ;
306
+ expect ( globalScope . references [ 2 ] . from ) . to . be . equal ( globalScope ) ;
307
+ expect ( globalScope . references [ 2 ] . resolved ) . to . be . equal ( globalScope . variables [ 1 ] ) ;
308
+ expect ( globalScope . variables [ 1 ] . references ) . to . have . length ( 2 ) ;
309
+ expect ( globalScope . variables [ 1 ] . references [ 0 ] ) . to . be . equal ( globalScope . references [ 1 ] ) ;
310
+ expect ( globalScope . variables [ 1 ] . references [ 1 ] ) . to . be . equal ( globalScope . references [ 2 ] ) ;
311
+ expect ( globalScope . through ) . to . have . length ( 0 ) ;
312
+ expect ( globalScope . implicit . variables ) . to . have . length ( 0 ) ;
313
+ expect ( globalScope . implicit . set . size ) . to . be . equal ( 0 ) ;
314
+ expect ( globalScope . implicit . left ) . to . have . length ( 0 ) ;
315
+
316
+ scopeManager . addGlobals ( [ "foo" , "bar" ] ) ;
317
+
318
+ expect ( globalScope . variables ) . to . have . length ( 2 ) ;
319
+ expect ( globalScope . variables [ 0 ] . name ) . to . be . equal ( "foo" ) ;
320
+ expect ( globalScope . variables [ 0 ] . scope ) . to . be . equal ( globalScope ) ;
321
+ expect ( globalScope . variables [ 0 ] . defs ) . to . have . length ( 1 ) ;
322
+ expect ( globalScope . variables [ 0 ] . identifiers ) . to . have . length ( 1 ) ;
323
+ expect ( globalScope . variables [ 1 ] . name ) . to . be . equal ( "bar" ) ;
324
+ expect ( globalScope . variables [ 1 ] . scope ) . to . be . equal ( globalScope ) ;
325
+ expect ( globalScope . variables [ 1 ] . defs ) . to . have . length ( 1 ) ;
326
+ expect ( globalScope . variables [ 1 ] . identifiers ) . to . have . length ( 1 ) ;
327
+ expect ( globalScope . set . size ) . to . be . equal ( 2 ) ;
328
+ expect ( globalScope . set . get ( "foo" ) ) . to . be . equal ( globalScope . variables [ 0 ] ) ;
329
+ expect ( globalScope . set . get ( "bar" ) ) . to . be . equal ( globalScope . variables [ 1 ] ) ;
330
+ expect ( globalScope . references ) . to . have . length ( 3 ) ;
331
+ expect ( globalScope . references [ 0 ] . identifier . name ) . to . be . equal ( "foo" ) ;
332
+ expect ( globalScope . references [ 0 ] . from ) . to . be . equal ( globalScope ) ;
333
+ expect ( globalScope . references [ 0 ] . resolved ) . to . be . equal ( globalScope . variables [ 0 ] ) ;
334
+ expect ( globalScope . variables [ 0 ] . references ) . to . have . length ( 1 ) ;
335
+ expect ( globalScope . variables [ 0 ] . references [ 0 ] ) . to . be . equal ( globalScope . references [ 0 ] ) ;
336
+ expect ( globalScope . references [ 1 ] . identifier . name ) . to . be . equal ( "bar" ) ;
337
+ expect ( globalScope . references [ 1 ] . from ) . to . be . equal ( globalScope ) ;
338
+ expect ( globalScope . references [ 1 ] . resolved ) . to . be . equal ( globalScope . variables [ 1 ] ) ;
339
+ expect ( globalScope . references [ 2 ] . identifier . name ) . to . be . equal ( "bar" ) ;
340
+ expect ( globalScope . references [ 2 ] . from ) . to . be . equal ( globalScope ) ;
69
341
expect ( globalScope . references [ 2 ] . resolved ) . to . be . equal ( globalScope . variables [ 1 ] ) ;
70
342
expect ( globalScope . variables [ 1 ] . references ) . to . have . length ( 2 ) ;
71
343
expect ( globalScope . variables [ 1 ] . references [ 0 ] ) . to . be . equal ( globalScope . references [ 1 ] ) ;
0 commit comments