[ez] ComponentDeclaration transforms only into FunctionDeclaration
ComponentDeclarations can only be transformed into FunctionDeclarations, so the types were wrong
Lauren Tan committed
Aug 11, 2023 at 13:31 UTC
6c719f62a07114cfa23631e79a8962f6c770ddda
2 files changed
+4
-5
compiler/forget/packages/babel-plugin-react-forget/src/Entrypoint/Program.ts
+1
-1
@@ -330,7 +330,7 @@ function shouldVisitNode(
330
fn: NodePath<t.FunctionDeclaration | t.ArrowFunctionExpression>,
331
pass: CompilerPass
332
): boolean {
333
- if (pass.opts.enableOnlyOnReactScript) {
333
+ if (pass.opts.enableOnlyOnReactScript && fn.isFunctionDeclaration()) {
334
return isComponentDeclaration(fn.node);
335
}
336
compiler/forget/packages/babel-plugin-react-forget/src/Utils/ComponentDeclaration.ts
+3
-4
@@ -1,18 +1,17 @@
1
import * as t from "@babel/types";
2
3
-type FunctionDeclOrExpr = t.FunctionDeclaration | t.ArrowFunctionExpression;
4
-type ComponentDeclaration = FunctionDeclOrExpr & {
3
+export type ComponentDeclaration = t.FunctionDeclaration & {
4
__componentDeclaration: boolean;
5
};
6
7
export function isComponentDeclaration(
9
- node: FunctionDeclOrExpr
8
+ node: t.FunctionDeclaration
9
): node is ComponentDeclaration {
10
return Object.prototype.hasOwnProperty.call(node, "__componentDeclaration");
11
}
12
13
export function parseComponentDeclaration(
15
- node: FunctionDeclOrExpr
14
+ node: t.FunctionDeclaration
15
): ComponentDeclaration | null {
16
return isComponentDeclaration(node) ? node : null;
17
}