UNPKG

7.57 kBJavaScriptView Raw
1/** @license React v17.0.2
2 * react-is.development.js
3 *
4 * Copyright (c) Facebook, Inc. and its affiliates.
5 *
6 * This source code is licensed under the MIT license found in the
7 * LICENSE file in the root directory of this source tree.
8 */
9
10'use strict';
11
12if (process.env.NODE_ENV !== "production") {
13 (function() {
14'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. If there is no native Symbol
20// nor polyfill, then a plain number is used for performance.
21var REACT_ELEMENT_TYPE = 0xeac7;
22var REACT_PORTAL_TYPE = 0xeaca;
23var REACT_FRAGMENT_TYPE = 0xeacb;
24var REACT_STRICT_MODE_TYPE = 0xeacc;
25var REACT_PROFILER_TYPE = 0xead2;
26var REACT_PROVIDER_TYPE = 0xeacd;
27var REACT_CONTEXT_TYPE = 0xeace;
28var REACT_FORWARD_REF_TYPE = 0xead0;
29var REACT_SUSPENSE_TYPE = 0xead1;
30var REACT_SUSPENSE_LIST_TYPE = 0xead8;
31var REACT_MEMO_TYPE = 0xead3;
32var REACT_LAZY_TYPE = 0xead4;
33var REACT_BLOCK_TYPE = 0xead9;
34var REACT_SERVER_BLOCK_TYPE = 0xeada;
35var REACT_FUNDAMENTAL_TYPE = 0xead5;
36var REACT_SCOPE_TYPE = 0xead7;
37var REACT_OPAQUE_ID_TYPE = 0xeae0;
38var REACT_DEBUG_TRACING_MODE_TYPE = 0xeae1;
39var REACT_OFFSCREEN_TYPE = 0xeae2;
40var REACT_LEGACY_HIDDEN_TYPE = 0xeae3;
41
42if (typeof Symbol === 'function' && Symbol.for) {
43 var symbolFor = Symbol.for;
44 REACT_ELEMENT_TYPE = symbolFor('react.element');
45 REACT_PORTAL_TYPE = symbolFor('react.portal');
46 REACT_FRAGMENT_TYPE = symbolFor('react.fragment');
47 REACT_STRICT_MODE_TYPE = symbolFor('react.strict_mode');
48 REACT_PROFILER_TYPE = symbolFor('react.profiler');
49 REACT_PROVIDER_TYPE = symbolFor('react.provider');
50 REACT_CONTEXT_TYPE = symbolFor('react.context');
51 REACT_FORWARD_REF_TYPE = symbolFor('react.forward_ref');
52 REACT_SUSPENSE_TYPE = symbolFor('react.suspense');
53 REACT_SUSPENSE_LIST_TYPE = symbolFor('react.suspense_list');
54 REACT_MEMO_TYPE = symbolFor('react.memo');
55 REACT_LAZY_TYPE = symbolFor('react.lazy');
56 REACT_BLOCK_TYPE = symbolFor('react.block');
57 REACT_SERVER_BLOCK_TYPE = symbolFor('react.server.block');
58 REACT_FUNDAMENTAL_TYPE = symbolFor('react.fundamental');
59 REACT_SCOPE_TYPE = symbolFor('react.scope');
60 REACT_OPAQUE_ID_TYPE = symbolFor('react.opaque.id');
61 REACT_DEBUG_TRACING_MODE_TYPE = symbolFor('react.debug_trace_mode');
62 REACT_OFFSCREEN_TYPE = symbolFor('react.offscreen');
63 REACT_LEGACY_HIDDEN_TYPE = symbolFor('react.legacy_hidden');
64}
65
66// Filter certain DOM attributes (e.g. src, href) if their values are empty strings.
67
68var enableScopeAPI = false; // Experimental Create Event Handle API.
69
70function isValidElementType(type) {
71 if (typeof type === 'string' || typeof type === 'function') {
72 return true;
73 } // Note: typeof might be other than 'symbol' or 'number' (e.g. if it's a polyfill).
74
75
76 if (type === REACT_FRAGMENT_TYPE || type === REACT_PROFILER_TYPE || type === REACT_DEBUG_TRACING_MODE_TYPE || type === REACT_STRICT_MODE_TYPE || type === REACT_SUSPENSE_TYPE || type === REACT_SUSPENSE_LIST_TYPE || type === REACT_LEGACY_HIDDEN_TYPE || enableScopeAPI ) {
77 return true;
78 }
79
80 if (typeof type === 'object' && type !== null) {
81 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 || type.$$typeof === REACT_FUNDAMENTAL_TYPE || type.$$typeof === REACT_BLOCK_TYPE || type[0] === REACT_SERVER_BLOCK_TYPE) {
82 return true;
83 }
84 }
85
86 return false;
87}
88
89function typeOf(object) {
90 if (typeof object === 'object' && object !== null) {
91 var $$typeof = object.$$typeof;
92
93 switch ($$typeof) {
94 case REACT_ELEMENT_TYPE:
95 var type = object.type;
96
97 switch (type) {
98 case REACT_FRAGMENT_TYPE:
99 case REACT_PROFILER_TYPE:
100 case REACT_STRICT_MODE_TYPE:
101 case REACT_SUSPENSE_TYPE:
102 case REACT_SUSPENSE_LIST_TYPE:
103 return type;
104
105 default:
106 var $$typeofType = type && type.$$typeof;
107
108 switch ($$typeofType) {
109 case REACT_CONTEXT_TYPE:
110 case REACT_FORWARD_REF_TYPE:
111 case REACT_LAZY_TYPE:
112 case REACT_MEMO_TYPE:
113 case REACT_PROVIDER_TYPE:
114 return $$typeofType;
115
116 default:
117 return $$typeof;
118 }
119
120 }
121
122 case REACT_PORTAL_TYPE:
123 return $$typeof;
124 }
125 }
126
127 return undefined;
128}
129var ContextConsumer = REACT_CONTEXT_TYPE;
130var ContextProvider = REACT_PROVIDER_TYPE;
131var Element = REACT_ELEMENT_TYPE;
132var ForwardRef = REACT_FORWARD_REF_TYPE;
133var Fragment = REACT_FRAGMENT_TYPE;
134var Lazy = REACT_LAZY_TYPE;
135var Memo = REACT_MEMO_TYPE;
136var Portal = REACT_PORTAL_TYPE;
137var Profiler = REACT_PROFILER_TYPE;
138var StrictMode = REACT_STRICT_MODE_TYPE;
139var Suspense = REACT_SUSPENSE_TYPE;
140var hasWarnedAboutDeprecatedIsAsyncMode = false;
141var hasWarnedAboutDeprecatedIsConcurrentMode = false; // AsyncMode should be deprecated
142
143function isAsyncMode(object) {
144 {
145 if (!hasWarnedAboutDeprecatedIsAsyncMode) {
146 hasWarnedAboutDeprecatedIsAsyncMode = true; // Using console['warn'] to evade Babel and ESLint
147
148 console['warn']('The ReactIs.isAsyncMode() alias has been deprecated, ' + 'and will be removed in React 18+.');
149 }
150 }
151
152 return false;
153}
154function isConcurrentMode(object) {
155 {
156 if (!hasWarnedAboutDeprecatedIsConcurrentMode) {
157 hasWarnedAboutDeprecatedIsConcurrentMode = true; // Using console['warn'] to evade Babel and ESLint
158
159 console['warn']('The ReactIs.isConcurrentMode() alias has been deprecated, ' + 'and will be removed in React 18+.');
160 }
161 }
162
163 return false;
164}
165function isContextConsumer(object) {
166 return typeOf(object) === REACT_CONTEXT_TYPE;
167}
168function isContextProvider(object) {
169 return typeOf(object) === REACT_PROVIDER_TYPE;
170}
171function isElement(object) {
172 return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
173}
174function isForwardRef(object) {
175 return typeOf(object) === REACT_FORWARD_REF_TYPE;
176}
177function isFragment(object) {
178 return typeOf(object) === REACT_FRAGMENT_TYPE;
179}
180function isLazy(object) {
181 return typeOf(object) === REACT_LAZY_TYPE;
182}
183function isMemo(object) {
184 return typeOf(object) === REACT_MEMO_TYPE;
185}
186function isPortal(object) {
187 return typeOf(object) === REACT_PORTAL_TYPE;
188}
189function isProfiler(object) {
190 return typeOf(object) === REACT_PROFILER_TYPE;
191}
192function isStrictMode(object) {
193 return typeOf(object) === REACT_STRICT_MODE_TYPE;
194}
195function isSuspense(object) {
196 return typeOf(object) === REACT_SUSPENSE_TYPE;
197}
198
199exports.ContextConsumer = ContextConsumer;
200exports.ContextProvider = ContextProvider;
201exports.Element = Element;
202exports.ForwardRef = ForwardRef;
203exports.Fragment = Fragment;
204exports.Lazy = Lazy;
205exports.Memo = Memo;
206exports.Portal = Portal;
207exports.Profiler = Profiler;
208exports.StrictMode = StrictMode;
209exports.Suspense = Suspense;
210exports.isAsyncMode = isAsyncMode;
211exports.isConcurrentMode = isConcurrentMode;
212exports.isContextConsumer = isContextConsumer;
213exports.isContextProvider = isContextProvider;
214exports.isElement = isElement;
215exports.isForwardRef = isForwardRef;
216exports.isFragment = isFragment;
217exports.isLazy = isLazy;
218exports.isMemo = isMemo;
219exports.isPortal = isPortal;
220exports.isProfiler = isProfiler;
221exports.isStrictMode = isStrictMode;
222exports.isSuspense = isSuspense;
223exports.isValidElementType = isValidElementType;
224exports.typeOf = typeOf;
225 })();
226}