(type: mixed)
| 55 | |
| 56 | class="cm">// Note that the reconciler package should generally prefer to use getComponentNameFromFiber() instead. |
| 57 | export default function getComponentNameFromType(type: mixed): string | null { |
| 58 | if (type == null) { |
| 59 | class="cm">// Host root, text node or just invalid type. |
| 60 | return null; |
| 61 | } |
| 62 | if (typeof type === class="st">'function') { |
| 63 | if ((type: any).$$typeof === REACT_CLIENT_REFERENCE) { |
| 64 | class="cm">// TODO: Create a convention for naming client references with debug info. |
| 65 | return null; |
| 66 | } |
| 67 | return (type: any).displayName || type.name || null; |
| 68 | } |
| 69 | if (typeof type === class="st">'string') { |
| 70 | return type; |
| 71 | } |
| 72 | switch (type) { |
| 73 | case REACT_FRAGMENT_TYPE: |
| 74 | return class="st">'Fragment'; |
| 75 | case REACT_PROFILER_TYPE: |
| 76 | return class="st">'Profiler'; |
| 77 | case REACT_STRICT_MODE_TYPE: |
| 78 | return class="st">'StrictMode'; |
| 79 | case REACT_SUSPENSE_TYPE: |
| 80 | return class="st">'Suspense'; |
| 81 | case REACT_SUSPENSE_LIST_TYPE: |
| 82 | return class="st">'SuspenseList'; |
| 83 | case REACT_ACTIVITY_TYPE: |
| 84 | return class="st">'Activity'; |
| 85 | case REACT_VIEW_TRANSITION_TYPE: |
| 86 | if (enableViewTransition) { |
| 87 | return class="st">'ViewTransition'; |
| 88 | } |
| 89 | class="cm">// Fall through |
| 90 | case REACT_TRACING_MARKER_TYPE: |
| 91 | if (enableTransitionTracing) { |
| 92 | return class="st">'TracingMarker'; |
| 93 | } |
| 94 | } |
| 95 | if (typeof type === class="st">'object') { |
| 96 | if (__DEV__) { |
| 97 | if (typeof (type: any).tag === class="st">'number') { |
| 98 | console.error( |
| 99 | class="st">'Received an unexpected object in getComponentNameFromType(). ' + |
| 100 | class="st">'This is likely a bug in React. Please file an issue.', |
| 101 | ); |
| 102 | } |
| 103 | } |
| 104 | switch (type.$$typeof) { |
| 105 | case REACT_PORTAL_TYPE: |
| 106 | return class="st">'Portal'; |
| 107 | case REACT_CONTEXT_TYPE: |
| 108 | const context: ReactContext<any> = (type: any); |
| 109 | return getContextName(context); |
| 110 | case REACT_CONSUMER_TYPE: |
| 111 | const consumer: ReactConsumerType<any> = (type: any); |
| 112 | return getContextName(consumer._context) + class="st">'.Consumer'; |
| 113 | case REACT_FORWARD_REF_TYPE: |
| 114 | return getWrappedName(type, type.render, class="st">'ForwardRef'); |
no test coverage detected