const hasSymbol = typeof Symbol === 'function' && Symbol.for; // const REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for('react.element') : 0xeac7; const REACT_PORTAL_TYPE = hasSymbol ? Symbol.for('react.portal') : 0xeaca; const REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for('react.fragment') : 0xeacb; const REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol.for('react.strict_mode') : 0xeacc; const REACT_PROFILER_TYPE = hasSymbol ? Symbol.for('react.profiler') : 0xead2; const REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for('react.provider') : 0xeacd; const REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace; // const REACT_CONCURRENT_MODE_TYPE = hasSymbol ? Symbol.for('react.concurrent_mode') : 0xeacf; const REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0; const REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for('react.suspense') : 0xead1; const REACT_SUSPENSE_LIST_TYPE = hasSymbol ? Symbol.for('react.suspense_list') : 0xead8; const REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3; const REACT_LAZY_TYPE = hasSymbol ? Symbol.for('react.lazy') : 0xead4; const REACT_BLOCK_TYPE = hasSymbol ? Symbol.for('react.block') : 0xead9; // const REACT_FUNDAMENTAL_TYPE = hasSymbol ? Symbol.for('react.fundamental') : 0xead5; // const REACT_RESPONDER_TYPE = hasSymbol ? Symbol.for('react.responder') : 0xead6; // const REACT_SCOPE_TYPE = hasSymbol ? Symbol.for('react.scope') : 0xead7; function getWrappedName(outerType: any, innerType: any, wrapperName: any) { const functionName = innerType.displayName || innerType.name || ''; return ( outerType.displayName || (functionName !== '' ? wrapperName + '(' + functionName + ')' : wrapperName) ); } function refineResolvedLazyComponent(lazyComponent: any) { return lazyComponent._status === 1 ? lazyComponent._result : null; } export default function getComponentName(type: any): string { if (type == null) { return ''; } if (typeof type === 'function') { return type.displayName || type.name || null; } if (typeof type === 'string') { return type; } switch (type) { case REACT_FRAGMENT_TYPE: return 'Fragment'; case REACT_PORTAL_TYPE: return 'Portal'; case REACT_PROFILER_TYPE: return 'Profiler'; case REACT_STRICT_MODE_TYPE: return 'StrictMode'; case REACT_SUSPENSE_TYPE: return 'Suspense'; case REACT_SUSPENSE_LIST_TYPE: return 'SuspenseList'; } if (typeof type === 'object') { switch (type.$$typeof) { case REACT_CONTEXT_TYPE: return 'Context.Consumer'; case REACT_PROVIDER_TYPE: return 'Context.Provider'; case REACT_FORWARD_REF_TYPE: return getWrappedName(type, type.render, 'ForwardRef'); case REACT_MEMO_TYPE: return getComponentName(type.type); case REACT_BLOCK_TYPE: return getComponentName(type.render); case REACT_LAZY_TYPE: let resolvedThenable = refineResolvedLazyComponent(type); if (resolvedThenable) { return getComponentName(resolvedThenable); } break; } } return ''; }