UNPKG

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