@@ -514,42 +514,6 @@ const describePossibleImportDef = (def: TSESLint.Scope.Definition) => {
514
514
return null ;
515
515
} ;
516
516
517
- const collectReferences = ( scope : TSESLint . Scope . Scope ) => {
518
- const locals = new Set ( ) ;
519
- const imports = new Map < string , ImportDetails > ( ) ;
520
- const unresolved = new Set ( ) ;
521
-
522
- let currentScope : TSESLint . Scope . Scope | null = scope ;
523
-
524
- while ( currentScope !== null ) {
525
- for ( const ref of currentScope . variables ) {
526
- if ( ref . defs . length === 0 ) {
527
- continue ;
528
- }
529
-
530
- const def = ref . defs [ ref . defs . length - 1 ] ;
531
-
532
- const importDetails = describePossibleImportDef ( def ) ;
533
-
534
- if ( importDetails ) {
535
- imports . set ( importDetails . local , importDetails ) ;
536
-
537
- continue ;
538
- }
539
-
540
- locals . add ( ref . name ) ;
541
- }
542
-
543
- for ( const ref of currentScope . through ) {
544
- unresolved . add ( ref . identifier . name ) ;
545
- }
546
-
547
- currentScope = currentScope . upper ;
548
- }
549
-
550
- return { locals, imports, unresolved } ;
551
- } ;
552
-
553
517
const resolveScope = ( scope : TSESLint . Scope . Scope , identifier : string ) => {
554
518
let currentScope : TSESLint . Scope . Scope | null = scope ;
555
519
@@ -621,15 +585,29 @@ export const scopeHasLocalReference = (
621
585
scope : TSESLint . Scope . Scope ,
622
586
referenceName : string ,
623
587
) => {
624
- const references = collectReferences ( scope ) ;
625
-
626
- return (
627
- // referenceName was found as a local variable or function declaration.
628
- references . locals . has ( referenceName ) ||
629
- // referenceName was found as an imported identifier
630
- references . imports . has ( referenceName ) ||
631
- // referenceName was not found as an unresolved reference,
632
- // meaning it is likely not an implicit global reference.
633
- ! references . unresolved . has ( referenceName )
634
- ) ;
588
+ let currentScope : TSESLint . Scope . Scope | null = scope ;
589
+
590
+ while ( currentScope !== null ) {
591
+ for ( const ref of currentScope . variables ) {
592
+ if ( ref . defs . length === 0 ) {
593
+ continue ;
594
+ }
595
+
596
+ const def = ref . defs [ ref . defs . length - 1 ] ;
597
+
598
+ const importDetails = describePossibleImportDef ( def ) ;
599
+
600
+ // referenceName was found as an imported identifier
601
+ if ( importDetails ?. local === referenceName ) {
602
+ return true ;
603
+ }
604
+
605
+ // referenceName was found as a local variable or function declaration.
606
+ return ref . name === referenceName ;
607
+ }
608
+
609
+ currentScope = currentScope . upper ;
610
+ }
611
+
612
+ return false ;
635
613
} ;
0 commit comments