[ez] ComponentDeclaration transforms only into FunctionDeclaration

ComponentDeclarations can only be transformed into FunctionDeclarations, so the 
types were wrong
This commit is contained in:
Lauren Tan
2023-08-11 13:31:06 -04:00
parent c3ec002d69
commit 6c719f62a0
2 changed files with 4 additions and 5 deletions
@@ -330,7 +330,7 @@ function shouldVisitNode(
fn: NodePath<t.FunctionDeclaration | t.ArrowFunctionExpression>,
pass: CompilerPass
): boolean {
if (pass.opts.enableOnlyOnReactScript) {
if (pass.opts.enableOnlyOnReactScript && fn.isFunctionDeclaration()) {
return isComponentDeclaration(fn.node);
}
@@ -1,18 +1,17 @@
import * as t from "@babel/types";
type FunctionDeclOrExpr = t.FunctionDeclaration | t.ArrowFunctionExpression;
type ComponentDeclaration = FunctionDeclOrExpr & {
export type ComponentDeclaration = t.FunctionDeclaration & {
__componentDeclaration: boolean;
};
export function isComponentDeclaration(
node: FunctionDeclOrExpr
node: t.FunctionDeclaration
): node is ComponentDeclaration {
return Object.prototype.hasOwnProperty.call(node, "__componentDeclaration");
}
export function parseComponentDeclaration(
node: FunctionDeclOrExpr
node: t.FunctionDeclaration
): ComponentDeclaration | null {
return isComponentDeclaration(node) ? node : null;
}