mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[ez] ComponentDeclaration transforms only into FunctionDeclaration
ComponentDeclarations can only be transformed into FunctionDeclarations, so the types were wrong
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
+3
-4
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user