@@ -20,10 +20,15 @@ export interface Import {
20
20
/** Resolves the import of the specified identifier. */
21
21
export function getImportOfIdentifier ( node : ts . Identifier , typeChecker : ts . TypeChecker ) : Import |
22
22
null {
23
+ // Free standing identifiers which resolve to an import will be handled
24
+ // as direct imports. e.g. "@Component()" where "Component" is an identifier
25
+ // referring to an import specifier.
23
26
const directImport = getSpecificImportOfIdentifier ( node , typeChecker ) ;
24
27
if ( directImport !== null ) {
25
28
return directImport ;
26
29
} else if ( ts . isQualifiedName ( node . parent ) && node . parent . right === node ) {
30
+ // Determines the import of a qualified name. e.g. "let t: core.Component". In that
31
+ // case, the import of the most left identifier will be determined ("core").
27
32
const qualifierRoot = getQualifiedNameRoot ( node . parent ) ;
28
33
if ( qualifierRoot ) {
29
34
const moduleName = getImportOfNamespacedIdentifier ( qualifierRoot , typeChecker ) ;
@@ -32,6 +37,8 @@ export function getImportOfIdentifier(node: ts.Identifier, typeChecker: ts.TypeC
32
37
}
33
38
}
34
39
} else if ( ts . isPropertyAccessExpression ( node . parent ) && node . parent . name === node ) {
40
+ // Determines the import of a property expression. e.g. "@core.Component". In that
41
+ // case, the import of the most left identifier will be determined ("core").
35
42
const rootIdentifier = getPropertyAccessRoot ( node . parent ) ;
36
43
if ( rootIdentifier ) {
37
44
const moduleName = getImportOfNamespacedIdentifier ( rootIdentifier , typeChecker ) ;
@@ -57,6 +64,8 @@ function getSpecificImportOfIdentifier(node: ts.Identifier, typeChecker: ts.Type
57
64
if ( ! ts . isImportSpecifier ( declaration ) ) {
58
65
return null ;
59
66
}
67
+ // Since the declaration is an import specifier, we can walk up three times to get a reference
68
+ // to the import declaration node (NamedImports -> ImportClause -> ImportDeclaration).
60
69
const importDecl = declaration . parent . parent . parent ;
61
70
if ( ! ts . isStringLiteral ( importDecl . moduleSpecifier ) ) {
62
71
return null ;
@@ -81,6 +90,8 @@ function getImportOfNamespacedIdentifier(node: ts.Identifier, typeChecker: ts.Ty
81
90
if ( ! ts . isNamespaceImport ( declaration ) ) {
82
91
return null ;
83
92
}
93
+ // Since the declaration is a namespace import, we can walk up three times to get a reference
94
+ // to the import declaration node (NamespaceImport -> ImportClause -> ImportDeclaration).
84
95
const importDecl = declaration . parent . parent ;
85
96
if ( ! ts . isStringLiteral ( importDecl . moduleSpecifier ) ) {
86
97
return null ;
0 commit comments