UNPKG

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