UNPKG

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