UNPKG

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