mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Add ComponentDeclaration util
This commit is contained in:
@@ -14,6 +14,7 @@ import {
|
||||
ErrorSeverity,
|
||||
} from "../CompilerError";
|
||||
import { GeneratedSource } from "../HIR";
|
||||
import { isComponentDeclaration } from "../Utils/ComponentDeclaration";
|
||||
import { getOrInsertDefault } from "../Utils/utils";
|
||||
import { addInstrumentForget } from "./Instrumentation";
|
||||
import { ExternalFunction, PluginOptions, parsePluginOptions } from "./Options";
|
||||
@@ -330,9 +331,7 @@ function shouldVisitNode(
|
||||
pass: CompilerPass
|
||||
): boolean {
|
||||
if (pass.opts.enableOnlyOnReactScript) {
|
||||
// Typescript gets angry about lookup the magic prop
|
||||
let fnAny = fn as any;
|
||||
if (!fnAny.node.__componentDeclaration) {
|
||||
if (!isComponentDeclaration(fn.node)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import * as t from "@babel/types";
|
||||
|
||||
type FunctionDeclOrExpr = t.FunctionDeclaration | t.ArrowFunctionExpression;
|
||||
type ComponentDeclaration = FunctionDeclOrExpr & {
|
||||
__componentDeclaration: boolean;
|
||||
};
|
||||
|
||||
export function isComponentDeclaration(
|
||||
node: FunctionDeclOrExpr
|
||||
): node is ComponentDeclaration {
|
||||
return Object.prototype.hasOwnProperty.call(node, "__componentDeclaration");
|
||||
}
|
||||
|
||||
export function parseComponentDeclaration(
|
||||
node: FunctionDeclOrExpr
|
||||
): ComponentDeclaration | null {
|
||||
return isComponentDeclaration(node) ? node : null;
|
||||
}
|
||||
Reference in New Issue
Block a user