Skip to content

Commit 92475da

Browse files
refactor(oxlint-plugin): derive HOC_NAMES_FOR_MEMOISATION from REACT_HOC_NAMES
build-same-file-memo-registry.ts maintained its own `HOC_NAMES_FOR_MEMOISATION` that hand-redeclared the four React-native HOCs (memo / forwardRef / React.memo / React.forwardRef) before extending with the third-party ones (observer / observable / lazy / withTracking). Derive the React-side prefix from the canonical `REACT_HOC_NAMES` constant in constants/react.ts via spread. Adding a new React-native HOC in one place now extends both detectors automatically. Behaviour-neutral. Co-authored-by: Aiden Bai <aidenybai@users.noreply.github.com>
1 parent 9426276 commit 92475da

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

packages/oxlint-plugin-react-doctor/src/plugin/utils/build-same-file-memo-registry.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { REACT_HOC_NAMES } from "../constants/react.js";
12
import type { EsTreeNode } from "./es-tree-node.js";
23
import { isNodeOfType } from "./is-node-of-type.js";
34

@@ -9,11 +10,13 @@ import { isNodeOfType } from "./is-node-of-type.js";
910
// that premise doesn't hold — the parent re-renders unconditionally.
1011
export type MemoStatus = "memoised" | "not-memoised" | "unknown";
1112

13+
// Extends `REACT_HOC_NAMES` (the React-native pair {memo, forwardRef,
14+
// React.memo, React.forwardRef}) with the third-party wrappers that
15+
// produce memoised output: MobX `observer`, legend-state `observable`,
16+
// React.lazy, and the `withTracking` HOC. Adding a new React-side HOC
17+
// to `REACT_HOC_NAMES` automatically extends this set too.
1218
const HOC_NAMES_FOR_MEMOISATION: ReadonlySet<string> = new Set([
13-
"memo",
14-
"React.memo",
15-
"forwardRef",
16-
"React.forwardRef",
19+
...REACT_HOC_NAMES,
1720
"observer", // MobX
1821
"observable", // legend-state
1922
"lazy",

0 commit comments

Comments
 (0)