UNPKG

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