UNPKG

8.59 kBJavaScriptView Raw
1/** @license React v16.9.0
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
18Object.defineProperty(exports, '__esModule', { value: true });
19
20// The Symbol used to tag the ReactElement-like types. If there is no native Symbol
21// nor polyfill, then a plain number is used for performance.
22var hasSymbol = typeof Symbol === 'function' && Symbol.for;
23
24var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for('react.element') : 0xeac7;
25var REACT_PORTAL_TYPE = hasSymbol ? Symbol.for('react.portal') : 0xeaca;
26var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for('react.fragment') : 0xeacb;
27var REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol.for('react.strict_mode') : 0xeacc;
28var REACT_PROFILER_TYPE = hasSymbol ? Symbol.for('react.profiler') : 0xead2;
29var REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for('react.provider') : 0xeacd;
30var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace;
31// TODO: We don't use AsyncMode or ConcurrentMode anymore. They were temporary
32// (unstable) APIs that have been removed. Can we remove the symbols?
33var REACT_ASYNC_MODE_TYPE = hasSymbol ? Symbol.for('react.async_mode') : 0xeacf;
34var REACT_CONCURRENT_MODE_TYPE = hasSymbol ? Symbol.for('react.concurrent_mode') : 0xeacf;
35var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0;
36var REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for('react.suspense') : 0xead1;
37var REACT_SUSPENSE_LIST_TYPE = hasSymbol ? Symbol.for('react.suspense_list') : 0xead8;
38var REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3;
39var REACT_LAZY_TYPE = hasSymbol ? Symbol.for('react.lazy') : 0xead4;
40var REACT_FUNDAMENTAL_TYPE = hasSymbol ? Symbol.for('react.fundamental') : 0xead5;
41var REACT_RESPONDER_TYPE = hasSymbol ? Symbol.for('react.responder') : 0xead6;
42
43function isValidElementType(type) {
44 return typeof type === 'string' || typeof type === 'function' ||
45 // Note: its typeof might be other than 'symbol' or 'number' if it's a polyfill.
46 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);
47}
48
49/**
50 * Forked from fbjs/warning:
51 * https://github.com/facebook/fbjs/blob/e66ba20ad5be433eb54423f2b097d829324d9de6/packages/fbjs/src/__forks__/warning.js
52 *
53 * Only change is we use console.warn instead of console.error,
54 * and do nothing when 'console' is not supported.
55 * This really simplifies the code.
56 * ---
57 * Similar to invariant but only logs a warning if the condition is not met.
58 * This can be used to log issues in development environments in critical
59 * paths. Removing the logging code for production environments will keep the
60 * same logic and follow the same code paths.
61 */
62
63var lowPriorityWarning = function () {};
64
65{
66 var printWarning = function (format) {
67 for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
68 args[_key - 1] = arguments[_key];
69 }
70
71 var argIndex = 0;
72 var message = 'Warning: ' + format.replace(/%s/g, function () {
73 return args[argIndex++];
74 });
75 if (typeof console !== 'undefined') {
76 console.warn(message);
77 }
78 try {
79 // --- Welcome to debugging React ---
80 // This error was thrown as a convenience so that you can use this stack
81 // to find the callsite that caused this warning to fire.
82 throw new Error(message);
83 } catch (x) {}
84 };
85
86 lowPriorityWarning = function (condition, format) {
87 if (format === undefined) {
88 throw new Error('`lowPriorityWarning(condition, format, ...args)` requires a warning ' + 'message argument');
89 }
90 if (!condition) {
91 for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
92 args[_key2 - 2] = arguments[_key2];
93 }
94
95 printWarning.apply(undefined, [format].concat(args));
96 }
97 };
98}
99
100var lowPriorityWarning$1 = lowPriorityWarning;
101
102function typeOf(object) {
103 if (typeof object === 'object' && object !== null) {
104 var $$typeof = object.$$typeof;
105 switch ($$typeof) {
106 case REACT_ELEMENT_TYPE:
107 var type = object.type;
108
109 switch (type) {
110 case REACT_ASYNC_MODE_TYPE:
111 case REACT_CONCURRENT_MODE_TYPE:
112 case REACT_FRAGMENT_TYPE:
113 case REACT_PROFILER_TYPE:
114 case REACT_STRICT_MODE_TYPE:
115 case REACT_SUSPENSE_TYPE:
116 return type;
117 default:
118 var $$typeofType = type && type.$$typeof;
119
120 switch ($$typeofType) {
121 case REACT_CONTEXT_TYPE:
122 case REACT_FORWARD_REF_TYPE:
123 case REACT_PROVIDER_TYPE:
124 return $$typeofType;
125 default:
126 return $$typeof;
127 }
128 }
129 case REACT_LAZY_TYPE:
130 case REACT_MEMO_TYPE:
131 case REACT_PORTAL_TYPE:
132 return $$typeof;
133 }
134 }
135
136 return undefined;
137}
138
139// AsyncMode is deprecated along with isAsyncMode
140var AsyncMode = REACT_ASYNC_MODE_TYPE;
141var ConcurrentMode = REACT_CONCURRENT_MODE_TYPE;
142var ContextConsumer = REACT_CONTEXT_TYPE;
143var ContextProvider = REACT_PROVIDER_TYPE;
144var Element = REACT_ELEMENT_TYPE;
145var ForwardRef = REACT_FORWARD_REF_TYPE;
146var Fragment = REACT_FRAGMENT_TYPE;
147var Lazy = REACT_LAZY_TYPE;
148var Memo = REACT_MEMO_TYPE;
149var Portal = REACT_PORTAL_TYPE;
150var Profiler = REACT_PROFILER_TYPE;
151var StrictMode = REACT_STRICT_MODE_TYPE;
152var Suspense = REACT_SUSPENSE_TYPE;
153
154var hasWarnedAboutDeprecatedIsAsyncMode = false;
155
156// AsyncMode should be deprecated
157function isAsyncMode(object) {
158 {
159 if (!hasWarnedAboutDeprecatedIsAsyncMode) {
160 hasWarnedAboutDeprecatedIsAsyncMode = true;
161 lowPriorityWarning$1(false, '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.');
162 }
163 }
164 return isConcurrentMode(object) || typeOf(object) === REACT_ASYNC_MODE_TYPE;
165}
166function isConcurrentMode(object) {
167 return typeOf(object) === REACT_CONCURRENT_MODE_TYPE;
168}
169function isContextConsumer(object) {
170 return typeOf(object) === REACT_CONTEXT_TYPE;
171}
172function isContextProvider(object) {
173 return typeOf(object) === REACT_PROVIDER_TYPE;
174}
175function isElement(object) {
176 return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
177}
178function isForwardRef(object) {
179 return typeOf(object) === REACT_FORWARD_REF_TYPE;
180}
181function isFragment(object) {
182 return typeOf(object) === REACT_FRAGMENT_TYPE;
183}
184function isLazy(object) {
185 return typeOf(object) === REACT_LAZY_TYPE;
186}
187function isMemo(object) {
188 return typeOf(object) === REACT_MEMO_TYPE;
189}
190function isPortal(object) {
191 return typeOf(object) === REACT_PORTAL_TYPE;
192}
193function isProfiler(object) {
194 return typeOf(object) === REACT_PROFILER_TYPE;
195}
196function isStrictMode(object) {
197 return typeOf(object) === REACT_STRICT_MODE_TYPE;
198}
199function isSuspense(object) {
200 return typeOf(object) === REACT_SUSPENSE_TYPE;
201}
202
203exports.typeOf = typeOf;
204exports.AsyncMode = AsyncMode;
205exports.ConcurrentMode = ConcurrentMode;
206exports.ContextConsumer = ContextConsumer;
207exports.ContextProvider = ContextProvider;
208exports.Element = Element;
209exports.ForwardRef = ForwardRef;
210exports.Fragment = Fragment;
211exports.Lazy = Lazy;
212exports.Memo = Memo;
213exports.Portal = Portal;
214exports.Profiler = Profiler;
215exports.StrictMode = StrictMode;
216exports.Suspense = Suspense;
217exports.isValidElementType = isValidElementType;
218exports.isAsyncMode = isAsyncMode;
219exports.isConcurrentMode = isConcurrentMode;
220exports.isContextConsumer = isContextConsumer;
221exports.isContextProvider = isContextProvider;
222exports.isElement = isElement;
223exports.isForwardRef = isForwardRef;
224exports.isFragment = isFragment;
225exports.isLazy = isLazy;
226exports.isMemo = isMemo;
227exports.isPortal = isPortal;
228exports.isProfiler = isProfiler;
229exports.isStrictMode = isStrictMode;
230exports.isSuspense = isSuspense;
231 })();
232}