@@ -35,6 +35,7 @@ import type {
35
35
TSTypeParameterDeclaration ,
36
36
RestElement ,
37
37
TypeScript ,
38
+ TSQualifiedName ,
38
39
} from '@babel/types' ;
39
40
import { getDocblock } from './docblock.js' ;
40
41
@@ -68,6 +69,22 @@ const namedTypes = {
68
69
TSIndexedAccessType : handleTSIndexedAccessType ,
69
70
} ;
70
71
72
+ function handleTSQualifiedName (
73
+ path : NodePath < TSQualifiedName > ,
74
+ ) : TypeDescriptor < TSFunctionSignatureType > {
75
+ const left = path . get ( 'left' ) ;
76
+ const right = path . get ( 'right' ) ;
77
+
78
+ if ( left . isIdentifier ( { name : 'React' } ) && right . isIdentifier ( ) ) {
79
+ return {
80
+ name : `${ left . node . name } ${ right . node . name } ` ,
81
+ raw : printValue ( path ) ,
82
+ } ;
83
+ }
84
+
85
+ return { name : printValue ( path ) . replace ( / < .* > $ / , '' ) } ;
86
+ }
87
+
71
88
function handleTSArrayType (
72
89
path : NodePath < TSArrayType > ,
73
90
typeParams : TypeParameters | null ,
@@ -87,17 +104,7 @@ function handleTSTypeReference(
87
104
const typeName = path . get ( 'typeName' ) ;
88
105
89
106
if ( typeName . isTSQualifiedName ( ) ) {
90
- const left = typeName . get ( 'left' ) ;
91
- const right = typeName . get ( 'right' ) ;
92
-
93
- if ( left . isIdentifier ( { name : 'React' } ) && right . isIdentifier ( ) ) {
94
- type = {
95
- name : `${ left . node . name } ${ right . node . name } ` ,
96
- raw : printValue ( typeName ) ,
97
- } ;
98
- } else {
99
- type = { name : printValue ( typeName ) . replace ( / < .* > $ / , '' ) } ;
100
- }
107
+ type = handleTSQualifiedName ( typeName ) ;
101
108
} else {
102
109
type = { name : ( typeName as NodePath < Identifier > ) . node . name } ;
103
110
}
@@ -366,17 +373,25 @@ function handleTSTypeQuery(
366
373
path : NodePath < TSTypeQuery > ,
367
374
typeParams : TypeParameters | null ,
368
375
) : TypeDescriptor < TSFunctionSignatureType > {
369
- const resolvedPath = resolveToValue ( path . get ( 'exprName' ) ) ;
376
+ const exprName = path . get ( 'exprName' ) ;
370
377
371
- if ( 'typeAnnotation' in resolvedPath . node ) {
372
- return getTSTypeWithResolvedTypes (
373
- resolvedPath . get ( 'typeAnnotation' ) as NodePath < TypeScript > ,
374
- typeParams ,
375
- ) ;
376
- }
378
+ if ( exprName . isIdentifier ( ) ) {
379
+ const resolvedPath = resolveToValue ( path . get ( 'exprName' ) ) ;
380
+
381
+ if ( resolvedPath . has ( 'typeAnnotation' ) ) {
382
+ return getTSTypeWithResolvedTypes (
383
+ resolvedPath . get ( 'typeAnnotation' ) as NodePath < TypeScript > ,
384
+ typeParams ,
385
+ ) ;
386
+ }
377
387
378
- // @ts -ignore Do we need to handle TsQualifiedName here TODO
379
- return { name : path . node . exprName . name } ;
388
+ return { name : exprName . node . name } ;
389
+ } else if ( exprName . isTSQualifiedName ( ) ) {
390
+ return handleTSQualifiedName ( exprName ) ;
391
+ } else {
392
+ // TSImportType
393
+ return { name : printValue ( exprName ) } ;
394
+ }
380
395
}
381
396
382
397
function handleTSTypeOperator (
0 commit comments