react-is.development.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /**
  2. * @license React
  3. * react-is.development.js
  4. *
  5. * Copyright (c) Facebook, Inc. and its affiliates.
  6. *
  7. * This source code is licensed under the MIT license found in the
  8. * LICENSE file in the root directory of this source tree.
  9. */
  10. 'use strict';
  11. if (process.env.NODE_ENV !== "production") {
  12. (function() {
  13. 'use strict';
  14. // ATTENTION
  15. // When adding new symbols to this file,
  16. // Please consider also adding to 'react-devtools-shared/src/backend/ReactSymbols'
  17. // The Symbol used to tag the ReactElement-like types.
  18. var REACT_ELEMENT_TYPE = Symbol.for('react.element');
  19. var REACT_PORTAL_TYPE = Symbol.for('react.portal');
  20. var REACT_FRAGMENT_TYPE = Symbol.for('react.fragment');
  21. var REACT_STRICT_MODE_TYPE = Symbol.for('react.strict_mode');
  22. var REACT_PROFILER_TYPE = Symbol.for('react.profiler');
  23. var REACT_PROVIDER_TYPE = Symbol.for('react.provider');
  24. var REACT_CONTEXT_TYPE = Symbol.for('react.context');
  25. var REACT_SERVER_CONTEXT_TYPE = Symbol.for('react.server_context');
  26. var REACT_FORWARD_REF_TYPE = Symbol.for('react.forward_ref');
  27. var REACT_SUSPENSE_TYPE = Symbol.for('react.suspense');
  28. var REACT_SUSPENSE_LIST_TYPE = Symbol.for('react.suspense_list');
  29. var REACT_MEMO_TYPE = Symbol.for('react.memo');
  30. var REACT_LAZY_TYPE = Symbol.for('react.lazy');
  31. var REACT_OFFSCREEN_TYPE = Symbol.for('react.offscreen');
  32. // -----------------------------------------------------------------------------
  33. var enableScopeAPI = false; // Experimental Create Event Handle API.
  34. var enableCacheElement = false;
  35. var enableTransitionTracing = false; // No known bugs, but needs performance testing
  36. var enableLegacyHidden = false; // Enables unstable_avoidThisFallback feature in Fiber
  37. // stuff. Intended to enable React core members to more easily debug scheduling
  38. // issues in DEV builds.
  39. var enableDebugTracing = false; // Track which Fiber(s) schedule render work.
  40. var REACT_MODULE_REFERENCE;
  41. {
  42. REACT_MODULE_REFERENCE = Symbol.for('react.module.reference');
  43. }
  44. function isValidElementType(type) {
  45. if (typeof type === 'string' || typeof type === 'function') {
  46. return true;
  47. } // Note: typeof might be other than 'symbol' or 'number' (e.g. if it's a polyfill).
  48. if (type === REACT_FRAGMENT_TYPE || type === REACT_PROFILER_TYPE || enableDebugTracing || type === REACT_STRICT_MODE_TYPE || type === REACT_SUSPENSE_TYPE || type === REACT_SUSPENSE_LIST_TYPE || enableLegacyHidden || type === REACT_OFFSCREEN_TYPE || enableScopeAPI || enableCacheElement || enableTransitionTracing ) {
  49. return true;
  50. }
  51. if (typeof type === 'object' && type !== null) {
  52. if (type.$$typeof === REACT_LAZY_TYPE || type.$$typeof === REACT_MEMO_TYPE || type.$$typeof === REACT_PROVIDER_TYPE || type.$$typeof === REACT_CONTEXT_TYPE || type.$$typeof === REACT_FORWARD_REF_TYPE || // This needs to include all possible module reference object
  53. // types supported by any Flight configuration anywhere since
  54. // we don't know which Flight build this will end up being used
  55. // with.
  56. type.$$typeof === REACT_MODULE_REFERENCE || type.getModuleId !== undefined) {
  57. return true;
  58. }
  59. }
  60. return false;
  61. }
  62. function typeOf(object) {
  63. if (typeof object === 'object' && object !== null) {
  64. var $$typeof = object.$$typeof;
  65. switch ($$typeof) {
  66. case REACT_ELEMENT_TYPE:
  67. var type = object.type;
  68. switch (type) {
  69. case REACT_FRAGMENT_TYPE:
  70. case REACT_PROFILER_TYPE:
  71. case REACT_STRICT_MODE_TYPE:
  72. case REACT_SUSPENSE_TYPE:
  73. case REACT_SUSPENSE_LIST_TYPE:
  74. return type;
  75. default:
  76. var $$typeofType = type && type.$$typeof;
  77. switch ($$typeofType) {
  78. case REACT_SERVER_CONTEXT_TYPE:
  79. case REACT_CONTEXT_TYPE:
  80. case REACT_FORWARD_REF_TYPE:
  81. case REACT_LAZY_TYPE:
  82. case REACT_MEMO_TYPE:
  83. case REACT_PROVIDER_TYPE:
  84. return $$typeofType;
  85. default:
  86. return $$typeof;
  87. }
  88. }
  89. case REACT_PORTAL_TYPE:
  90. return $$typeof;
  91. }
  92. }
  93. return undefined;
  94. }
  95. var ContextConsumer = REACT_CONTEXT_TYPE;
  96. var ContextProvider = REACT_PROVIDER_TYPE;
  97. var Element = REACT_ELEMENT_TYPE;
  98. var ForwardRef = REACT_FORWARD_REF_TYPE;
  99. var Fragment = REACT_FRAGMENT_TYPE;
  100. var Lazy = REACT_LAZY_TYPE;
  101. var Memo = REACT_MEMO_TYPE;
  102. var Portal = REACT_PORTAL_TYPE;
  103. var Profiler = REACT_PROFILER_TYPE;
  104. var StrictMode = REACT_STRICT_MODE_TYPE;
  105. var Suspense = REACT_SUSPENSE_TYPE;
  106. var SuspenseList = REACT_SUSPENSE_LIST_TYPE;
  107. var hasWarnedAboutDeprecatedIsAsyncMode = false;
  108. var hasWarnedAboutDeprecatedIsConcurrentMode = false; // AsyncMode should be deprecated
  109. function isAsyncMode(object) {
  110. {
  111. if (!hasWarnedAboutDeprecatedIsAsyncMode) {
  112. hasWarnedAboutDeprecatedIsAsyncMode = true; // Using console['warn'] to evade Babel and ESLint
  113. console['warn']('The ReactIs.isAsyncMode() alias has been deprecated, ' + 'and will be removed in React 18+.');
  114. }
  115. }
  116. return false;
  117. }
  118. function isConcurrentMode(object) {
  119. {
  120. if (!hasWarnedAboutDeprecatedIsConcurrentMode) {
  121. hasWarnedAboutDeprecatedIsConcurrentMode = true; // Using console['warn'] to evade Babel and ESLint
  122. console['warn']('The ReactIs.isConcurrentMode() alias has been deprecated, ' + 'and will be removed in React 18+.');
  123. }
  124. }
  125. return false;
  126. }
  127. function isContextConsumer(object) {
  128. return typeOf(object) === REACT_CONTEXT_TYPE;
  129. }
  130. function isContextProvider(object) {
  131. return typeOf(object) === REACT_PROVIDER_TYPE;
  132. }
  133. function isElement(object) {
  134. return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
  135. }
  136. function isForwardRef(object) {
  137. return typeOf(object) === REACT_FORWARD_REF_TYPE;
  138. }
  139. function isFragment(object) {
  140. return typeOf(object) === REACT_FRAGMENT_TYPE;
  141. }
  142. function isLazy(object) {
  143. return typeOf(object) === REACT_LAZY_TYPE;
  144. }
  145. function isMemo(object) {
  146. return typeOf(object) === REACT_MEMO_TYPE;
  147. }
  148. function isPortal(object) {
  149. return typeOf(object) === REACT_PORTAL_TYPE;
  150. }
  151. function isProfiler(object) {
  152. return typeOf(object) === REACT_PROFILER_TYPE;
  153. }
  154. function isStrictMode(object) {
  155. return typeOf(object) === REACT_STRICT_MODE_TYPE;
  156. }
  157. function isSuspense(object) {
  158. return typeOf(object) === REACT_SUSPENSE_TYPE;
  159. }
  160. function isSuspenseList(object) {
  161. return typeOf(object) === REACT_SUSPENSE_LIST_TYPE;
  162. }
  163. exports.ContextConsumer = ContextConsumer;
  164. exports.ContextProvider = ContextProvider;
  165. exports.Element = Element;
  166. exports.ForwardRef = ForwardRef;
  167. exports.Fragment = Fragment;
  168. exports.Lazy = Lazy;
  169. exports.Memo = Memo;
  170. exports.Portal = Portal;
  171. exports.Profiler = Profiler;
  172. exports.StrictMode = StrictMode;
  173. exports.Suspense = Suspense;
  174. exports.SuspenseList = SuspenseList;
  175. exports.isAsyncMode = isAsyncMode;
  176. exports.isConcurrentMode = isConcurrentMode;
  177. exports.isContextConsumer = isContextConsumer;
  178. exports.isContextProvider = isContextProvider;
  179. exports.isElement = isElement;
  180. exports.isForwardRef = isForwardRef;
  181. exports.isFragment = isFragment;
  182. exports.isLazy = isLazy;
  183. exports.isMemo = isMemo;
  184. exports.isPortal = isPortal;
  185. exports.isProfiler = isProfiler;
  186. exports.isStrictMode = isStrictMode;
  187. exports.isSuspense = isSuspense;
  188. exports.isSuspenseList = isSuspenseList;
  189. exports.isValidElementType = isValidElementType;
  190. exports.typeOf = typeOf;
  191. })();
  192. }