Skip to content

Commit 6612e01

Browse files
committed
refactor(core): move component init path function to dedicated file
1 parent ce8fac6 commit 6612e01

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed

packages/core/src/component/component-collector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import { DISPLAY_NAME_ASSIGNMENT_SELECTOR } from "../constants";
1414
import { isReactHookCall } from "../hook";
1515
import { DEFAULT_COMPONENT_HINT } from "./component-collector-hint";
1616
import { isValidComponentDefinition } from "./component-definition";
17-
import { getComponentFlagFromInitPath } from "./component-flag";
1817
import { getFunctionComponentId } from "./component-id";
18+
import { getComponentFlagFromInitPath } from "./component-init-path";
1919
import { getComponentNameFromId, hasNoneOrLooseComponentName } from "./component-name";
2020

2121
type FunctionEntry = {
Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import type { FunctionComponent } from "./component-semantic-node";
2-
import * as AST from "@eslint-react/ast";
3-
41
/* eslint-disable perfectionist/sort-objects */
52
export type ComponentFlag = bigint;
63

@@ -12,14 +9,3 @@ export const ComponentFlag = {
129
ForwardRef: 1n << 3n,
1310
Async: 1n << 4n,
1411
};
15-
16-
export function getComponentFlagFromInitPath(initPath: FunctionComponent["initPath"]) {
17-
let flag = ComponentFlag.None;
18-
if (initPath != null && AST.hasCallInFunctionInitPath("memo", initPath)) {
19-
flag |= ComponentFlag.Memo;
20-
}
21-
if (initPath != null && AST.hasCallInFunctionInitPath("forwardRef", initPath)) {
22-
flag |= ComponentFlag.ForwardRef;
23-
}
24-
return flag;
25-
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { FunctionComponent } from "./component-semantic-node";
2+
import * as AST from "@eslint-react/ast";
3+
import { ComponentFlag } from "./component-flag";
4+
5+
export function getComponentFlagFromInitPath(initPath: FunctionComponent["initPath"]) {
6+
let flag = ComponentFlag.None;
7+
if (initPath != null && AST.hasCallInFunctionInitPath("memo", initPath)) {
8+
flag |= ComponentFlag.Memo;
9+
}
10+
if (initPath != null && AST.hasCallInFunctionInitPath("forwardRef", initPath)) {
11+
flag |= ComponentFlag.ForwardRef;
12+
}
13+
return flag;
14+
}

packages/core/src/component/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export * from "./component-collector-hint";
33
export * from "./component-collector-legacy";
44
export * from "./component-flag";
55
export * from "./component-id";
6+
export * from "./component-init-path";
67
export type * from "./component-kind";
78
export * from "./component-lifecycle";
89
export * from "./component-name";

0 commit comments

Comments
 (0)