(value: string | undefined, jsx: boolean)
| 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. |
no test coverage detected