diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/Entrypoint/Program.ts b/compiler/forget/packages/babel-plugin-react-forget/src/Entrypoint/Program.ts index 6afcafa694..7fcbbf5046 100644 --- a/compiler/forget/packages/babel-plugin-react-forget/src/Entrypoint/Program.ts +++ b/compiler/forget/packages/babel-plugin-react-forget/src/Entrypoint/Program.ts @@ -330,7 +330,7 @@ function shouldVisitNode( fn: NodePath, pass: CompilerPass ): boolean { - if (pass.opts.enableOnlyOnReactScript) { + if (pass.opts.enableOnlyOnReactScript && fn.isFunctionDeclaration()) { return isComponentDeclaration(fn.node); } diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/Utils/ComponentDeclaration.ts b/compiler/forget/packages/babel-plugin-react-forget/src/Utils/ComponentDeclaration.ts index 4b50f4efee..b2686e8506 100644 --- a/compiler/forget/packages/babel-plugin-react-forget/src/Utils/ComponentDeclaration.ts +++ b/compiler/forget/packages/babel-plugin-react-forget/src/Utils/ComponentDeclaration.ts @@ -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; }