Skip to content

Commit 0b547b3

Browse files
Improved React Component detection
1 parent 9124c41 commit 0b547b3

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ export class ReactComponentPostProcessor extends PostProcessor {
1616
// Function Components (standard functions)
1717
const allFunctions: LCEFunctionDeclaration[] = (concepts.get(LCEFunctionDeclaration.conceptId) ?? []) as LCEFunctionDeclaration[];
1818
for (const func of allFunctions) {
19-
if (func.returnType instanceof LCETypeDeclared &&
20-
(func.returnType.fqn.globalFqn === '"react".React.JSX.Element' ||
21-
func.returnType.fqn.globalFqn === '"react".JSX.Element')) {
19+
if (
20+
func.returnType instanceof LCETypeDeclared &&
21+
(func.returnType.fqn.globalFqn === '"react".React.JSX.Element' || func.returnType.fqn.globalFqn === '"react".JSX.Element')
22+
) {
2223
const component = new LCEReactComponent(func.fqn, func.functionName, []);
2324
if (func.metadata.has(JSXDependencyContextProcessor.JSX_DEPENDENCY_METADATA)) {
2425
component.renderedElements.push(...func.metadata.get(JSXDependencyContextProcessor.JSX_DEPENDENCY_METADATA));
@@ -31,10 +32,11 @@ export class ReactComponentPostProcessor extends PostProcessor {
3132
const allVariables: LCEVariableDeclaration[] = (concepts.get(LCEVariableDeclaration.conceptId) ?? []) as LCEVariableDeclaration[];
3233
for (const variable of allVariables) {
3334
if (
34-
variable.type instanceof LCETypeFunction &&
35-
variable.type.returnType instanceof LCETypeDeclared &&
36-
(variable.type.returnType.fqn.globalFqn === '"react".React.JSX.Element' ||
37-
variable.type.returnType.fqn.globalFqn === '"react".JSX.Element')
35+
(variable.type instanceof LCETypeFunction &&
36+
variable.type.returnType instanceof LCETypeDeclared &&
37+
(variable.type.returnType.fqn.globalFqn === '"react".React.JSX.Element' ||
38+
variable.type.returnType.fqn.globalFqn === '"react".JSX.Element')) ||
39+
(variable.type instanceof LCETypeDeclared && variable.type.fqn.globalFqn === '"react".React.FC')
3840
) {
3941
const component = new LCEReactComponent(variable.fqn, variable.variableName, []);
4042
if (variable.metadata.has(JSXDependencyContextProcessor.JSX_DEPENDENCY_METADATA)) {

0 commit comments

Comments
 (0)