@@ -26,6 +26,7 @@ pub struct AliasConfig {
26
26
/// on.
27
27
pub ignore_named_child_scope : bool ,
28
28
}
29
+
29
30
impl AliasConfig {
30
31
pub fn marks ( mut self , arg : Option < Marks > ) -> Self {
31
32
self . marks = arg;
98
99
config,
99
100
unresolved_ctxt,
100
101
101
- ctx : Ctx {
102
- track_expr_ident : true ,
103
- ..Default :: default ( )
104
- } ,
102
+ ctx : Ctx :: TrackExprIdent ,
105
103
106
104
bindings : FxHashSet :: default ( ) ,
107
105
accesses : FxHashSet :: default ( ) ,
@@ -138,10 +136,7 @@ where
138
136
config,
139
137
unresolved_ctxt,
140
138
141
- ctx : Ctx {
142
- track_expr_ident : true ,
143
- ..Default :: default ( )
144
- } ,
139
+ ctx : Ctx :: TrackExprIdent ,
145
140
146
141
bindings : FxHashSet :: default ( ) ,
147
142
accesses : FxHashSet :: default ( ) ,
@@ -191,7 +186,7 @@ impl InfectionCollector {
191
186
192
187
self . accesses . insert ( (
193
188
e,
194
- if self . ctx . is_callee {
189
+ if self . ctx . contains ( Ctx :: IsCallee ) {
195
190
AccessKind :: Call
196
191
} else {
197
192
AccessKind :: Reference
@@ -204,15 +199,15 @@ impl Visit for InfectionCollector {
204
199
noop_visit_type ! ( ) ;
205
200
206
201
fn visit_arrow_expr ( & mut self , n : & ArrowExpr ) {
207
- let old = self . ctx . is_pat_decl ;
202
+ let old = self . ctx . contains ( Ctx :: IsPatDecl ) ;
208
203
209
204
for p in & n. params {
210
- self . ctx . is_pat_decl = true ;
205
+ self . ctx . insert ( Ctx :: IsPatDecl ) ;
211
206
p. visit_with ( self ) ;
212
207
}
213
208
214
209
n. body . visit_with ( self ) ;
215
- self . ctx . is_pat_decl = old;
210
+ self . ctx . set ( Ctx :: IsPatDecl , old) ;
216
211
}
217
212
218
213
fn visit_assign_expr ( & mut self , n : & AssignExpr ) {
@@ -230,7 +225,7 @@ impl Visit for InfectionCollector {
230
225
fn visit_assign_pat_prop ( & mut self , node : & AssignPatProp ) {
231
226
node. value . visit_with ( self ) ;
232
227
233
- if self . ctx . is_pat_decl {
228
+ if self . ctx . contains ( Ctx :: IsPatDecl ) {
234
229
self . add_binding ( & node. key . clone ( ) . into ( ) ) ;
235
230
}
236
231
}
@@ -258,29 +253,18 @@ impl Visit for InfectionCollector {
258
253
| op ! ( "<<" )
259
254
| op ! ( ">>" )
260
255
| op ! ( ">>>" ) => {
261
- let ctx = Ctx {
262
- track_expr_ident : false ,
263
- is_callee : false ,
264
- ..self . ctx
265
- } ;
256
+ let ctx = self . ctx - Ctx :: TrackExprIdent - Ctx :: IsCallee ;
266
257
e. visit_children_with ( & mut * self . with_ctx ( ctx) ) ;
267
258
}
268
259
_ => {
269
- let ctx = Ctx {
270
- track_expr_ident : true ,
271
- is_callee : false ,
272
- ..self . ctx
273
- } ;
260
+ let ctx = ( self . ctx | Ctx :: TrackExprIdent ) - Ctx :: IsCallee ;
274
261
e. visit_children_with ( & mut * self . with_ctx ( ctx) ) ;
275
262
}
276
263
}
277
264
}
278
265
279
266
fn visit_callee ( & mut self , n : & Callee ) {
280
- let ctx = Ctx {
281
- is_callee : true ,
282
- ..self . ctx
283
- } ;
267
+ let ctx = self . ctx | Ctx :: IsCallee ;
284
268
n. visit_children_with ( & mut * self . with_ctx ( ctx) ) ;
285
269
}
286
270
@@ -292,19 +276,12 @@ impl Visit for InfectionCollector {
292
276
293
277
fn visit_cond_expr ( & mut self , e : & CondExpr ) {
294
278
{
295
- let ctx = Ctx {
296
- track_expr_ident : false ,
297
- is_callee : false ,
298
- ..self . ctx
299
- } ;
279
+ let ctx = self . ctx - Ctx :: TrackExprIdent - Ctx :: IsCallee ;
300
280
e. test . visit_with ( & mut * self . with_ctx ( ctx) ) ;
301
281
}
302
282
303
283
{
304
- let ctx = Ctx {
305
- track_expr_ident : true ,
306
- ..self . ctx
307
- } ;
284
+ let ctx = self . ctx | Ctx :: TrackExprIdent ;
308
285
e. cons . visit_with ( & mut * self . with_ctx ( ctx) ) ;
309
286
e. alt . visit_with ( & mut * self . with_ctx ( ctx) ) ;
310
287
}
@@ -319,17 +296,13 @@ impl Visit for InfectionCollector {
319
296
320
297
match e {
321
298
Expr :: Ident ( i) => {
322
- if self . ctx . track_expr_ident {
299
+ if self . ctx . contains ( Ctx :: TrackExprIdent ) {
323
300
self . add_usage ( i. to_id ( ) ) ;
324
301
}
325
302
}
326
303
327
304
_ => {
328
- let ctx = Ctx {
329
- track_expr_ident : true ,
330
- is_pat_decl : false ,
331
- ..self . ctx
332
- } ;
305
+ let ctx = ( self . ctx | Ctx :: TrackExprIdent ) - Ctx :: IsPatDecl ;
333
306
e. visit_children_with ( & mut * self . with_ctx ( ctx) ) ;
334
307
}
335
308
}
@@ -368,42 +341,35 @@ impl Visit for InfectionCollector {
368
341
369
342
fn visit_member_expr ( & mut self , n : & MemberExpr ) {
370
343
{
371
- let ctx = Ctx {
372
- track_expr_ident : self . config . need_all ,
373
- ..self . ctx
374
- } ;
344
+ let mut ctx = self . ctx ;
345
+ ctx. set ( Ctx :: TrackExprIdent , self . config . need_all ) ;
375
346
n. obj . visit_with ( & mut * self . with_ctx ( ctx) ) ;
376
347
}
377
348
378
349
{
379
- let ctx = Ctx {
380
- track_expr_ident : self . config . need_all ,
381
- ..self . ctx
382
- } ;
350
+ let mut ctx = self . ctx ;
351
+ ctx. set ( Ctx :: TrackExprIdent , self . config . need_all ) ;
383
352
n. prop . visit_with ( & mut * self . with_ctx ( ctx) ) ;
384
353
}
385
354
}
386
355
387
356
fn visit_member_prop ( & mut self , n : & MemberProp ) {
388
357
if let MemberProp :: Computed ( c) = & n {
389
- c. visit_with ( & mut * self . with_ctx ( Ctx {
390
- is_callee : false ,
391
- ..self . ctx
392
- } ) ) ;
358
+ c. visit_with ( & mut * self . with_ctx ( self . ctx - Ctx :: IsCallee ) ) ;
393
359
}
394
360
}
395
361
396
362
fn visit_param ( & mut self , node : & Param ) {
397
- let old = self . ctx . is_pat_decl ;
398
- self . ctx . is_pat_decl = true ;
363
+ let old = self . ctx . contains ( Ctx :: IsPatDecl ) ;
364
+ self . ctx . insert ( Ctx :: IsPatDecl ) ;
399
365
node. visit_children_with ( self ) ;
400
- self . ctx . is_pat_decl = old;
366
+ self . ctx . set ( Ctx :: IsPatDecl , old) ;
401
367
}
402
368
403
369
fn visit_pat ( & mut self , node : & Pat ) {
404
370
node. visit_children_with ( self ) ;
405
371
406
- if self . ctx . is_pat_decl {
372
+ if self . ctx . contains ( Ctx :: IsPatDecl ) {
407
373
if let Pat :: Ident ( i) = node {
408
374
self . add_binding ( i)
409
375
}
@@ -412,10 +378,7 @@ impl Visit for InfectionCollector {
412
378
413
379
fn visit_prop_name ( & mut self , n : & PropName ) {
414
380
if let PropName :: Computed ( c) = & n {
415
- c. visit_with ( & mut * self . with_ctx ( Ctx {
416
- is_callee : false ,
417
- ..self . ctx
418
- } ) ) ;
381
+ c. visit_with ( & mut * self . with_ctx ( self . ctx - Ctx :: IsCallee ) ) ;
419
382
}
420
383
}
421
384
@@ -431,10 +394,7 @@ impl Visit for InfectionCollector {
431
394
432
395
fn visit_super_prop_expr ( & mut self , n : & SuperPropExpr ) {
433
396
if let SuperProp :: Computed ( c) = & n. prop {
434
- c. visit_with ( & mut * self . with_ctx ( Ctx {
435
- is_callee : false ,
436
- ..self . ctx
437
- } ) ) ;
397
+ c. visit_with ( & mut * self . with_ctx ( self . ctx - Ctx :: IsCallee ) ) ;
438
398
}
439
399
}
440
400
@@ -446,40 +406,28 @@ impl Visit for InfectionCollector {
446
406
| op ! ( "!" )
447
407
| op ! ( "typeof" )
448
408
| op ! ( "void" ) => {
449
- let ctx = Ctx {
450
- track_expr_ident : false ,
451
- is_callee : false ,
452
- ..self . ctx
453
- } ;
409
+ let ctx = self . ctx - Ctx :: TrackExprIdent - Ctx :: IsCallee ;
454
410
e. visit_children_with ( & mut * self . with_ctx ( ctx) ) ;
455
411
}
456
412
457
413
_ => {
458
- let ctx = Ctx {
459
- track_expr_ident : true ,
460
- is_callee : false ,
461
- ..self . ctx
462
- } ;
414
+ let ctx = ( self . ctx | Ctx :: TrackExprIdent ) - Ctx :: IsCallee ;
463
415
e. visit_children_with ( & mut * self . with_ctx ( ctx) ) ;
464
416
}
465
417
}
466
418
}
467
419
468
420
fn visit_update_expr ( & mut self , e : & UpdateExpr ) {
469
- let ctx = Ctx {
470
- track_expr_ident : false ,
471
- is_callee : false ,
472
- ..self . ctx
473
- } ;
421
+ let ctx = self . ctx - Ctx :: TrackExprIdent - Ctx :: IsCallee ;
474
422
e. arg . visit_with ( & mut * self . with_ctx ( ctx) ) ;
475
423
}
476
424
477
425
fn visit_var_declarator ( & mut self , n : & VarDeclarator ) {
478
426
{
479
- let old = self . ctx . is_pat_decl ;
480
- self . ctx . is_pat_decl = true ;
427
+ let old = self . ctx . contains ( Ctx :: IsPatDecl ) ;
428
+ self . ctx . insert ( Ctx :: IsPatDecl ) ;
481
429
n. name . visit_with ( self ) ;
482
- self . ctx . is_pat_decl = old;
430
+ self . ctx . set ( Ctx :: IsPatDecl , old) ;
483
431
}
484
432
485
433
if self . config . ignore_named_child_scope {
@@ -489,10 +437,10 @@ impl Visit for InfectionCollector {
489
437
}
490
438
491
439
{
492
- let old = self . ctx . is_pat_decl ;
493
- self . ctx . is_pat_decl = false ;
440
+ let old = self . ctx . contains ( Ctx :: IsPatDecl ) ;
441
+ self . ctx . remove ( Ctx :: IsPatDecl ) ;
494
442
n. init . visit_with ( self ) ;
495
- self . ctx . is_pat_decl = old;
443
+ self . ctx . set ( Ctx :: IsPatDecl , old) ;
496
444
}
497
445
}
498
446
}
0 commit comments