@@ -25,20 +25,28 @@ import getTypeIdentifier from './getTypeIdentifier.js';
2525import isReactBuiltinReference from './isReactBuiltinReference.js' ;
2626import unwrapBuiltinTSPropTypes from './unwrapBuiltinTSPropTypes.js' ;
2727
28- // TODO TESTME
29-
3028function getStatelessPropsPath (
3129 componentDefinition : NodePath ,
3230) : NodePath | undefined {
33- let value = componentDefinition ;
31+ if ( ! componentDefinition . isFunction ( ) ) return ;
3432
35- if ( isReactForwardRefCall ( value ) ) {
36- value = resolveToValue ( value . get ( 'arguments' ) [ 0 ] ! ) ;
37- }
33+ return componentDefinition . get ( 'params' ) [ 0 ] ;
34+ }
3835
39- if ( ! value . isFunction ( ) ) return ;
36+ function getForwardRefGenericsType (
37+ componentDefinition : NodePath ,
38+ ) : NodePath < TSType > | null {
39+ const typeParameters = componentDefinition . get ( 'typeParameters' ) as NodePath <
40+ TSTypeParameterInstantiation | null | undefined
41+ > ;
42+
43+ if ( typeParameters && typeParameters . hasNode ( ) ) {
44+ const params = typeParameters . get ( 'params' ) ;
45+
46+ return params [ 1 ] ?? null ;
47+ }
4048
41- return value . get ( 'params' ) [ 0 ] ;
49+ return null ;
4250}
4351
4452function findAssignedVariableType (
@@ -106,6 +114,19 @@ export default (componentDefinition: NodePath): NodePath[] => {
106114 }
107115 }
108116 } else {
117+ if ( isReactForwardRefCall ( componentDefinition ) ) {
118+ const genericTypeAnnotation =
119+ getForwardRefGenericsType ( componentDefinition ) ;
120+
121+ if ( genericTypeAnnotation ) {
122+ typePaths . push ( genericTypeAnnotation ) ;
123+ }
124+
125+ componentDefinition = resolveToValue (
126+ componentDefinition . get ( 'arguments' ) [ 0 ] ! ,
127+ ) ;
128+ }
129+
109130 const propsParam = getStatelessPropsPath ( componentDefinition ) ;
110131
111132 if ( propsParam ) {
0 commit comments