Skip to content

Commit 1afab37

Browse files
Improved React component detection
1 parent 6201bf7 commit 1afab37

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

typescript/src/react/post-processors/react-component.post-processor.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class ReactComponentPostProcessor extends PostProcessor {
3636
variable.type.returnType instanceof LCETypeDeclared &&
3737
(variable.type.returnType.fqn.globalFqn === '"react".React.JSX.Element' ||
3838
variable.type.returnType.fqn.globalFqn === '"react".JSX.Element')) ||
39-
(variable.type instanceof LCETypeDeclared && variable.type.fqn.globalFqn === '"react".React.FC')
39+
(variable.type instanceof LCETypeDeclared && isReactFunctionComponentType(variable.type.fqn.globalFqn))
4040
) {
4141
const component = new LCEReactComponent(variable.fqn, variable.variableName, []);
4242
if (variable.metadata.has(JSXDependencyContextProcessor.JSX_DEPENDENCY_METADATA)) {
@@ -62,3 +62,19 @@ export class ReactComponentPostProcessor extends PostProcessor {
6262
}
6363
}
6464
}
65+
66+
/**
67+
* returns whether the provided fqn belongs to an interface/type describing a React function component
68+
*/
69+
function 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+
}

0 commit comments

Comments
 (0)