@@ -18,7 +18,7 @@ export class ReactComponentPostProcessor extends PostProcessor {
1818 for ( const func of allFunctions ) {
1919 if (
2020 func . returnType instanceof LCETypeDeclared &&
21- ( func . returnType . fqn . globalFqn === '"react".React.JSX.Element' || func . returnType . fqn . globalFqn === '"react".JSX.Element' )
21+ isComponentReturnType ( func . returnType . fqn . globalFqn )
2222 ) {
2323 const component = new LCEReactComponent ( func . fqn , func . functionName , [ ] ) ;
2424 if ( func . metadata . has ( JSXDependencyContextProcessor . JSX_DEPENDENCY_METADATA ) ) {
@@ -34,8 +34,7 @@ export class ReactComponentPostProcessor extends PostProcessor {
3434 if (
3535 ( variable . type instanceof LCETypeFunction &&
3636 variable . type . returnType instanceof LCETypeDeclared &&
37- ( variable . type . returnType . fqn . globalFqn === '"react".React.JSX.Element' ||
38- variable . type . returnType . fqn . globalFqn === '"react".JSX.Element' ) ) ||
37+ isComponentReturnType ( variable . type . returnType . fqn . globalFqn ) ) ||
3938 ( variable . type instanceof LCETypeDeclared && isReactFunctionComponentType ( variable . type . fqn . globalFqn ) )
4039 ) {
4140 const component = new LCEReactComponent ( variable . fqn , variable . variableName , [ ] ) ;
@@ -63,18 +62,26 @@ export class ReactComponentPostProcessor extends PostProcessor {
6362 }
6463}
6564
65+ /**
66+ * returns whether the provided fqn is a return type that indicates that a function is a React component
67+ */
68+ function isComponentReturnType ( globalFqn : string ) : boolean {
69+ return [
70+ '"react".React.ReactNode' ,
71+ '"react".React.JSX.Element' ,
72+ '"react".JSX.Element'
73+ ] . includes ( globalFqn ) ;
74+ }
75+
6676/**
6777 * returns whether the provided fqn belongs to an interface/type describing a React function component
6878 */
6979function isReactFunctionComponentType ( globalFqn : string ) : boolean {
70- switch ( globalFqn ) {
71- case '"react".React.FC' :
72- case '"react".React.ExoticComponent' :
73- case '"react".React.NamedExoticComponent' :
74- case '"react".React.ForwardRefExoticComponent' :
75- case '"react".React.MemoExoticComponent' :
76- return true ;
77- default :
78- return false ;
79- }
80+ return [
81+ '"react".React.FC' ,
82+ '"react".React.ExoticComponent' ,
83+ '"react".React.NamedExoticComponent' ,
84+ '"react".React.ForwardRefExoticComponent' ,
85+ '"react".React.MemoExoticComponent'
86+ ] . includes ( globalFqn ) ;
8087}
0 commit comments