UNPKG

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