UNPKG

8.97 kBJavaScriptView Raw
1/** @license React v16.10.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
12(function (global, factory) {
13 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
14 typeof define === 'function' && define.amd ? define(['exports'], factory) :
15 (factory((global.ReactIs = {})));
16}(this, (function (exports) { '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_FUNDAMENTAL_TYPE = hasSymbol ? Symbol.for('react.fundamental') : 0xead5;
38var REACT_RESPONDER_TYPE = hasSymbol ? Symbol.for('react.responder') : 0xead6;
39var REACT_SCOPE_TYPE = hasSymbol ? Symbol.for('react.scope') : 0xead7;
40
41function isValidElementType(type) {
42 return typeof type === 'string' || typeof type === 'function' || // Note: its typeof might be other than 'symbol' or 'number' if it's a polyfill.
43 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);
44}
45
46/**
47 * Forked from fbjs/warning:
48 * https://github.com/facebook/fbjs/blob/e66ba20ad5be433eb54423f2b097d829324d9de6/packages/fbjs/src/__forks__/warning.js
49 *
50 * Only change is we use console.warn instead of console.error,
51 * and do nothing when 'console' is not supported.
52 * This really simplifies the code.
53 * ---
54 * Similar to invariant but only logs a warning if the condition is not met.
55 * This can be used to log issues in development environments in critical
56 * paths. Removing the logging code for production environments will keep the
57 * same logic and follow the same code paths.
58 */
59var lowPriorityWarningWithoutStack = function () {};
60
61{
62 var printWarning = function (format) {
63 for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
64 args[_key - 1] = arguments[_key];
65 }
66
67 var argIndex = 0;
68 var message = 'Warning: ' + format.replace(/%s/g, function () {
69 return args[argIndex++];
70 });
71
72 if (typeof console !== 'undefined') {
73 console.warn(message);
74 }
75
76 try {
77 // --- Welcome to debugging React ---
78 // This error was thrown as a convenience so that you can use this stack
79 // to find the callsite that caused this warning to fire.
80 throw new Error(message);
81 } catch (x) {}
82 };
83
84 lowPriorityWarningWithoutStack = function (condition, format) {
85 if (format === undefined) {
86 throw new Error('`lowPriorityWarningWithoutStack(condition, format, ...args)` requires a warning ' + 'message argument');
87 }
88
89 if (!condition) {
90 for (var _len2 = arguments.length, args = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
91 args[_key2 - 2] = arguments[_key2];
92 }
93
94 printWarning.apply(void 0, [format].concat(args));
95 }
96 };
97}
98
99var lowPriorityWarningWithoutStack$1 = lowPriorityWarningWithoutStack;
100
101function typeOf(object) {
102 if (typeof object === 'object' && object !== null) {
103 var $$typeof = object.$$typeof;
104
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
118 default:
119 var $$typeofType = type && type.$$typeof;
120
121 switch ($$typeofType) {
122 case REACT_CONTEXT_TYPE:
123 case REACT_FORWARD_REF_TYPE:
124 case REACT_PROVIDER_TYPE:
125 return $$typeofType;
126
127 default:
128 return $$typeof;
129 }
130
131 }
132
133 case REACT_LAZY_TYPE:
134 case REACT_MEMO_TYPE:
135 case REACT_PORTAL_TYPE:
136 return $$typeof;
137 }
138 }
139
140 return undefined;
141} // AsyncMode is deprecated along with isAsyncMode
142
143var AsyncMode = REACT_ASYNC_MODE_TYPE;
144var ConcurrentMode = REACT_CONCURRENT_MODE_TYPE;
145var ContextConsumer = REACT_CONTEXT_TYPE;
146var ContextProvider = REACT_PROVIDER_TYPE;
147var Element = REACT_ELEMENT_TYPE;
148var ForwardRef = REACT_FORWARD_REF_TYPE;
149var Fragment = REACT_FRAGMENT_TYPE;
150var Lazy = REACT_LAZY_TYPE;
151var Memo = REACT_MEMO_TYPE;
152var Portal = REACT_PORTAL_TYPE;
153var Profiler = REACT_PROFILER_TYPE;
154var StrictMode = REACT_STRICT_MODE_TYPE;
155var Suspense = REACT_SUSPENSE_TYPE;
156var hasWarnedAboutDeprecatedIsAsyncMode = false; // AsyncMode should be deprecated
157
158function isAsyncMode(object) {
159 {
160 if (!hasWarnedAboutDeprecatedIsAsyncMode) {
161 hasWarnedAboutDeprecatedIsAsyncMode = true;
162 lowPriorityWarningWithoutStack$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.');
163 }
164 }
165
166 return isConcurrentMode(object) || typeOf(object) === REACT_ASYNC_MODE_TYPE;
167}
168function isConcurrentMode(object) {
169 return typeOf(object) === REACT_CONCURRENT_MODE_TYPE;
170}
171function isContextConsumer(object) {
172 return typeOf(object) === REACT_CONTEXT_TYPE;
173}
174function isContextProvider(object) {
175 return typeOf(object) === REACT_PROVIDER_TYPE;
176}
177function isElement(object) {
178 return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
179}
180function isForwardRef(object) {
181 return typeOf(object) === REACT_FORWARD_REF_TYPE;
182}
183function isFragment(object) {
184 return typeOf(object) === REACT_FRAGMENT_TYPE;
185}
186function isLazy(object) {
187 return typeOf(object) === REACT_LAZY_TYPE;
188}
189function isMemo(object) {
190 return typeOf(object) === REACT_MEMO_TYPE;
191}
192function isPortal(object) {
193 return typeOf(object) === REACT_PORTAL_TYPE;
194}
195function isProfiler(object) {
196 return typeOf(object) === REACT_PROFILER_TYPE;
197}
198function isStrictMode(object) {
199 return typeOf(object) === REACT_STRICT_MODE_TYPE;
200}
201function isSuspense(object) {
202 return typeOf(object) === REACT_SUSPENSE_TYPE;
203}
204
205exports.typeOf = typeOf;
206exports.AsyncMode = AsyncMode;
207exports.ConcurrentMode = ConcurrentMode;
208exports.ContextConsumer = ContextConsumer;
209exports.ContextProvider = ContextProvider;
210exports.Element = Element;
211exports.ForwardRef = ForwardRef;
212exports.Fragment = Fragment;
213exports.Lazy = Lazy;
214exports.Memo = Memo;
215exports.Portal = Portal;
216exports.Profiler = Profiler;
217exports.StrictMode = StrictMode;
218exports.Suspense = Suspense;
219exports.isValidElementType = isValidElementType;
220exports.isAsyncMode = isAsyncMode;
221exports.isConcurrentMode = isConcurrentMode;
222exports.isContextConsumer = isContextConsumer;
223exports.isContextProvider = isContextProvider;
224exports.isElement = isElement;
225exports.isForwardRef = isForwardRef;
226exports.isFragment = isFragment;
227exports.isLazy = isLazy;
228exports.isMemo = isMemo;
229exports.isPortal = isPortal;
230exports.isProfiler = isProfiler;
231exports.isStrictMode = isStrictMode;
232exports.isSuspense = isSuspense;
233
234Object.defineProperty(exports, '__esModule', { value: true });
235
236})));