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 |
|
27 |
|
28 |
|
29 | var validateFormat = function () {};
|
30 |
|
31 | {
|
32 | validateFormat = function (format) {
|
33 | if (format === undefined) {
|
34 | throw new Error('invariant requires an error message argument');
|
35 | }
|
36 | };
|
37 | }
|
38 |
|
39 | function invariant(condition, format, a, b, c, d, e, f) {
|
40 | validateFormat(format);
|
41 |
|
42 | if (!condition) {
|
43 | var error = void 0;
|
44 | if (format === undefined) {
|
45 | error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
|
46 | } else {
|
47 | var args = [a, b, c, d, e, f];
|
48 | var argIndex = 0;
|
49 | error = new Error(format.replace(/%s/g, function () {
|
50 | return args[argIndex++];
|
51 | }));
|
52 | error.name = 'Invariant Violation';
|
53 | }
|
54 |
|
55 | error.framesToPop = 1;
|
56 | throw error;
|
57 | }
|
58 | }
|
59 |
|
60 |
|
61 |
|
62 |
|
63 | var ReactInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
64 |
|
65 | var _assign = ReactInternals.assign;
|
66 |
|
67 |
|
68 |
|
69 | var hasSymbol = typeof Symbol === 'function' && Symbol.for;
|
70 |
|
71 | var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for('react.element') : 0xeac7;
|
72 | var REACT_PORTAL_TYPE = hasSymbol ? Symbol.for('react.portal') : 0xeaca;
|
73 | var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for('react.fragment') : 0xeacb;
|
74 | var REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol.for('react.strict_mode') : 0xeacc;
|
75 | var REACT_PROFILER_TYPE = hasSymbol ? Symbol.for('react.profiler') : 0xead2;
|
76 | var REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for('react.provider') : 0xeacd;
|
77 | var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace;
|
78 | var REACT_ASYNC_MODE_TYPE = hasSymbol ? Symbol.for('react.async_mode') : 0xeacf;
|
79 | var REACT_CONCURRENT_MODE_TYPE = hasSymbol ? Symbol.for('react.concurrent_mode') : 0xeacf;
|
80 | var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0;
|
81 | var REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for('react.suspense') : 0xead1;
|
82 | var REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3;
|
83 | var REACT_LAZY_TYPE = hasSymbol ? Symbol.for('react.lazy') : 0xead4;
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 | {
|
100 |
|
101 | }
|
102 |
|
103 | function typeOf(object) {
|
104 | if (typeof object === 'object' && object !== null) {
|
105 | var $$typeof = object.$$typeof;
|
106 | switch ($$typeof) {
|
107 | case REACT_ELEMENT_TYPE:
|
108 | var type = object.type;
|
109 |
|
110 | switch (type) {
|
111 | case REACT_ASYNC_MODE_TYPE:
|
112 | case REACT_CONCURRENT_MODE_TYPE:
|
113 | case REACT_FRAGMENT_TYPE:
|
114 | case REACT_PROFILER_TYPE:
|
115 | case REACT_STRICT_MODE_TYPE:
|
116 | case REACT_SUSPENSE_TYPE:
|
117 | return type;
|
118 | default:
|
119 | var $$typeofType = type && type.$$typeof;
|
120 |
|
121 | switch ($$typeofType) {
|
122 | case REACT_CONTEXT_TYPE:
|
123 | case REACT_FORWARD_REF_TYPE:
|
124 | case REACT_PROVIDER_TYPE:
|
125 | return $$typeofType;
|
126 | default:
|
127 | return $$typeof;
|
128 | }
|
129 | }
|
130 | case REACT_LAZY_TYPE:
|
131 | case REACT_MEMO_TYPE:
|
132 | case REACT_PORTAL_TYPE:
|
133 | return $$typeof;
|
134 | }
|
135 | }
|
136 |
|
137 | return undefined;
|
138 | }
|
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 | function isForwardRef(object) {
|
162 | return typeOf(object) === REACT_FORWARD_REF_TYPE;
|
163 | }
|
164 |
|
165 | var BEFORE_SLASH_RE = /^(.*)[\\\/]/;
|
166 |
|
167 | var describeComponentFrame = function (name, source, ownerName) {
|
168 | var sourceInfo = '';
|
169 | if (source) {
|
170 | var path = source.fileName;
|
171 | var fileName = path.replace(BEFORE_SLASH_RE, '');
|
172 | {
|
173 |
|
174 |
|
175 | if (/^index\./.test(fileName)) {
|
176 | var match = path.match(BEFORE_SLASH_RE);
|
177 | if (match) {
|
178 | var pathBeforeSlash = match[1];
|
179 | if (pathBeforeSlash) {
|
180 | var folderName = pathBeforeSlash.replace(BEFORE_SLASH_RE, '');
|
181 | fileName = folderName + '/' + fileName;
|
182 | }
|
183 | }
|
184 | }
|
185 | }
|
186 | sourceInfo = ' (at ' + fileName + ':' + source.lineNumber + ')';
|
187 | } else if (ownerName) {
|
188 | sourceInfo = ' (created by ' + ownerName + ')';
|
189 | }
|
190 | return '\n in ' + (name || 'Unknown') + sourceInfo;
|
191 | };
|
192 |
|
193 |
|
194 |
|
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 | var warningWithoutStack = function () {};
|
201 |
|
202 | {
|
203 | warningWithoutStack = function (condition, format) {
|
204 | for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
205 | args[_key - 2] = arguments[_key];
|
206 | }
|
207 |
|
208 | if (format === undefined) {
|
209 | throw new Error('`warningWithoutStack(condition, format, ...args)` requires a warning ' + 'message argument');
|
210 | }
|
211 | if (args.length > 8) {
|
212 |
|
213 | throw new Error('warningWithoutStack() currently supports at most 8 arguments.');
|
214 | }
|
215 | if (condition) {
|
216 | return;
|
217 | }
|
218 | if (typeof console !== 'undefined') {
|
219 | var argsWithFormat = args.map(function (item) {
|
220 | return '' + item;
|
221 | });
|
222 | argsWithFormat.unshift('Warning: ' + format);
|
223 |
|
224 |
|
225 |
|
226 | Function.prototype.apply.call(console.error, console, argsWithFormat);
|
227 | }
|
228 | try {
|
229 |
|
230 |
|
231 |
|
232 | var argIndex = 0;
|
233 | var message = 'Warning: ' + format.replace(/%s/g, function () {
|
234 | return args[argIndex++];
|
235 | });
|
236 | throw new Error(message);
|
237 | } catch (x) {}
|
238 | };
|
239 | }
|
240 |
|
241 | var warningWithoutStack$1 = warningWithoutStack;
|
242 |
|
243 | var Resolved = 1;
|
244 |
|
245 |
|
246 | function refineResolvedLazyComponent(lazyComponent) {
|
247 | return lazyComponent._status === Resolved ? lazyComponent._result : null;
|
248 | }
|
249 |
|
250 | function getWrappedName(outerType, innerType, wrapperName) {
|
251 | var functionName = innerType.displayName || innerType.name || '';
|
252 | return outerType.displayName || (functionName !== '' ? wrapperName + '(' + functionName + ')' : wrapperName);
|
253 | }
|
254 |
|
255 | function getComponentName(type) {
|
256 | if (type == null) {
|
257 |
|
258 | return null;
|
259 | }
|
260 | {
|
261 | if (typeof type.tag === 'number') {
|
262 | warningWithoutStack$1(false, 'Received an unexpected object in getComponentName(). ' + 'This is likely a bug in React. Please file an issue.');
|
263 | }
|
264 | }
|
265 | if (typeof type === 'function') {
|
266 | return type.displayName || type.name || null;
|
267 | }
|
268 | if (typeof type === 'string') {
|
269 | return type;
|
270 | }
|
271 | switch (type) {
|
272 | case REACT_CONCURRENT_MODE_TYPE:
|
273 | return 'ConcurrentMode';
|
274 | case REACT_FRAGMENT_TYPE:
|
275 | return 'Fragment';
|
276 | case REACT_PORTAL_TYPE:
|
277 | return 'Portal';
|
278 | case REACT_PROFILER_TYPE:
|
279 | return 'Profiler';
|
280 | case REACT_STRICT_MODE_TYPE:
|
281 | return 'StrictMode';
|
282 | case REACT_SUSPENSE_TYPE:
|
283 | return 'Suspense';
|
284 | }
|
285 | if (typeof type === 'object') {
|
286 | switch (type.$$typeof) {
|
287 | case REACT_CONTEXT_TYPE:
|
288 | return 'Context.Consumer';
|
289 | case REACT_PROVIDER_TYPE:
|
290 | return 'Context.Provider';
|
291 | case REACT_FORWARD_REF_TYPE:
|
292 | return getWrappedName(type, type.render, 'ForwardRef');
|
293 | case REACT_MEMO_TYPE:
|
294 | return getComponentName(type.type);
|
295 | case REACT_LAZY_TYPE:
|
296 | {
|
297 | var thenable = type;
|
298 | var resolvedThenable = refineResolvedLazyComponent(thenable);
|
299 | if (resolvedThenable) {
|
300 | return getComponentName(resolvedThenable);
|
301 | }
|
302 | }
|
303 | }
|
304 | }
|
305 | return null;
|
306 | }
|
307 |
|
308 |
|
309 |
|
310 | var hasOwnProperty = Object.prototype.hasOwnProperty;
|
311 |
|
312 |
|
313 |
|
314 |
|
315 |
|
316 | function is(x, y) {
|
317 |
|
318 | if (x === y) {
|
319 |
|
320 |
|
321 |
|
322 | return x !== 0 || y !== 0 || 1 / x === 1 / y;
|
323 | } else {
|
324 |
|
325 | return x !== x && y !== y;
|
326 | }
|
327 | }
|
328 |
|
329 |
|
330 |
|
331 |
|
332 |
|
333 |
|
334 | function shallowEqual(objA, objB) {
|
335 | if (is(objA, objB)) {
|
336 | return true;
|
337 | }
|
338 |
|
339 | if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
|
340 | return false;
|
341 | }
|
342 |
|
343 | var keysA = Object.keys(objA);
|
344 | var keysB = Object.keys(objB);
|
345 |
|
346 | if (keysA.length !== keysB.length) {
|
347 | return false;
|
348 | }
|
349 |
|
350 |
|
351 | for (var i = 0; i < keysA.length; i++) {
|
352 | if (!hasOwnProperty.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) {
|
353 | return false;
|
354 | }
|
355 | }
|
356 |
|
357 | return true;
|
358 | }
|
359 |
|
360 |
|
361 |
|
362 |
|
363 |
|
364 |
|
365 |
|
366 |
|
367 |
|
368 |
|
369 | var ReactPropTypesSecret$1 = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
|
370 |
|
371 | var ReactPropTypesSecret_1 = ReactPropTypesSecret$1;
|
372 |
|
373 |
|
374 |
|
375 |
|
376 |
|
377 |
|
378 |
|
379 |
|
380 |
|
381 |
|
382 | var printWarning$1 = function() {};
|
383 |
|
384 | {
|
385 | var ReactPropTypesSecret = ReactPropTypesSecret_1;
|
386 | var loggedTypeFailures = {};
|
387 |
|
388 | printWarning$1 = function(text) {
|
389 | var message = 'Warning: ' + text;
|
390 | if (typeof console !== 'undefined') {
|
391 | console.error(message);
|
392 | }
|
393 | try {
|
394 |
|
395 |
|
396 |
|
397 | throw new Error(message);
|
398 | } catch (x) {}
|
399 | };
|
400 | }
|
401 |
|
402 |
|
403 |
|
404 |
|
405 |
|
406 |
|
407 |
|
408 |
|
409 |
|
410 |
|
411 |
|
412 |
|
413 | function checkPropTypes(typeSpecs, values, location, componentName, getStack) {
|
414 | {
|
415 | for (var typeSpecName in typeSpecs) {
|
416 | if (typeSpecs.hasOwnProperty(typeSpecName)) {
|
417 | var error;
|
418 |
|
419 |
|
420 |
|
421 | try {
|
422 |
|
423 |
|
424 | if (typeof typeSpecs[typeSpecName] !== 'function') {
|
425 | var err = Error(
|
426 | (componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' +
|
427 | 'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.'
|
428 | );
|
429 | err.name = 'Invariant Violation';
|
430 | throw err;
|
431 | }
|
432 | error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret);
|
433 | } catch (ex) {
|
434 | error = ex;
|
435 | }
|
436 | if (error && !(error instanceof Error)) {
|
437 | printWarning$1(
|
438 | (componentName || 'React class') + ': type specification of ' +
|
439 | location + ' `' + typeSpecName + '` is invalid; the type checker ' +
|
440 | 'function must return `null` or an `Error` but returned a ' + typeof error + '. ' +
|
441 | 'You may have forgotten to pass an argument to the type checker ' +
|
442 | 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' +
|
443 | 'shape all require an argument).'
|
444 | );
|
445 |
|
446 | }
|
447 | if (error instanceof Error && !(error.message in loggedTypeFailures)) {
|
448 |
|
449 |
|
450 | loggedTypeFailures[error.message] = true;
|
451 |
|
452 | var stack = getStack ? getStack() : '';
|
453 |
|
454 | printWarning$1(
|
455 | 'Failed ' + location + ' type: ' + error.message + (stack != null ? stack : '')
|
456 | );
|
457 | }
|
458 | }
|
459 | }
|
460 | }
|
461 | }
|
462 |
|
463 | var checkPropTypes_1 = checkPropTypes;
|
464 |
|
465 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
466 |
|
467 | var emptyObject = {};
|
468 | {
|
469 | Object.freeze(emptyObject);
|
470 | }
|
471 |
|
472 | var Updater = function () {
|
473 | function Updater(renderer) {
|
474 | _classCallCheck(this, Updater);
|
475 |
|
476 | this._renderer = renderer;
|
477 | this._callbacks = [];
|
478 | }
|
479 |
|
480 | Updater.prototype._enqueueCallback = function _enqueueCallback(callback, publicInstance) {
|
481 | if (typeof callback === 'function' && publicInstance) {
|
482 | this._callbacks.push({
|
483 | callback: callback,
|
484 | publicInstance: publicInstance
|
485 | });
|
486 | }
|
487 | };
|
488 |
|
489 | Updater.prototype._invokeCallbacks = function _invokeCallbacks() {
|
490 | var callbacks = this._callbacks;
|
491 | this._callbacks = [];
|
492 |
|
493 | callbacks.forEach(function (_ref) {
|
494 | var callback = _ref.callback,
|
495 | publicInstance = _ref.publicInstance;
|
496 |
|
497 | callback.call(publicInstance);
|
498 | });
|
499 | };
|
500 |
|
501 | Updater.prototype.isMounted = function isMounted(publicInstance) {
|
502 | return !!this._renderer._element;
|
503 | };
|
504 |
|
505 | Updater.prototype.enqueueForceUpdate = function enqueueForceUpdate(publicInstance, callback, callerName) {
|
506 | this._enqueueCallback(callback, publicInstance);
|
507 | this._renderer._forcedUpdate = true;
|
508 | this._renderer.render(this._renderer._element, this._renderer._context);
|
509 | };
|
510 |
|
511 | Updater.prototype.enqueueReplaceState = function enqueueReplaceState(publicInstance, completeState, callback, callerName) {
|
512 | this._enqueueCallback(callback, publicInstance);
|
513 | this._renderer._newState = completeState;
|
514 | this._renderer.render(this._renderer._element, this._renderer._context);
|
515 | };
|
516 |
|
517 | Updater.prototype.enqueueSetState = function enqueueSetState(publicInstance, partialState, callback, callerName) {
|
518 | this._enqueueCallback(callback, publicInstance);
|
519 | var currentState = this._renderer._newState || publicInstance.state;
|
520 |
|
521 | if (typeof partialState === 'function') {
|
522 | partialState = partialState.call(publicInstance, currentState, publicInstance.props);
|
523 | }
|
524 |
|
525 |
|
526 | if (partialState === null || partialState === undefined) {
|
527 | return;
|
528 | }
|
529 |
|
530 | this._renderer._newState = _assign({}, currentState, partialState);
|
531 |
|
532 | this._renderer.render(this._renderer._element, this._renderer._context);
|
533 | };
|
534 |
|
535 | return Updater;
|
536 | }();
|
537 |
|
538 | var ReactShallowRenderer = function () {
|
539 | function ReactShallowRenderer() {
|
540 | _classCallCheck(this, ReactShallowRenderer);
|
541 |
|
542 | this._context = null;
|
543 | this._element = null;
|
544 | this._instance = null;
|
545 | this._newState = null;
|
546 | this._rendered = null;
|
547 | this._rendering = false;
|
548 | this._forcedUpdate = false;
|
549 | this._updater = new Updater(this);
|
550 | }
|
551 |
|
552 | ReactShallowRenderer.prototype.getMountedInstance = function getMountedInstance() {
|
553 | return this._instance;
|
554 | };
|
555 |
|
556 | ReactShallowRenderer.prototype.getRenderOutput = function getRenderOutput() {
|
557 | return this._rendered;
|
558 | };
|
559 |
|
560 | ReactShallowRenderer.prototype.render = function render(element) {
|
561 | var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : emptyObject;
|
562 |
|
563 | !React.isValidElement(element) ? invariant(false, 'ReactShallowRenderer render(): Invalid component element.%s', typeof element === 'function' ? ' Instead of passing a component class, make sure to instantiate ' + 'it by passing it to React.createElement.' : '') : void 0;
|
564 |
|
565 | !(typeof element.type !== 'string') ? invariant(false, 'ReactShallowRenderer render(): Shallow rendering works only with custom components, not primitives (%s). Instead of calling `.render(el)` and inspecting the rendered output, look at `el.props` directly instead.', element.type) : void 0;
|
566 | !(isForwardRef(element) || typeof element.type === 'function') ? invariant(false, 'ReactShallowRenderer render(): Shallow rendering works only with custom components, but the provided element type was `%s`.', Array.isArray(element.type) ? 'array' : element.type === null ? 'null' : typeof element.type) : void 0;
|
567 |
|
568 | if (this._rendering) {
|
569 | return;
|
570 | }
|
571 |
|
572 | this._rendering = true;
|
573 | this._element = element;
|
574 | this._context = getMaskedContext(element.type.contextTypes, context);
|
575 |
|
576 | if (this._instance) {
|
577 | this._updateClassComponent(element, this._context);
|
578 | } else {
|
579 | if (isForwardRef(element)) {
|
580 | this._rendered = element.type.render(element.props, element.ref);
|
581 | } else if (shouldConstruct(element.type)) {
|
582 | this._instance = new element.type(element.props, this._context, this._updater);
|
583 |
|
584 | this._updateStateFromStaticLifecycle(element.props);
|
585 |
|
586 | if (element.type.hasOwnProperty('contextTypes')) {
|
587 | currentlyValidatingElement = element;
|
588 |
|
589 | checkPropTypes_1(element.type.contextTypes, this._context, 'context', getName(element.type, this._instance), getStackAddendum);
|
590 |
|
591 | currentlyValidatingElement = null;
|
592 | }
|
593 |
|
594 | this._mountClassComponent(element, this._context);
|
595 | } else {
|
596 | this._rendered = element.type.call(undefined, element.props, this._context);
|
597 | }
|
598 | }
|
599 |
|
600 | this._rendering = false;
|
601 | this._updater._invokeCallbacks();
|
602 |
|
603 | return this.getRenderOutput();
|
604 | };
|
605 |
|
606 | ReactShallowRenderer.prototype.unmount = function unmount() {
|
607 | if (this._instance) {
|
608 | if (typeof this._instance.componentWillUnmount === 'function') {
|
609 | this._instance.componentWillUnmount();
|
610 | }
|
611 | }
|
612 |
|
613 | this._context = null;
|
614 | this._element = null;
|
615 | this._newState = null;
|
616 | this._rendered = null;
|
617 | this._instance = null;
|
618 | };
|
619 |
|
620 | ReactShallowRenderer.prototype._mountClassComponent = function _mountClassComponent(element, context) {
|
621 | this._instance.context = context;
|
622 | this._instance.props = element.props;
|
623 | this._instance.state = this._instance.state || null;
|
624 | this._instance.updater = this._updater;
|
625 |
|
626 | if (typeof this._instance.UNSAFE_componentWillMount === 'function' || typeof this._instance.componentWillMount === 'function') {
|
627 | var beforeState = this._newState;
|
628 |
|
629 |
|
630 |
|
631 | if (typeof element.type.getDerivedStateFromProps !== 'function' && typeof this._instance.getSnapshotBeforeUpdate !== 'function') {
|
632 | if (typeof this._instance.componentWillMount === 'function') {
|
633 | this._instance.componentWillMount();
|
634 | }
|
635 | if (typeof this._instance.UNSAFE_componentWillMount === 'function') {
|
636 | this._instance.UNSAFE_componentWillMount();
|
637 | }
|
638 | }
|
639 |
|
640 |
|
641 | if (beforeState !== this._newState) {
|
642 | this._instance.state = this._newState || emptyObject;
|
643 | }
|
644 | }
|
645 |
|
646 | this._rendered = this._instance.render();
|
647 |
|
648 |
|
649 | };
|
650 |
|
651 | ReactShallowRenderer.prototype._updateClassComponent = function _updateClassComponent(element, context) {
|
652 | var props = element.props,
|
653 | type = element.type;
|
654 |
|
655 |
|
656 | var oldState = this._instance.state || emptyObject;
|
657 | var oldProps = this._instance.props;
|
658 |
|
659 | if (oldProps !== props) {
|
660 |
|
661 |
|
662 | if (typeof element.type.getDerivedStateFromProps !== 'function' && typeof this._instance.getSnapshotBeforeUpdate !== 'function') {
|
663 | if (typeof this._instance.componentWillReceiveProps === 'function') {
|
664 | this._instance.componentWillReceiveProps(props, context);
|
665 | }
|
666 | if (typeof this._instance.UNSAFE_componentWillReceiveProps === 'function') {
|
667 | this._instance.UNSAFE_componentWillReceiveProps(props, context);
|
668 | }
|
669 | }
|
670 | }
|
671 | this._updateStateFromStaticLifecycle(props);
|
672 |
|
673 |
|
674 | var state = this._newState || oldState;
|
675 |
|
676 | var shouldUpdate = true;
|
677 | if (this._forcedUpdate) {
|
678 | shouldUpdate = true;
|
679 | this._forcedUpdate = false;
|
680 | } else if (typeof this._instance.shouldComponentUpdate === 'function') {
|
681 | shouldUpdate = !!this._instance.shouldComponentUpdate(props, state, context);
|
682 | } else if (type.prototype && type.prototype.isPureReactComponent) {
|
683 | shouldUpdate = !shallowEqual(oldProps, props) || !shallowEqual(oldState, state);
|
684 | }
|
685 |
|
686 | if (shouldUpdate) {
|
687 |
|
688 |
|
689 | if (typeof element.type.getDerivedStateFromProps !== 'function' && typeof this._instance.getSnapshotBeforeUpdate !== 'function') {
|
690 | if (typeof this._instance.componentWillUpdate === 'function') {
|
691 | this._instance.componentWillUpdate(props, state, context);
|
692 | }
|
693 | if (typeof this._instance.UNSAFE_componentWillUpdate === 'function') {
|
694 | this._instance.UNSAFE_componentWillUpdate(props, state, context);
|
695 | }
|
696 | }
|
697 | }
|
698 |
|
699 | this._instance.context = context;
|
700 | this._instance.props = props;
|
701 | this._instance.state = state;
|
702 |
|
703 | if (shouldUpdate) {
|
704 | this._rendered = this._instance.render();
|
705 | }
|
706 |
|
707 |
|
708 | };
|
709 |
|
710 | ReactShallowRenderer.prototype._updateStateFromStaticLifecycle = function _updateStateFromStaticLifecycle(props) {
|
711 | var type = this._element.type;
|
712 |
|
713 |
|
714 | if (typeof type.getDerivedStateFromProps === 'function') {
|
715 | var oldState = this._newState || this._instance.state;
|
716 | var partialState = type.getDerivedStateFromProps.call(null, props, oldState);
|
717 |
|
718 | if (partialState != null) {
|
719 | var newState = _assign({}, oldState, partialState);
|
720 | this._instance.state = this._newState = newState;
|
721 | }
|
722 | }
|
723 | };
|
724 |
|
725 | return ReactShallowRenderer;
|
726 | }();
|
727 |
|
728 | ReactShallowRenderer.createRenderer = function () {
|
729 | return new ReactShallowRenderer();
|
730 | };
|
731 |
|
732 | var currentlyValidatingElement = null;
|
733 |
|
734 | function getDisplayName(element) {
|
735 | if (element == null) {
|
736 | return '#empty';
|
737 | } else if (typeof element === 'string' || typeof element === 'number') {
|
738 | return '#text';
|
739 | } else if (typeof element.type === 'string') {
|
740 | return element.type;
|
741 | } else {
|
742 | return element.type.displayName || element.type.name || 'Unknown';
|
743 | }
|
744 | }
|
745 |
|
746 | function getStackAddendum() {
|
747 | var stack = '';
|
748 | if (currentlyValidatingElement) {
|
749 | var name = getDisplayName(currentlyValidatingElement);
|
750 | var owner = currentlyValidatingElement._owner;
|
751 | stack += describeComponentFrame(name, currentlyValidatingElement._source, owner && getComponentName(owner.type));
|
752 | }
|
753 | return stack;
|
754 | }
|
755 |
|
756 | function getName(type, instance) {
|
757 | var constructor = instance && instance.constructor;
|
758 | return type.displayName || constructor && constructor.displayName || type.name || constructor && constructor.name || null;
|
759 | }
|
760 |
|
761 | function shouldConstruct(Component) {
|
762 | return !!(Component.prototype && Component.prototype.isReactComponent);
|
763 | }
|
764 |
|
765 | function getMaskedContext(contextTypes, unmaskedContext) {
|
766 | if (!contextTypes) {
|
767 | return emptyObject;
|
768 | }
|
769 | var context = {};
|
770 | for (var key in contextTypes) {
|
771 | context[key] = unmaskedContext[key];
|
772 | }
|
773 | return context;
|
774 | }
|
775 |
|
776 |
|
777 |
|
778 | var ReactShallowRenderer$2 = Object.freeze({
|
779 | default: ReactShallowRenderer
|
780 | });
|
781 |
|
782 | var ReactShallowRenderer$3 = ( ReactShallowRenderer$2 && ReactShallowRenderer ) || ReactShallowRenderer$2;
|
783 |
|
784 |
|
785 |
|
786 | var shallow = ReactShallowRenderer$3.default || ReactShallowRenderer$3;
|
787 |
|
788 | return shallow;
|
789 |
|
790 | })));
|