1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | 'use strict';
|
11 |
|
12 | (function (global, factory) {
|
13 | typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('react')) :
|
14 | typeof define === 'function' && define.amd ? define(['react'], factory) :
|
15 | (global.ReactShallowRenderer = factory(global.React));
|
16 | }(this, (function (React) { 'use strict';
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | function ReactError(error) {
|
27 | error.name = 'Invariant Violation';
|
28 | return error;
|
29 | }
|
30 |
|
31 | var ReactInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
32 |
|
33 | var _assign = ReactInternals.assign;
|
34 |
|
35 |
|
36 |
|
37 | var hasSymbol = typeof Symbol === 'function' && Symbol.for;
|
38 |
|
39 | var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for('react.element') : 0xeac7;
|
40 | var REACT_PORTAL_TYPE = hasSymbol ? Symbol.for('react.portal') : 0xeaca;
|
41 | var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for('react.fragment') : 0xeacb;
|
42 | var REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol.for('react.strict_mode') : 0xeacc;
|
43 | var REACT_PROFILER_TYPE = hasSymbol ? Symbol.for('react.profiler') : 0xead2;
|
44 | var REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for('react.provider') : 0xeacd;
|
45 | var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace;
|
46 |
|
47 |
|
48 | var REACT_ASYNC_MODE_TYPE = hasSymbol ? Symbol.for('react.async_mode') : 0xeacf;
|
49 | var REACT_CONCURRENT_MODE_TYPE = hasSymbol ? Symbol.for('react.concurrent_mode') : 0xeacf;
|
50 | var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0;
|
51 | var REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for('react.suspense') : 0xead1;
|
52 | var REACT_SUSPENSE_LIST_TYPE = hasSymbol ? Symbol.for('react.suspense_list') : 0xead8;
|
53 | var REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3;
|
54 | var REACT_LAZY_TYPE = hasSymbol ? Symbol.for('react.lazy') : 0xead4;
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 | {
|
71 |
|
72 | }
|
73 |
|
74 | function 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 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 | var ForwardRef = REACT_FORWARD_REF_TYPE;
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 | function isForwardRef(object) {
|
133 | return typeOf(object) === REACT_FORWARD_REF_TYPE;
|
134 | }
|
135 |
|
136 |
|
137 | function isMemo(object) {
|
138 | return typeOf(object) === REACT_MEMO_TYPE;
|
139 | }
|
140 |
|
141 | var BEFORE_SLASH_RE = /^(.*)[\\\/]/;
|
142 |
|
143 | var 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 |
|
150 |
|
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 |
|
171 |
|
172 |
|
173 |
|
174 |
|
175 |
|
176 | var 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 |
|
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 |
|
201 |
|
202 | Function.prototype.apply.call(console.error, console, argsWithFormat);
|
203 | }
|
204 | try {
|
205 |
|
206 |
|
207 |
|
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 |
|
217 | var warningWithoutStack$1 = warningWithoutStack;
|
218 |
|
219 | var Resolved = 1;
|
220 |
|
221 |
|
222 | function refineResolvedLazyComponent(lazyComponent) {
|
223 | return lazyComponent._status === Resolved ? lazyComponent._result : null;
|
224 | }
|
225 |
|
226 | function getWrappedName(outerType, innerType, wrapperName) {
|
227 | var functionName = innerType.displayName || innerType.name || '';
|
228 | return outerType.displayName || (functionName !== '' ? wrapperName + '(' + functionName + ')' : wrapperName);
|
229 | }
|
230 |
|
231 | function getComponentName(type) {
|
232 | if (type == null) {
|
233 |
|
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 |
|
287 |
|
288 |
|
289 | function is(x, y) {
|
290 | return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y
|
291 | ;
|
292 | }
|
293 |
|
294 | var hasOwnProperty = Object.prototype.hasOwnProperty;
|
295 |
|
296 |
|
297 |
|
298 |
|
299 |
|
300 |
|
301 | function 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 |
|
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 |
|
329 |
|
330 |
|
331 |
|
332 |
|
333 |
|
334 |
|
335 |
|
336 |
|
337 |
|
338 |
|
339 |
|
340 |
|
341 |
|
342 |
|
343 |
|
344 |
|
345 |
|
346 |
|
347 | var ReactPropTypesSecret$1 = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
|
348 |
|
349 | var ReactPropTypesSecret_1 = ReactPropTypesSecret$1;
|
350 |
|
351 |
|
352 |
|
353 |
|
354 |
|
355 |
|
356 |
|
357 |
|
358 |
|
359 |
|
360 | var 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 |
|
373 |
|
374 |
|
375 | throw new Error(message);
|
376 | } catch (x) {}
|
377 | };
|
378 | }
|
379 |
|
380 |
|
381 |
|
382 |
|
383 |
|
384 |
|
385 |
|
386 |
|
387 |
|
388 |
|
389 |
|
390 |
|
391 | function checkPropTypes(typeSpecs, values, location, componentName, getStack) {
|
392 | {
|
393 | for (var typeSpecName in typeSpecs) {
|
394 | if (typeSpecs.hasOwnProperty(typeSpecName)) {
|
395 | var error;
|
396 |
|
397 |
|
398 |
|
399 | try {
|
400 |
|
401 |
|
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 |
|
427 |
|
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 |
|
441 | var checkPropTypes_1 = checkPropTypes;
|
442 |
|
443 | var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
444 |
|
445 |
|
446 |
|
447 |
|
448 | if (!ReactSharedInternals.hasOwnProperty('ReactCurrentDispatcher')) {
|
449 | ReactSharedInternals.ReactCurrentDispatcher = {
|
450 | current: null
|
451 | };
|
452 | }
|
453 | if (!ReactSharedInternals.hasOwnProperty('ReactCurrentBatchConfig')) {
|
454 | ReactSharedInternals.ReactCurrentBatchConfig = {
|
455 | suspense: null
|
456 | };
|
457 | }
|
458 |
|
459 |
|
460 |
|
461 |
|
462 |
|
463 |
|
464 |
|
465 |
|
466 | var 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 |
|
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 |
|
485 | var warning$1 = warning;
|
486 |
|
487 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
488 |
|
489 | var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
|
490 |
|
491 |
|
492 | var RE_RENDER_LIMIT = 25;
|
493 |
|
494 | var emptyObject = {};
|
495 | {
|
496 | Object.freeze(emptyObject);
|
497 | }
|
498 |
|
499 |
|
500 | var currentHookNameInDev = void 0;
|
501 |
|
502 | function 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 |
|
509 |
|
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 |
|
522 | var 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 |
|
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 |
|
588 | function createHook() {
|
589 | return {
|
590 | memoizedState: null,
|
591 | queue: null,
|
592 | next: null
|
593 | };
|
594 | }
|
595 |
|
596 | function basicStateReducer(state, action) {
|
597 | return typeof action === 'function' ? action(state) : action;
|
598 | }
|
599 |
|
600 | var 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 |
|
647 | var _queue = workInProgressHook.queue;
|
648 | var _dispatch = _queue.dispatch;
|
649 | if (_this2._numberOfReRenders > 0) {
|
650 |
|
651 | if (_this2._renderPhaseUpdates !== null) {
|
652 |
|
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 |
|
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 |
|
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 |
|
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 |
|
794 |
|
795 |
|
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 |
|
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 |
|
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 |
|
834 | this.render(this._element, this._context);
|
835 | }
|
836 | };
|
837 |
|
838 | ReactShallowRenderer.prototype._createWorkInProgressHook = function _createWorkInProgressHook() {
|
839 | if (this._workInProgressHook === null) {
|
840 |
|
841 | if (this._firstWorkInProgressHook === null) {
|
842 | this._isReRender = false;
|
843 | this._firstWorkInProgressHook = this._workInProgressHook = createHook();
|
844 | } else {
|
845 |
|
846 | this._isReRender = true;
|
847 | this._workInProgressHook = this._firstWorkInProgressHook;
|
848 | }
|
849 | } else {
|
850 | if (this._workInProgressHook.next === null) {
|
851 | this._isReRender = false;
|
852 |
|
853 | this._workInProgressHook = this._workInProgressHook.next = createHook();
|
854 | } else {
|
855 |
|
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 |
|
866 |
|
867 |
|
868 |
|
869 | this._didScheduleRenderPhaseUpdate = false;
|
870 | this._numberOfReRenders += 1;
|
871 |
|
872 |
|
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 |
|
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 |
|
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 |
|
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 |
|
972 |
|
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 |
|
1018 |
|
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 |
|
1029 | if (beforeState !== this._newState) {
|
1030 | this._instance.state = this._newState || emptyObject;
|
1031 | }
|
1032 | }
|
1033 |
|
1034 | this._rendered = this._instance.render();
|
1035 |
|
1036 |
|
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 |
|
1048 |
|
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 |
|
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 |
|
1080 |
|
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 |
|
1100 |
|
1101 | };
|
1102 |
|
1103 | return ReactShallowRenderer;
|
1104 | }();
|
1105 |
|
1106 | ReactShallowRenderer.createRenderer = function () {
|
1107 | return new ReactShallowRenderer();
|
1108 | };
|
1109 |
|
1110 | var currentlyValidatingElement = null;
|
1111 |
|
1112 | function 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 |
|
1125 | function 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 |
|
1135 | function getName(type, instance) {
|
1136 | var constructor = instance && instance.constructor;
|
1137 | return type.displayName || constructor && constructor.displayName || type.name || constructor && constructor.name || null;
|
1138 | }
|
1139 |
|
1140 | function shouldConstruct(Component) {
|
1141 | return !!(Component.prototype && Component.prototype.isReactComponent);
|
1142 | }
|
1143 |
|
1144 | function 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 |
|
1157 | var ReactShallowRenderer$2 = Object.freeze({
|
1158 | default: ReactShallowRenderer
|
1159 | });
|
1160 |
|
1161 | var ReactShallowRenderer$3 = ( ReactShallowRenderer$2 && ReactShallowRenderer ) || ReactShallowRenderer$2;
|
1162 |
|
1163 |
|
1164 |
|
1165 | var shallow = ReactShallowRenderer$3.default || ReactShallowRenderer$3;
|
1166 |
|
1167 | return shallow;
|
1168 |
|
1169 | })));
|