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