MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / componentName

Function componentName

src/resolution/frameworks/react.ts:1074–1084  ·  view source on GitHub ↗
(value: string | undefined, jsx: boolean)

Source from the content-addressed store, hash-verified

1072 // renders; the first element inside it is.
1073 const WRAPPER = /^(?:Suspense|ErrorBoundary|\w*(?:Guard|Provider|Wrapper|Route)|(?:Protected|Private|Auth|Require\w*)\w*)$/;
1074 const componentName = (value: string | undefined, jsx: boolean): string | undefined => {
1075 if (!value) return undefined;
1076 if (!jsx) return /^\s*([A-Z][\w]*)\s*$/.exec(value)?.[1];
1077 const inner = value.replace(/^\s*(?:\(\s*)?/, '');
1078 if (!/^<\s*[A-Z]/.test(inner)) return undefined;
1079 const { own, props } = elementTags(inner);
1080 const content = (t: string): boolean => !WRAPPER.test(t) && t !== 'Outlet';
1081 // Then a page handed to a guard as a prop (`<PrivateRoute component={<Profile />} />`),
1082 // then the innermost wrapper: `<RequireAuth><Outlet /></RequireAuth>` renders the guard.
1083 return own.find(content) ?? props.find(content) ?? [...own].reverse().find((t) => t !== 'Outlet') ?? own[0];
1084 };
1085 // The component an `element` shows, `Outlet` included.
1086 const elementTag = (value: string | undefined): string | undefined => componentName(value, true);
1087 // The page an `element` shows: `element={<Outlet />}` renders the route inside it and nothing of its own.

Callers 3

elementTagFunction · 0.85
unitFunction · 0.85
jsxFunction · 0.85

Calls 2

elementTagsFunction · 0.85
execMethod · 0.65

Tested by

no test coverage detected