From 6c719f62a07114cfa23631e79a8962f6c770ddda Mon Sep 17 00:00:00 2001 From: Lauren Tan Date: Fri, 11 Aug 2023 13:31:06 -0400 Subject: [PATCH] [ez] ComponentDeclaration transforms only into FunctionDeclaration ComponentDeclarations can only be transformed into FunctionDeclarations, so the types were wrong --- .../babel-plugin-react-forget/src/Entrypoint/Program.ts | 2 +- .../src/Utils/ComponentDeclaration.ts | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) 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; }