@@ -35,6 +35,7 @@ import type {
3535 TSTypeParameterDeclaration ,
3636 RestElement ,
3737 TypeScript ,
38+ TSQualifiedName ,
3839} from '@babel/types' ;
3940import { getDocblock } from './docblock.js' ;
4041
@@ -68,6 +69,22 @@ const namedTypes = {
6869 TSIndexedAccessType : handleTSIndexedAccessType ,
6970} ;
7071
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+
7188function handleTSArrayType (
7289 path : NodePath < TSArrayType > ,
7390 typeParams : TypeParameters | null ,
@@ -87,17 +104,7 @@ function handleTSTypeReference(
87104 const typeName = path . get ( 'typeName' ) ;
88105
89106 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 ) ;
101108 } else {
102109 type = { name : ( typeName as NodePath < Identifier > ) . node . name } ;
103110 }
@@ -366,17 +373,25 @@ function handleTSTypeQuery(
366373 path : NodePath < TSTypeQuery > ,
367374 typeParams : TypeParameters | null ,
368375) : TypeDescriptor < TSFunctionSignatureType > {
369- const resolvedPath = resolveToValue ( path . get ( 'exprName' ) ) ;
376+ const exprName = path . get ( 'exprName' ) ;
370377
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+ }
377387
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+ }
380395}
381396
382397function handleTSTypeOperator (
0 commit comments