UNPKG

6.98 kBJavaScriptView Raw
1/** @license React v16.13.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
10'use strict';
11
12
13
14if (process.env.NODE_ENV !== "production") {
15 (function() {
16'use strict';
17
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.
20var hasSymbol = typeof Symbol === 'function' && Symbol.for;
21var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for('react.element') : 0xeac7;
22var REACT_PORTAL_TYPE = hasSymbol ? Symbol.for('react.portal') : 0xeaca;
23var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for('react.fragment') : 0xeacb;
24var REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol.for('react.strict_mode') : 0xeacc;
25var REACT_PROFILER_TYPE = hasSymbol ? Symbol.for('react.profiler') : 0xead2;
26var REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for('react.provider') : 0xeacd;
27var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace; // TODO: We don't use AsyncMode or ConcurrentMode anymore. They were temporary
28// (unstable) APIs that have been removed. Can we remove the symbols?
29
30var REACT_ASYNC_MODE_TYPE = hasSymbol ? Symbol.for('react.async_mode') : 0xeacf;
31var REACT_CONCURRENT_MODE_TYPE = hasSymbol ? Symbol.for('react.concurrent_mode') : 0xeacf;
32var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0;
33var REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for('react.suspense') : 0xead1;
34var REACT_SUSPENSE_LIST_TYPE = hasSymbol ? Symbol.for('react.suspense_list') : 0xead8;
35var REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3;
36var REACT_LAZY_TYPE = hasSymbol ? Symbol.for('react.lazy') : 0xead4;
37var REACT_BLOCK_TYPE = hasSymbol ? Symbol.for('react.block') : 0xead9;
38var REACT_FUNDAMENTAL_TYPE = hasSymbol ? Symbol.for('react.fundamental') : 0xead5;
39var REACT_RESPONDER_TYPE = hasSymbol ? Symbol.for('react.responder') : 0xead6;
40var REACT_SCOPE_TYPE = hasSymbol ? Symbol.for('react.scope') : 0xead7;
41
42function isValidElementType(type) {
43 return typeof type === 'string' || typeof type === 'function' || // Note: its typeof might be other than 'symbol' or 'number' if it's a polyfill.
44 type === REACT_FRAGMENT_TYPE || type === REACT_CONCURRENT_MODE_TYPE || type === REACT_PROFILER_TYPE || type === REACT_STRICT_MODE_TYPE || type === REACT_SUSPENSE_TYPE || type === REACT_SUSPENSE_LIST_TYPE || typeof type === 'object' && type !== null && (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_RESPONDER_TYPE || type.$$typeof === REACT_SCOPE_TYPE || type.$$typeof === REACT_BLOCK_TYPE);
45}
46
47function typeOf(object) {
48 if (typeof object === 'object' && object !== null) {
49 var $$typeof = object.$$typeof;
50
51 switch ($$typeof) {
52 case REACT_ELEMENT_TYPE:
53 var type = object.type;
54
55 switch (type) {
56 case REACT_ASYNC_MODE_TYPE:
57 case REACT_CONCURRENT_MODE_TYPE:
58 case REACT_FRAGMENT_TYPE:
59 case REACT_PROFILER_TYPE:
60 case REACT_STRICT_MODE_TYPE:
61 case REACT_SUSPENSE_TYPE:
62 return type;
63
64 default:
65 var $$typeofType = type && type.$$typeof;
66
67 switch ($$typeofType) {
68 case REACT_CONTEXT_TYPE:
69 case REACT_FORWARD_REF_TYPE:
70 case REACT_LAZY_TYPE:
71 case REACT_MEMO_TYPE:
72 case REACT_PROVIDER_TYPE:
73 return $$typeofType;
74
75 default:
76 return $$typeof;
77 }
78
79 }
80
81 case REACT_PORTAL_TYPE:
82 return $$typeof;
83 }
84 }
85
86 return undefined;
87} // AsyncMode is deprecated along with isAsyncMode
88
89var AsyncMode = REACT_ASYNC_MODE_TYPE;
90var ConcurrentMode = REACT_CONCURRENT_MODE_TYPE;
91var ContextConsumer = REACT_CONTEXT_TYPE;
92var ContextProvider = REACT_PROVIDER_TYPE;
93var Element = REACT_ELEMENT_TYPE;
94var ForwardRef = REACT_FORWARD_REF_TYPE;
95var Fragment = REACT_FRAGMENT_TYPE;
96var Lazy = REACT_LAZY_TYPE;
97var Memo = REACT_MEMO_TYPE;
98var Portal = REACT_PORTAL_TYPE;
99var Profiler = REACT_PROFILER_TYPE;
100var StrictMode = REACT_STRICT_MODE_TYPE;
101var Suspense = REACT_SUSPENSE_TYPE;
102var hasWarnedAboutDeprecatedIsAsyncMode = false; // AsyncMode should be deprecated
103
104function isAsyncMode(object) {
105 {
106 if (!hasWarnedAboutDeprecatedIsAsyncMode) {
107 hasWarnedAboutDeprecatedIsAsyncMode = true; // Using console['warn'] to evade Babel and ESLint
108
109 console['warn']('The ReactIs.isAsyncMode() alias has been deprecated, ' + 'and will be removed in React 17+. Update your code to use ' + 'ReactIs.isConcurrentMode() instead. It has the exact same API.');
110 }
111 }
112
113 return isConcurrentMode(object) || typeOf(object) === REACT_ASYNC_MODE_TYPE;
114}
115function isConcurrentMode(object) {
116 return typeOf(object) === REACT_CONCURRENT_MODE_TYPE;
117}
118function isContextConsumer(object) {
119 return typeOf(object) === REACT_CONTEXT_TYPE;
120}
121function isContextProvider(object) {
122 return typeOf(object) === REACT_PROVIDER_TYPE;
123}
124function isElement(object) {
125 return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
126}
127function isForwardRef(object) {
128 return typeOf(object) === REACT_FORWARD_REF_TYPE;
129}
130function isFragment(object) {
131 return typeOf(object) === REACT_FRAGMENT_TYPE;
132}
133function isLazy(object) {
134 return typeOf(object) === REACT_LAZY_TYPE;
135}
136function isMemo(object) {
137 return typeOf(object) === REACT_MEMO_TYPE;
138}
139function isPortal(object) {
140 return typeOf(object) === REACT_PORTAL_TYPE;
141}
142function isProfiler(object) {
143 return typeOf(object) === REACT_PROFILER_TYPE;
144}
145function isStrictMode(object) {
146 return typeOf(object) === REACT_STRICT_MODE_TYPE;
147}
148function isSuspense(object) {
149 return typeOf(object) === REACT_SUSPENSE_TYPE;
150}
151
152exports.AsyncMode = AsyncMode;
153exports.ConcurrentMode = ConcurrentMode;
154exports.ContextConsumer = ContextConsumer;
155exports.ContextProvider = ContextProvider;
156exports.Element = Element;
157exports.ForwardRef = ForwardRef;
158exports.Fragment = Fragment;
159exports.Lazy = Lazy;
160exports.Memo = Memo;
161exports.Portal = Portal;
162exports.Profiler = Profiler;
163exports.StrictMode = StrictMode;
164exports.Suspense = Suspense;
165exports.isAsyncMode = isAsyncMode;
166exports.isConcurrentMode = isConcurrentMode;
167exports.isContextConsumer = isContextConsumer;
168exports.isContextProvider = isContextProvider;
169exports.isElement = isElement;
170exports.isForwardRef = isForwardRef;
171exports.isFragment = isFragment;
172exports.isLazy = isLazy;
173exports.isMemo = isMemo;
174exports.isPortal = isPortal;
175exports.isProfiler = isProfiler;
176exports.isStrictMode = isStrictMode;
177exports.isSuspense = isSuspense;
178exports.isValidElementType = isValidElementType;
179exports.typeOf = typeOf;
180 })();
181}