UNPKG

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