@@ -2,25 +2,23 @@ import { Node, TypeReferenceNode, TypeNode, TypeAliasDeclaration, SourceFile, St
2
2
import { ProjectAdapter } from "./ast/projectAdapter" ;
3
3
4
4
export class TypeReferenceFinder {
5
- constructor ( private project : ProjectAdapter ) { }
5
+ constructor ( private project : ProjectAdapter ) { }
6
6
7
7
public findTypeReference ( node : Node ) : TypeAliasDeclaration | undefined {
8
8
return Node . isIdentifier ( node ) ? this . findTypeReferenceInIdentifier ( node as Identifier ) : undefined ;
9
9
}
10
10
11
11
private findTypeReferenceInIdentifier ( node : Identifier ) {
12
- const aliases = this . findAllMatchingAliases ( node . getText ( ) ) ;
12
+ const aliases = this . findAllMatchingAliases ( node ) ;
13
13
this . logMatches ( aliases , node . getText ( ) ) ;
14
14
return aliases . length > 0 ? aliases [ 0 ] : undefined ;
15
15
}
16
16
17
- private findAllMatchingAliases ( targetDependency : string ) : TypeAliasDeclaration [ ] {
18
- return this . project . getSourceFiles ( ) . flatMap ( sourceFile => this . findMatchingAliasesInFile ( sourceFile , targetDependency ) ) ;
19
- }
20
-
21
- private findMatchingAliasesInFile ( sourceFile : SourceFile , targetDependency : string ) : TypeAliasDeclaration [ ] {
22
- console . log ( `🔎 Searching for ${ targetDependency } in ${ sourceFile . getTypeAliases ( ) . length } type aliases` ) ;
23
- return sourceFile . getTypeAliases ( ) . filter ( alias => this . matchesDependencyOfType ( alias , targetDependency ) ) ;
17
+ private findAllMatchingAliases ( targetDependency : Node ) : TypeAliasDeclaration [ ] {
18
+ return targetDependency
19
+ . getSourceFile ( )
20
+ . getTypeAliases ( )
21
+ . filter ( alias => this . matchesDependencyOfType ( alias , targetDependency . getText ( ) ) ) ;
24
22
}
25
23
26
24
private matchesDependencyOfType ( alias : TypeAliasDeclaration , targetDependency : string ) : boolean {
0 commit comments