Skip to content

Commit

Permalink
Update base for Update on "[compiler] Expect components to have hook …
Browse files Browse the repository at this point in the history
…calls or jsx directly in body"

Summary: We can tighten our criteria for what is a component by requiring that a component or hook contain JSX or hook calls directly within its body, excluding nested functions . Currently, if we see them within the body anywhere -- including nested functions -- we treat it as a component if the other requirements are met. This change makes this stricter.

We also now expect components (but not necessarily hooks) to have return statements, and those returns must be potential React nodes (we can reject functions that return function or object literals, for example).

[ghstack-poisoned]
  • Loading branch information
mvitousek committed Jun 11, 2024
1 parent ade6917 commit 650ed71
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -501,12 +501,12 @@ function getReactFunctionType(
}

// Component and hook declarations are known components/hooks
let explicitSyntax: ReactFunctionType | null = null;
let componentSyntaxType: ReactFunctionType | null = null;
if (fn.isFunctionDeclaration()) {
if (isComponentDeclaration(fn.node)) {
explicitSyntax = "Component";
componentSyntaxType = "Component";
} else if (isHookDeclaration(fn.node)) {
explicitSyntax = "Hook";
componentSyntaxType = "Hook";
}
}

Expand All @@ -517,10 +517,10 @@ function getReactFunctionType(
}
case "infer": {
// Check if this is a component or hook-like function
return explicitSyntax ?? getComponentOrHookLike(fn, hookPattern);
return componentSyntaxType ?? getComponentOrHookLike(fn, hookPattern);
}
case "syntax": {
return explicitSyntax;
return componentSyntaxType;
}
case "all": {
// Compile only top level functions
Expand Down

0 comments on commit 650ed71

Please sign in to comment.