UNPKG

39.7 kBJavaScriptView Raw
1/** @license React v16.8.5
2 * react-test-renderer-shallow.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' ? module.exports = factory(require('react')) :
14 typeof define === 'function' && define.amd ? define(['react'], factory) :
15 (global.ReactShallowRenderer = factory(global.React));
16}(this, (function (React) { 'use strict';
17
18/**
19 * Use invariant() to assert state which your program assumes to be true.
20 *
21 * Provide sprintf-style format (only %s is supported) and arguments
22 * to provide information about what broke and what you were
23 * expecting.
24 *
25 * The invariant message will be stripped in production, but the invariant
26 * will remain to ensure logic does not differ in production.
27 */
28
29var validateFormat = function () {};
30
31{
32 validateFormat = function (format) {
33 if (format === undefined) {
34 throw new Error('invariant requires an error message argument');
35 }
36 };
37}
38
39function invariant(condition, format, a, b, c, d, e, f) {
40 validateFormat(format);
41
42 if (!condition) {
43 var error = void 0;
44 if (format === undefined) {
45 error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
46 } else {
47 var args = [a, b, c, d, e, f];
48 var argIndex = 0;
49 error = new Error(format.replace(/%s/g, function () {
50 return args[argIndex++];
51 }));
52 error.name = 'Invariant Violation';
53 }
54
55 error.framesToPop = 1; // we don't care about invariant's own frame
56 throw error;
57 }
58}
59
60// Relying on the `invariant()` implementation lets us
61// preserve the format and params in the www builds.
62
63var ReactInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
64
65var _assign = ReactInternals.assign;
66
67// The Symbol used to tag the ReactElement-like types. If there is no native Symbol
68// nor polyfill, then a plain number is used for performance.
69var hasSymbol = typeof Symbol === 'function' && Symbol.for;
70
71var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for('react.element') : 0xeac7;
72var REACT_PORTAL_TYPE = hasSymbol ? Symbol.for('react.portal') : 0xeaca;
73var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for('react.fragment') : 0xeacb;
74var REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol.for('react.strict_mode') : 0xeacc;
75var REACT_PROFILER_TYPE = hasSymbol ? Symbol.for('react.profiler') : 0xead2;
76var REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for('react.provider') : 0xeacd;
77var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace;
78var REACT_ASYNC_MODE_TYPE = hasSymbol ? Symbol.for('react.async_mode') : 0xeacf;
79var REACT_CONCURRENT_MODE_TYPE = hasSymbol ? Symbol.for('react.concurrent_mode') : 0xeacf;
80var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0;
81var REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for('react.suspense') : 0xead1;
82var REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3;
83var REACT_LAZY_TYPE = hasSymbol ? Symbol.for('react.lazy') : 0xead4;
84
85/**
86 * Forked from fbjs/warning:
87 * https://github.com/facebook/fbjs/blob/e66ba20ad5be433eb54423f2b097d829324d9de6/packages/fbjs/src/__forks__/warning.js
88 *
89 * Only change is we use console.warn instead of console.error,
90 * and do nothing when 'console' is not supported.
91 * This really simplifies the code.
92 * ---
93 * Similar to invariant but only logs a warning if the condition is not met.
94 * This can be used to log issues in development environments in critical
95 * paths. Removing the logging code for production environments will keep the
96 * same logic and follow the same code paths.
97 */
98
99{
100
101}
102
103function typeOf(object) {
104 if (typeof object === 'object' && object !== null) {
105 var $$typeof = object.$$typeof;
106 switch ($$typeof) {
107 case REACT_ELEMENT_TYPE:
108 var type = object.type;
109
110 switch (type) {
111 case REACT_ASYNC_MODE_TYPE:
112 case REACT_CONCURRENT_MODE_TYPE:
113 case REACT_FRAGMENT_TYPE:
114 case REACT_PROFILER_TYPE:
115 case REACT_STRICT_MODE_TYPE:
116 case REACT_SUSPENSE_TYPE:
117 return type;
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 default:
127 return $$typeof;
128 }
129 }
130 case REACT_LAZY_TYPE:
131 case REACT_MEMO_TYPE:
132 case REACT_PORTAL_TYPE:
133 return $$typeof;
134 }
135 }
136
137 return undefined;
138}
139
140// AsyncMode is deprecated along with isAsyncMode
141
142
143
144
145
146var ForwardRef = REACT_FORWARD_REF_TYPE;
147
148
149
150
151
152
153
154
155// AsyncMode should be deprecated
156
157
158
159
160
161function isForwardRef(object) {
162 return typeOf(object) === REACT_FORWARD_REF_TYPE;
163}
164
165
166function isMemo(object) {
167 return typeOf(object) === REACT_MEMO_TYPE;
168}
169
170var BEFORE_SLASH_RE = /^(.*)[\\\/]/;
171
172var describeComponentFrame = function (name, source, ownerName) {
173 var sourceInfo = '';
174 if (source) {
175 var path = source.fileName;
176 var fileName = path.replace(BEFORE_SLASH_RE, '');
177 {
178 // In DEV, include code for a common special case:
179 // prefer "folder/index.js" instead of just "index.js".
180 if (/^index\./.test(fileName)) {
181 var match = path.match(BEFORE_SLASH_RE);
182 if (match) {
183 var pathBeforeSlash = match[1];
184 if (pathBeforeSlash) {
185 var folderName = pathBeforeSlash.replace(BEFORE_SLASH_RE, '');
186 fileName = folderName + '/' + fileName;
187 }
188 }
189 }
190 }
191 sourceInfo = ' (at ' + fileName + ':' + source.lineNumber + ')';
192 } else if (ownerName) {
193 sourceInfo = ' (created by ' + ownerName + ')';
194 }
195 return '\n in ' + (name || 'Unknown') + sourceInfo;
196};
197
198/**
199 * Similar to invariant but only logs a warning if the condition is not met.
200 * This can be used to log issues in development environments in critical
201 * paths. Removing the logging code for production environments will keep the
202 * same logic and follow the same code paths.
203 */
204
205var warningWithoutStack = function () {};
206
207{
208 warningWithoutStack = function (condition, format) {
209 for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
210 args[_key - 2] = arguments[_key];
211 }
212
213 if (format === undefined) {
214 throw new Error('`warningWithoutStack(condition, format, ...args)` requires a warning ' + 'message argument');
215 }
216 if (args.length > 8) {
217 // Check before the condition to catch violations early.
218 throw new Error('warningWithoutStack() currently supports at most 8 arguments.');
219 }
220 if (condition) {
221 return;
222 }
223 if (typeof console !== 'undefined') {
224 var argsWithFormat = args.map(function (item) {
225 return '' + item;
226 });
227 argsWithFormat.unshift('Warning: ' + format);
228
229 // We intentionally don't use spread (or .apply) directly because it
230 // breaks IE9: https://github.com/facebook/react/issues/13610
231 Function.prototype.apply.call(console.error, console, argsWithFormat);
232 }
233 try {
234 // --- Welcome to debugging React ---
235 // This error was thrown as a convenience so that you can use this stack
236 // to find the callsite that caused this warning to fire.
237 var argIndex = 0;
238 var message = 'Warning: ' + format.replace(/%s/g, function () {
239 return args[argIndex++];
240 });
241 throw new Error(message);
242 } catch (x) {}
243 };
244}
245
246var warningWithoutStack$1 = warningWithoutStack;
247
248var Resolved = 1;
249
250
251function refineResolvedLazyComponent(lazyComponent) {
252 return lazyComponent._status === Resolved ? lazyComponent._result : null;
253}
254
255function getWrappedName(outerType, innerType, wrapperName) {
256 var functionName = innerType.displayName || innerType.name || '';
257 return outerType.displayName || (functionName !== '' ? wrapperName + '(' + functionName + ')' : wrapperName);
258}
259
260function getComponentName(type) {
261 if (type == null) {
262 // Host root, text node or just invalid type.
263 return null;
264 }
265 {
266 if (typeof type.tag === 'number') {
267 warningWithoutStack$1(false, 'Received an unexpected object in getComponentName(). ' + 'This is likely a bug in React. Please file an issue.');
268 }
269 }
270 if (typeof type === 'function') {
271 return type.displayName || type.name || null;
272 }
273 if (typeof type === 'string') {
274 return type;
275 }
276 switch (type) {
277 case REACT_CONCURRENT_MODE_TYPE:
278 return 'ConcurrentMode';
279 case REACT_FRAGMENT_TYPE:
280 return 'Fragment';
281 case REACT_PORTAL_TYPE:
282 return 'Portal';
283 case REACT_PROFILER_TYPE:
284 return 'Profiler';
285 case REACT_STRICT_MODE_TYPE:
286 return 'StrictMode';
287 case REACT_SUSPENSE_TYPE:
288 return 'Suspense';
289 }
290 if (typeof type === 'object') {
291 switch (type.$$typeof) {
292 case REACT_CONTEXT_TYPE:
293 return 'Context.Consumer';
294 case REACT_PROVIDER_TYPE:
295 return 'Context.Provider';
296 case REACT_FORWARD_REF_TYPE:
297 return getWrappedName(type, type.render, 'ForwardRef');
298 case REACT_MEMO_TYPE:
299 return getComponentName(type.type);
300 case REACT_LAZY_TYPE:
301 {
302 var thenable = type;
303 var resolvedThenable = refineResolvedLazyComponent(thenable);
304 if (resolvedThenable) {
305 return getComponentName(resolvedThenable);
306 }
307 }
308 }
309 }
310 return null;
311}
312
313/**
314 * inlined Object.is polyfill to avoid requiring consumers ship their own
315 * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
316 */
317function is(x, y) {
318 return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare
319 ;
320}
321
322var hasOwnProperty = Object.prototype.hasOwnProperty;
323
324/**
325 * Performs equality by iterating through keys on an object and returning false
326 * when any key has values which are not strictly equal between the arguments.
327 * Returns true when the values of all keys are strictly equal.
328 */
329function shallowEqual(objA, objB) {
330 if (is(objA, objB)) {
331 return true;
332 }
333
334 if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
335 return false;
336 }
337
338 var keysA = Object.keys(objA);
339 var keysB = Object.keys(objB);
340
341 if (keysA.length !== keysB.length) {
342 return false;
343 }
344
345 // Test for A's keys different from B.
346 for (var i = 0; i < keysA.length; i++) {
347 if (!hasOwnProperty.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) {
348 return false;
349 }
350 }
351
352 return true;
353}
354
355/**
356 * Copyright (c) 2013-present, Facebook, Inc.
357 *
358 * This source code is licensed under the MIT license found in the
359 * LICENSE file in the root directory of this source tree.
360 */
361
362
363
364var ReactPropTypesSecret$1 = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
365
366var ReactPropTypesSecret_1 = ReactPropTypesSecret$1;
367
368/**
369 * Copyright (c) 2013-present, Facebook, Inc.
370 *
371 * This source code is licensed under the MIT license found in the
372 * LICENSE file in the root directory of this source tree.
373 */
374
375
376
377var printWarning$1 = function() {};
378
379{
380 var ReactPropTypesSecret = ReactPropTypesSecret_1;
381 var loggedTypeFailures = {};
382
383 printWarning$1 = function(text) {
384 var message = 'Warning: ' + text;
385 if (typeof console !== 'undefined') {
386 console.error(message);
387 }
388 try {
389 // --- Welcome to debugging React ---
390 // This error was thrown as a convenience so that you can use this stack
391 // to find the callsite that caused this warning to fire.
392 throw new Error(message);
393 } catch (x) {}
394 };
395}
396
397/**
398 * Assert that the values match with the type specs.
399 * Error messages are memorized and will only be shown once.
400 *
401 * @param {object} typeSpecs Map of name to a ReactPropType
402 * @param {object} values Runtime values that need to be type-checked
403 * @param {string} location e.g. "prop", "context", "child context"
404 * @param {string} componentName Name of the component for error messages.
405 * @param {?Function} getStack Returns the component stack.
406 * @private
407 */
408function checkPropTypes(typeSpecs, values, location, componentName, getStack) {
409 {
410 for (var typeSpecName in typeSpecs) {
411 if (typeSpecs.hasOwnProperty(typeSpecName)) {
412 var error;
413 // Prop type validation may throw. In case they do, we don't want to
414 // fail the render phase where it didn't fail before. So we log it.
415 // After these have been cleaned up, we'll let them throw.
416 try {
417 // This is intentionally an invariant that gets caught. It's the same
418 // behavior as without this statement except with a better message.
419 if (typeof typeSpecs[typeSpecName] !== 'function') {
420 var err = Error(
421 (componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' +
422 'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.'
423 );
424 err.name = 'Invariant Violation';
425 throw err;
426 }
427 error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret);
428 } catch (ex) {
429 error = ex;
430 }
431 if (error && !(error instanceof Error)) {
432 printWarning$1(
433 (componentName || 'React class') + ': type specification of ' +
434 location + ' `' + typeSpecName + '` is invalid; the type checker ' +
435 'function must return `null` or an `Error` but returned a ' + typeof error + '. ' +
436 'You may have forgotten to pass an argument to the type checker ' +
437 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' +
438 'shape all require an argument).'
439 );
440
441 }
442 if (error instanceof Error && !(error.message in loggedTypeFailures)) {
443 // Only monitor this failure once because there tends to be a lot of the
444 // same error.
445 loggedTypeFailures[error.message] = true;
446
447 var stack = getStack ? getStack() : '';
448
449 printWarning$1(
450 'Failed ' + location + ' type: ' + error.message + (stack != null ? stack : '')
451 );
452 }
453 }
454 }
455 }
456}
457
458var checkPropTypes_1 = checkPropTypes;
459
460var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
461
462// Prevent newer renderers from RTE when used with older react package versions.
463// Current owner and dispatcher used to share the same ref,
464// but PR #14548 split them out to better support the react-debug-tools package.
465if (!ReactSharedInternals.hasOwnProperty('ReactCurrentDispatcher')) {
466 ReactSharedInternals.ReactCurrentDispatcher = {
467 current: null
468 };
469}
470
471/**
472 * Similar to invariant but only logs a warning if the condition is not met.
473 * This can be used to log issues in development environments in critical
474 * paths. Removing the logging code for production environments will keep the
475 * same logic and follow the same code paths.
476 */
477
478var warning = warningWithoutStack$1;
479
480{
481 warning = function (condition, format) {
482 if (condition) {
483 return;
484 }
485 var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
486 var stack = ReactDebugCurrentFrame.getStackAddendum();
487 // eslint-disable-next-line react-internal/warning-and-invariant-args
488
489 for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
490 args[_key - 2] = arguments[_key];
491 }
492
493 warningWithoutStack$1.apply(undefined, [false, format + '%s'].concat(args, [stack]));
494 };
495}
496
497var warning$1 = warning;
498
499function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
500
501var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
502
503
504var RE_RENDER_LIMIT = 25;
505
506var emptyObject = {};
507{
508 Object.freeze(emptyObject);
509}
510
511// In DEV, this is the name of the currently executing primitive hook
512var currentHookNameInDev = void 0;
513
514function areHookInputsEqual(nextDeps, prevDeps) {
515 if (prevDeps === null) {
516 warning$1(false, '%s received a final argument during this render, but not during ' + 'the previous render. Even though the final argument is optional, ' + 'its type cannot change between renders.', currentHookNameInDev);
517 return false;
518 }
519
520 // Don't bother comparing lengths in prod because these arrays should be
521 // passed inline.
522 if (nextDeps.length !== prevDeps.length) {
523 warning$1(false, 'The final argument passed to %s changed size between renders. The ' + 'order and size of this array must remain constant.\n\n' + 'Previous: %s\n' + 'Incoming: %s', currentHookNameInDev, '[' + nextDeps.join(', ') + ']', '[' + prevDeps.join(', ') + ']');
524 }
525 for (var i = 0; i < prevDeps.length && i < nextDeps.length; i++) {
526 if (is(nextDeps[i], prevDeps[i])) {
527 continue;
528 }
529 return false;
530 }
531 return true;
532}
533
534var Updater = function () {
535 function Updater(renderer) {
536 _classCallCheck(this, Updater);
537
538 this._renderer = renderer;
539 this._callbacks = [];
540 }
541
542 Updater.prototype._enqueueCallback = function _enqueueCallback(callback, publicInstance) {
543 if (typeof callback === 'function' && publicInstance) {
544 this._callbacks.push({
545 callback: callback,
546 publicInstance: publicInstance
547 });
548 }
549 };
550
551 Updater.prototype._invokeCallbacks = function _invokeCallbacks() {
552 var callbacks = this._callbacks;
553 this._callbacks = [];
554
555 callbacks.forEach(function (_ref) {
556 var callback = _ref.callback,
557 publicInstance = _ref.publicInstance;
558
559 callback.call(publicInstance);
560 });
561 };
562
563 Updater.prototype.isMounted = function isMounted(publicInstance) {
564 return !!this._renderer._element;
565 };
566
567 Updater.prototype.enqueueForceUpdate = function enqueueForceUpdate(publicInstance, callback, callerName) {
568 this._enqueueCallback(callback, publicInstance);
569 this._renderer._forcedUpdate = true;
570 this._renderer.render(this._renderer._element, this._renderer._context);
571 };
572
573 Updater.prototype.enqueueReplaceState = function enqueueReplaceState(publicInstance, completeState, callback, callerName) {
574 this._enqueueCallback(callback, publicInstance);
575 this._renderer._newState = completeState;
576 this._renderer.render(this._renderer._element, this._renderer._context);
577 };
578
579 Updater.prototype.enqueueSetState = function enqueueSetState(publicInstance, partialState, callback, callerName) {
580 this._enqueueCallback(callback, publicInstance);
581 var currentState = this._renderer._newState || publicInstance.state;
582
583 if (typeof partialState === 'function') {
584 partialState = partialState.call(publicInstance, currentState, publicInstance.props);
585 }
586
587 // Null and undefined are treated as no-ops.
588 if (partialState === null || partialState === undefined) {
589 return;
590 }
591
592 this._renderer._newState = _assign({}, currentState, partialState);
593
594 this._renderer.render(this._renderer._element, this._renderer._context);
595 };
596
597 return Updater;
598}();
599
600function createHook() {
601 return {
602 memoizedState: null,
603 queue: null,
604 next: null
605 };
606}
607
608function basicStateReducer(state, action) {
609 return typeof action === 'function' ? action(state) : action;
610}
611
612var ReactShallowRenderer = function () {
613 function ReactShallowRenderer() {
614 _classCallCheck(this, ReactShallowRenderer);
615
616 this._reset();
617 }
618
619 ReactShallowRenderer.prototype._reset = function _reset() {
620 this._context = null;
621 this._element = null;
622 this._instance = null;
623 this._newState = null;
624 this._rendered = null;
625 this._rendering = false;
626 this._forcedUpdate = false;
627 this._updater = new Updater(this);
628 this._dispatcher = this._createDispatcher();
629 this._workInProgressHook = null;
630 this._firstWorkInProgressHook = null;
631 this._isReRender = false;
632 this._didScheduleRenderPhaseUpdate = false;
633 this._renderPhaseUpdates = null;
634 this._numberOfReRenders = 0;
635 };
636
637 ReactShallowRenderer.prototype._validateCurrentlyRenderingComponent = function _validateCurrentlyRenderingComponent() {
638 !(this._rendering && !this._instance) ? invariant(false, 'Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:\n1. You might have mismatching versions of React and the renderer (such as React DOM)\n2. You might be breaking the Rules of Hooks\n3. You might have more than one copy of React in the same app\nSee https://fb.me/react-invalid-hook-call for tips about how to debug and fix this problem.') : void 0;
639 };
640
641 ReactShallowRenderer.prototype._createDispatcher = function _createDispatcher() {
642 var _this = this;
643
644 var useReducer = function (reducer, initialArg, init) {
645 _this._validateCurrentlyRenderingComponent();
646 _this._createWorkInProgressHook();
647 var workInProgressHook = _this._workInProgressHook;
648
649 if (_this._isReRender) {
650 // This is a re-render.
651 var _queue = workInProgressHook.queue;
652 var _dispatch = _queue.dispatch;
653 if (_this._numberOfReRenders > 0) {
654 // Apply the new render phase updates to the previous current hook.
655 if (_this._renderPhaseUpdates !== null) {
656 // Render phase updates are stored in a map of queue -> linked list
657 var firstRenderPhaseUpdate = _this._renderPhaseUpdates.get(_queue);
658 if (firstRenderPhaseUpdate !== undefined) {
659 _this._renderPhaseUpdates.delete(_queue);
660 var _newState = workInProgressHook.memoizedState;
661 var _update = firstRenderPhaseUpdate;
662 do {
663 var _action = _update.action;
664 _newState = reducer(_newState, _action);
665 _update = _update.next;
666 } while (_update !== null);
667 workInProgressHook.memoizedState = _newState;
668 return [_newState, _dispatch];
669 }
670 }
671 return [workInProgressHook.memoizedState, _dispatch];
672 }
673 // Process updates outside of render
674 var newState = workInProgressHook.memoizedState;
675 var update = _queue.first;
676 if (update !== null) {
677 do {
678 var _action2 = update.action;
679 newState = reducer(newState, _action2);
680 update = update.next;
681 } while (update !== null);
682 _queue.first = null;
683 workInProgressHook.memoizedState = newState;
684 }
685 return [newState, _dispatch];
686 } else {
687 var initialState = void 0;
688 if (reducer === basicStateReducer) {
689 // Special case for `useState`.
690 initialState = typeof initialArg === 'function' ? initialArg() : initialArg;
691 } else {
692 initialState = init !== undefined ? init(initialArg) : initialArg;
693 }
694 workInProgressHook.memoizedState = initialState;
695 var _queue2 = workInProgressHook.queue = {
696 first: null,
697 dispatch: null
698 };
699 var _dispatch2 = _queue2.dispatch = _this._dispatchAction.bind(_this, _queue2);
700 return [workInProgressHook.memoizedState, _dispatch2];
701 }
702 };
703
704 var useState = function (initialState) {
705 return useReducer(basicStateReducer,
706 // useReducer has a special case to support lazy useState initializers
707 initialState);
708 };
709
710 var useMemo = function (nextCreate, deps) {
711 _this._validateCurrentlyRenderingComponent();
712 _this._createWorkInProgressHook();
713
714 var nextDeps = deps !== undefined ? deps : null;
715
716 if (_this._workInProgressHook !== null && _this._workInProgressHook.memoizedState !== null) {
717 var prevState = _this._workInProgressHook.memoizedState;
718 var prevDeps = prevState[1];
719 if (nextDeps !== null) {
720 if (areHookInputsEqual(nextDeps, prevDeps)) {
721 return prevState[0];
722 }
723 }
724 }
725
726 var nextValue = nextCreate();
727 _this._workInProgressHook.memoizedState = [nextValue, nextDeps];
728 return nextValue;
729 };
730
731 var useRef = function (initialValue) {
732 _this._validateCurrentlyRenderingComponent();
733 _this._createWorkInProgressHook();
734 var previousRef = _this._workInProgressHook.memoizedState;
735 if (previousRef === null) {
736 var ref = { current: initialValue };
737 {
738 Object.seal(ref);
739 }
740 _this._workInProgressHook.memoizedState = ref;
741 return ref;
742 } else {
743 return previousRef;
744 }
745 };
746
747 var readContext = function (context, observedBits) {
748 return context._currentValue;
749 };
750
751 var noOp = function () {
752 _this._validateCurrentlyRenderingComponent();
753 };
754
755 var identity = function (fn) {
756 return fn;
757 };
758
759 return {
760 readContext: readContext,
761 useCallback: identity,
762 useContext: function (context) {
763 _this._validateCurrentlyRenderingComponent();
764 return readContext(context);
765 },
766 useDebugValue: noOp,
767 useEffect: noOp,
768 useImperativeHandle: noOp,
769 useLayoutEffect: noOp,
770 useMemo: useMemo,
771 useReducer: useReducer,
772 useRef: useRef,
773 useState: useState
774 };
775 };
776
777 ReactShallowRenderer.prototype._dispatchAction = function _dispatchAction(queue, action) {
778 !(this._numberOfReRenders < RE_RENDER_LIMIT) ? invariant(false, 'Too many re-renders. React limits the number of renders to prevent an infinite loop.') : void 0;
779
780 if (this._rendering) {
781 // This is a render phase update. Stash it in a lazily-created map of
782 // queue -> linked list of updates. After this render pass, we'll restart
783 // and apply the stashed updates on top of the work-in-progress hook.
784 this._didScheduleRenderPhaseUpdate = true;
785 var update = {
786 action: action,
787 next: null
788 };
789 var renderPhaseUpdates = this._renderPhaseUpdates;
790 if (renderPhaseUpdates === null) {
791 this._renderPhaseUpdates = renderPhaseUpdates = new Map();
792 }
793 var firstRenderPhaseUpdate = renderPhaseUpdates.get(queue);
794 if (firstRenderPhaseUpdate === undefined) {
795 renderPhaseUpdates.set(queue, update);
796 } else {
797 // Append the update to the end of the list.
798 var lastRenderPhaseUpdate = firstRenderPhaseUpdate;
799 while (lastRenderPhaseUpdate.next !== null) {
800 lastRenderPhaseUpdate = lastRenderPhaseUpdate.next;
801 }
802 lastRenderPhaseUpdate.next = update;
803 }
804 } else {
805 var _update2 = {
806 action: action,
807 next: null
808 };
809
810 // Append the update to the end of the list.
811 var last = queue.first;
812 if (last === null) {
813 queue.first = _update2;
814 } else {
815 while (last.next !== null) {
816 last = last.next;
817 }
818 last.next = _update2;
819 }
820
821 // Re-render now.
822 this.render(this._element, this._context);
823 }
824 };
825
826 ReactShallowRenderer.prototype._createWorkInProgressHook = function _createWorkInProgressHook() {
827 if (this._workInProgressHook === null) {
828 // This is the first hook in the list
829 if (this._firstWorkInProgressHook === null) {
830 this._isReRender = false;
831 this._firstWorkInProgressHook = this._workInProgressHook = createHook();
832 } else {
833 // There's already a work-in-progress. Reuse it.
834 this._isReRender = true;
835 this._workInProgressHook = this._firstWorkInProgressHook;
836 }
837 } else {
838 if (this._workInProgressHook.next === null) {
839 this._isReRender = false;
840 // Append to the end of the list
841 this._workInProgressHook = this._workInProgressHook.next = createHook();
842 } else {
843 // There's already a work-in-progress. Reuse it.
844 this._isReRender = true;
845 this._workInProgressHook = this._workInProgressHook.next;
846 }
847 }
848 return this._workInProgressHook;
849 };
850
851 ReactShallowRenderer.prototype._finishHooks = function _finishHooks(element, context) {
852 if (this._didScheduleRenderPhaseUpdate) {
853 // Updates were scheduled during the render phase. They are stored in
854 // the `renderPhaseUpdates` map. Call the component again, reusing the
855 // work-in-progress hooks and applying the additional updates on top. Keep
856 // restarting until no more updates are scheduled.
857 this._didScheduleRenderPhaseUpdate = false;
858 this._numberOfReRenders += 1;
859
860 // Start over from the beginning of the list
861 this._workInProgressHook = null;
862 this._rendering = false;
863 this.render(element, context);
864 } else {
865 this._workInProgressHook = null;
866 this._renderPhaseUpdates = null;
867 this._numberOfReRenders = 0;
868 }
869 };
870
871 ReactShallowRenderer.prototype.getMountedInstance = function getMountedInstance() {
872 return this._instance;
873 };
874
875 ReactShallowRenderer.prototype.getRenderOutput = function getRenderOutput() {
876 return this._rendered;
877 };
878
879 ReactShallowRenderer.prototype.render = function render(element) {
880 var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : emptyObject;
881
882 !React.isValidElement(element) ? invariant(false, 'ReactShallowRenderer render(): Invalid component element.%s', typeof element === 'function' ? ' Instead of passing a component class, make sure to instantiate ' + 'it by passing it to React.createElement.' : '') : void 0;
883 element = element;
884 // Show a special message for host elements since it's a common case.
885 !(typeof element.type !== 'string') ? invariant(false, 'ReactShallowRenderer render(): Shallow rendering works only with custom components, not primitives (%s). Instead of calling `.render(el)` and inspecting the rendered output, look at `el.props` directly instead.', element.type) : void 0;
886 !(isForwardRef(element) || typeof element.type === 'function' || isMemo(element.type)) ? invariant(false, 'ReactShallowRenderer render(): Shallow rendering works only with custom components, but the provided element type was `%s`.', Array.isArray(element.type) ? 'array' : element.type === null ? 'null' : typeof element.type) : void 0;
887
888 if (this._rendering) {
889 return;
890 }
891 if (this._element != null && this._element.type !== element.type) {
892 this._reset();
893 }
894
895 var elementType = isMemo(element.type) ? element.type.type : element.type;
896 var previousElement = this._element;
897
898 this._rendering = true;
899 this._element = element;
900 this._context = getMaskedContext(elementType.contextTypes, context);
901
902 // Inner memo component props aren't currently validated in createElement.
903 if (isMemo(element.type) && elementType.propTypes) {
904 currentlyValidatingElement = element;
905 checkPropTypes_1(elementType.propTypes, element.props, 'prop', getComponentName(elementType), getStackAddendum);
906 }
907
908 if (this._instance) {
909 this._updateClassComponent(elementType, element, this._context);
910 } else {
911 if (shouldConstruct(elementType)) {
912 this._instance = new elementType(element.props, this._context, this._updater);
913 if (typeof elementType.getDerivedStateFromProps === 'function') {
914 var partialState = elementType.getDerivedStateFromProps.call(null, element.props, this._instance.state);
915 if (partialState != null) {
916 this._instance.state = _assign({}, this._instance.state, partialState);
917 }
918 }
919
920 if (elementType.contextTypes) {
921 currentlyValidatingElement = element;
922 checkPropTypes_1(elementType.contextTypes, this._context, 'context', getName(elementType, this._instance), getStackAddendum);
923
924 currentlyValidatingElement = null;
925 }
926
927 this._mountClassComponent(elementType, element, this._context);
928 } else {
929 var shouldRender = true;
930 if (isMemo(element.type) && previousElement !== null) {
931 // This is a Memo component that is being re-rendered.
932 var compare = element.type.compare || shallowEqual;
933 if (compare(previousElement.props, element.props)) {
934 shouldRender = false;
935 }
936 }
937 if (shouldRender) {
938 var prevDispatcher = ReactCurrentDispatcher.current;
939 ReactCurrentDispatcher.current = this._dispatcher;
940 try {
941 // elementType could still be a ForwardRef if it was
942 // nested inside Memo.
943 if (elementType.$$typeof === ForwardRef) {
944 !(typeof elementType.render === 'function') ? invariant(false, 'forwardRef requires a render function but was given %s.', typeof elementType.render) : void 0;
945 this._rendered = elementType.render.call(undefined, element.props, element.ref);
946 } else {
947 this._rendered = elementType(element.props, this._context);
948 }
949 } finally {
950 ReactCurrentDispatcher.current = prevDispatcher;
951 }
952 this._finishHooks(element, context);
953 }
954 }
955 }
956
957 this._rendering = false;
958 this._updater._invokeCallbacks();
959
960 return this.getRenderOutput();
961 };
962
963 ReactShallowRenderer.prototype.unmount = function unmount() {
964 if (this._instance) {
965 if (typeof this._instance.componentWillUnmount === 'function') {
966 this._instance.componentWillUnmount();
967 }
968 }
969 this._reset();
970 };
971
972 ReactShallowRenderer.prototype._mountClassComponent = function _mountClassComponent(elementType, element, context) {
973 this._instance.context = context;
974 this._instance.props = element.props;
975 this._instance.state = this._instance.state || null;
976 this._instance.updater = this._updater;
977
978 if (typeof this._instance.UNSAFE_componentWillMount === 'function' || typeof this._instance.componentWillMount === 'function') {
979 var beforeState = this._newState;
980
981 // In order to support react-lifecycles-compat polyfilled components,
982 // Unsafe lifecycles should not be invoked for components using the new APIs.
983 if (typeof elementType.getDerivedStateFromProps !== 'function' && typeof this._instance.getSnapshotBeforeUpdate !== 'function') {
984 if (typeof this._instance.componentWillMount === 'function') {
985 this._instance.componentWillMount();
986 }
987 if (typeof this._instance.UNSAFE_componentWillMount === 'function') {
988 this._instance.UNSAFE_componentWillMount();
989 }
990 }
991
992 // setState may have been called during cWM
993 if (beforeState !== this._newState) {
994 this._instance.state = this._newState || emptyObject;
995 }
996 }
997
998 this._rendered = this._instance.render();
999 // Intentionally do not call componentDidMount()
1000 // because DOM refs are not available.
1001 };
1002
1003 ReactShallowRenderer.prototype._updateClassComponent = function _updateClassComponent(elementType, element, context) {
1004 var props = element.props;
1005
1006
1007 var oldState = this._instance.state || emptyObject;
1008 var oldProps = this._instance.props;
1009
1010 if (oldProps !== props) {
1011 // In order to support react-lifecycles-compat polyfilled components,
1012 // Unsafe lifecycles should not be invoked for components using the new APIs.
1013 if (typeof elementType.getDerivedStateFromProps !== 'function' && typeof this._instance.getSnapshotBeforeUpdate !== 'function') {
1014 if (typeof this._instance.componentWillReceiveProps === 'function') {
1015 this._instance.componentWillReceiveProps(props, context);
1016 }
1017 if (typeof this._instance.UNSAFE_componentWillReceiveProps === 'function') {
1018 this._instance.UNSAFE_componentWillReceiveProps(props, context);
1019 }
1020 }
1021 }
1022
1023 // Read state after cWRP in case it calls setState
1024 var state = this._newState || oldState;
1025 if (typeof elementType.getDerivedStateFromProps === 'function') {
1026 var partialState = elementType.getDerivedStateFromProps.call(null, props, state);
1027 if (partialState != null) {
1028 state = _assign({}, state, partialState);
1029 }
1030 }
1031
1032 var shouldUpdate = true;
1033 if (this._forcedUpdate) {
1034 shouldUpdate = true;
1035 this._forcedUpdate = false;
1036 } else if (typeof this._instance.shouldComponentUpdate === 'function') {
1037 shouldUpdate = !!this._instance.shouldComponentUpdate(props, state, context);
1038 } else if (elementType.prototype && elementType.prototype.isPureReactComponent) {
1039 shouldUpdate = !shallowEqual(oldProps, props) || !shallowEqual(oldState, state);
1040 }
1041
1042 if (shouldUpdate) {
1043 // In order to support react-lifecycles-compat polyfilled components,
1044 // Unsafe lifecycles should not be invoked for components using the new APIs.
1045 if (typeof elementType.getDerivedStateFromProps !== 'function' && typeof this._instance.getSnapshotBeforeUpdate !== 'function') {
1046 if (typeof this._instance.componentWillUpdate === 'function') {
1047 this._instance.componentWillUpdate(props, state, context);
1048 }
1049 if (typeof this._instance.UNSAFE_componentWillUpdate === 'function') {
1050 this._instance.UNSAFE_componentWillUpdate(props, state, context);
1051 }
1052 }
1053 }
1054
1055 this._instance.context = context;
1056 this._instance.props = props;
1057 this._instance.state = state;
1058 this._newState = null;
1059
1060 if (shouldUpdate) {
1061 this._rendered = this._instance.render();
1062 }
1063 // Intentionally do not call componentDidUpdate()
1064 // because DOM refs are not available.
1065 };
1066
1067 return ReactShallowRenderer;
1068}();
1069
1070ReactShallowRenderer.createRenderer = function () {
1071 return new ReactShallowRenderer();
1072};
1073
1074var currentlyValidatingElement = null;
1075
1076function getDisplayName(element) {
1077 if (element == null) {
1078 return '#empty';
1079 } else if (typeof element === 'string' || typeof element === 'number') {
1080 return '#text';
1081 } else if (typeof element.type === 'string') {
1082 return element.type;
1083 } else {
1084 var elementType = isMemo(element.type) ? element.type.type : element.type;
1085 return elementType.displayName || elementType.name || 'Unknown';
1086 }
1087}
1088
1089function getStackAddendum() {
1090 var stack = '';
1091 if (currentlyValidatingElement) {
1092 var name = getDisplayName(currentlyValidatingElement);
1093 var owner = currentlyValidatingElement._owner;
1094 stack += describeComponentFrame(name, currentlyValidatingElement._source, owner && getComponentName(owner.type));
1095 }
1096 return stack;
1097}
1098
1099function getName(type, instance) {
1100 var constructor = instance && instance.constructor;
1101 return type.displayName || constructor && constructor.displayName || type.name || constructor && constructor.name || null;
1102}
1103
1104function shouldConstruct(Component) {
1105 return !!(Component.prototype && Component.prototype.isReactComponent);
1106}
1107
1108function getMaskedContext(contextTypes, unmaskedContext) {
1109 if (!contextTypes || !unmaskedContext) {
1110 return emptyObject;
1111 }
1112 var context = {};
1113 for (var key in contextTypes) {
1114 context[key] = unmaskedContext[key];
1115 }
1116 return context;
1117}
1118
1119
1120
1121var ReactShallowRenderer$2 = Object.freeze({
1122 default: ReactShallowRenderer
1123});
1124
1125var ReactShallowRenderer$3 = ( ReactShallowRenderer$2 && ReactShallowRenderer ) || ReactShallowRenderer$2;
1126
1127// TODO: decide on the top-level export form.
1128// This is hacky but makes it work with both Rollup and Jest.
1129var shallow = ReactShallowRenderer$3.default || ReactShallowRenderer$3;
1130
1131return shallow;
1132
1133})));