Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ const CompilationModeSchema = z.enum([
* This is the default mode
*/
"infer",
// Compile only components using Flow component syntax and hooks using hook syntax.
"syntax",
// Compile only functions which are explicitly annotated with "use forget"
"annotation",
// Compile all top-level functions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,23 +499,28 @@ function getReactFunctionType(
return getComponentOrHookLike(fn, hookPattern) ?? "Other";
}
}

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

switch (pass.opts.compilationMode) {
case "annotation": {
// opt-ins are checked above
return null;
}
case "infer": {
// Component and hook declarations are known components/hooks
if (fn.isFunctionDeclaration()) {
if (isComponentDeclaration(fn.node)) {
return "Component";
} else if (isHookDeclaration(fn.node)) {
return "Hook";
}
}

// Otherwise check if this is a component or hook-like function
return getComponentOrHookLike(fn, hookPattern);
// Check if this is a component or hook-like function
return componentSyntaxType ?? getComponentOrHookLike(fn, hookPattern);
}
case "syntax": {
return componentSyntaxType;
}
case "all": {
// Compile only top level functions
Expand Down