UNPKG

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