UNPKG

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