1. /**
    
  2.  * Copyright (c) Meta Platforms, Inc. and affiliates.
    
  3.  *
    
  4.  * This source code is licensed under the MIT license found in the
    
  5.  * LICENSE file in the root directory of this source tree.
    
  6.  *
    
  7.  * @flow
    
  8.  */
    
  9. 
    
  10. 'use strict';
    
  11. 
    
  12. import {
    
  13.   REACT_CONTEXT_TYPE,
    
  14.   REACT_SERVER_CONTEXT_TYPE,
    
  15.   REACT_ELEMENT_TYPE,
    
  16.   REACT_FORWARD_REF_TYPE,
    
  17.   REACT_FRAGMENT_TYPE,
    
  18.   REACT_LAZY_TYPE,
    
  19.   REACT_MEMO_TYPE,
    
  20.   REACT_PORTAL_TYPE,
    
  21.   REACT_PROFILER_TYPE,
    
  22.   REACT_PROVIDER_TYPE,
    
  23.   REACT_STRICT_MODE_TYPE,
    
  24.   REACT_SUSPENSE_TYPE,
    
  25.   REACT_SUSPENSE_LIST_TYPE,
    
  26. } from 'shared/ReactSymbols';
    
  27. import isValidElementType from 'shared/isValidElementType';
    
  28. 
    
  29. export function typeOf(object: any): mixed {
    
  30.   if (typeof object === 'object' && object !== null) {
    
  31.     const $$typeof = object.$$typeof;
    
  32.     switch ($$typeof) {
    
  33.       case REACT_ELEMENT_TYPE:
    
  34.         const type = object.type;
    
  35. 
    
  36.         switch (type) {
    
  37.           case REACT_FRAGMENT_TYPE:
    
  38.           case REACT_PROFILER_TYPE:
    
  39.           case REACT_STRICT_MODE_TYPE:
    
  40.           case REACT_SUSPENSE_TYPE:
    
  41.           case REACT_SUSPENSE_LIST_TYPE:
    
  42.             return type;
    
  43.           default:
    
  44.             const $$typeofType = type && type.$$typeof;
    
  45. 
    
  46.             switch ($$typeofType) {
    
  47.               case REACT_SERVER_CONTEXT_TYPE:
    
  48.               case REACT_CONTEXT_TYPE:
    
  49.               case REACT_FORWARD_REF_TYPE:
    
  50.               case REACT_LAZY_TYPE:
    
  51.               case REACT_MEMO_TYPE:
    
  52.               case REACT_PROVIDER_TYPE:
    
  53.                 return $$typeofType;
    
  54.               default:
    
  55.                 return $$typeof;
    
  56.             }
    
  57.         }
    
  58.       case REACT_PORTAL_TYPE:
    
  59.         return $$typeof;
    
  60.     }
    
  61.   }
    
  62. 
    
  63.   return undefined;
    
  64. }
    
  65. 
    
  66. export const ContextConsumer = REACT_CONTEXT_TYPE;
    
  67. export const ContextProvider = REACT_PROVIDER_TYPE;
    
  68. export const Element = REACT_ELEMENT_TYPE;
    
  69. export const ForwardRef = REACT_FORWARD_REF_TYPE;
    
  70. export const Fragment = REACT_FRAGMENT_TYPE;
    
  71. export const Lazy = REACT_LAZY_TYPE;
    
  72. export const Memo = REACT_MEMO_TYPE;
    
  73. export const Portal = REACT_PORTAL_TYPE;
    
  74. export const Profiler = REACT_PROFILER_TYPE;
    
  75. export const StrictMode = REACT_STRICT_MODE_TYPE;
    
  76. export const Suspense = REACT_SUSPENSE_TYPE;
    
  77. export const SuspenseList = REACT_SUSPENSE_LIST_TYPE;
    
  78. 
    
  79. export {isValidElementType};
    
  80. 
    
  81. let hasWarnedAboutDeprecatedIsAsyncMode = false;
    
  82. let hasWarnedAboutDeprecatedIsConcurrentMode = false;
    
  83. 
    
  84. // AsyncMode should be deprecated
    
  85. export function isAsyncMode(object: any): boolean {
    
  86.   if (__DEV__) {
    
  87.     if (!hasWarnedAboutDeprecatedIsAsyncMode) {
    
  88.       hasWarnedAboutDeprecatedIsAsyncMode = true;
    
  89.       // Using console['warn'] to evade Babel and ESLint
    
  90.       console['warn'](
    
  91.         'The ReactIs.isAsyncMode() alias has been deprecated, ' +
    
  92.           'and will be removed in React 18+.',
    
  93.       );
    
  94.     }
    
  95.   }
    
  96.   return false;
    
  97. }
    
  98. export function isConcurrentMode(object: any): boolean {
    
  99.   if (__DEV__) {
    
  100.     if (!hasWarnedAboutDeprecatedIsConcurrentMode) {
    
  101.       hasWarnedAboutDeprecatedIsConcurrentMode = true;
    
  102.       // Using console['warn'] to evade Babel and ESLint
    
  103.       console['warn'](
    
  104.         'The ReactIs.isConcurrentMode() alias has been deprecated, ' +
    
  105.           'and will be removed in React 18+.',
    
  106.       );
    
  107.     }
    
  108.   }
    
  109.   return false;
    
  110. }
    
  111. export function isContextConsumer(object: any): boolean {
    
  112.   return typeOf(object) === REACT_CONTEXT_TYPE;
    
  113. }
    
  114. export function isContextProvider(object: any): boolean {
    
  115.   return typeOf(object) === REACT_PROVIDER_TYPE;
    
  116. }
    
  117. export function isElement(object: any): boolean {
    
  118.   return (
    
  119.     typeof object === 'object' &&
    
  120.     object !== null &&
    
  121.     object.$$typeof === REACT_ELEMENT_TYPE
    
  122.   );
    
  123. }
    
  124. export function isForwardRef(object: any): boolean {
    
  125.   return typeOf(object) === REACT_FORWARD_REF_TYPE;
    
  126. }
    
  127. export function isFragment(object: any): boolean {
    
  128.   return typeOf(object) === REACT_FRAGMENT_TYPE;
    
  129. }
    
  130. export function isLazy(object: any): boolean {
    
  131.   return typeOf(object) === REACT_LAZY_TYPE;
    
  132. }
    
  133. export function isMemo(object: any): boolean {
    
  134.   return typeOf(object) === REACT_MEMO_TYPE;
    
  135. }
    
  136. export function isPortal(object: any): boolean {
    
  137.   return typeOf(object) === REACT_PORTAL_TYPE;
    
  138. }
    
  139. export function isProfiler(object: any): boolean {
    
  140.   return typeOf(object) === REACT_PROFILER_TYPE;
    
  141. }
    
  142. export function isStrictMode(object: any): boolean {
    
  143.   return typeOf(object) === REACT_STRICT_MODE_TYPE;
    
  144. }
    
  145. export function isSuspense(object: any): boolean {
    
  146.   return typeOf(object) === REACT_SUSPENSE_TYPE;
    
  147. }
    
  148. export function isSuspenseList(object: any): boolean {
    
  149.   return typeOf(object) === REACT_SUSPENSE_LIST_TYPE;
    
  150. }