UNPKG

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