react-test-renderer 16.6.2 → 16.6.3
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/cjs/react-test-renderer.development.js +36 -43
- package/cjs/react-test-renderer.production.min.js +120 -121
- package/package.json +6 -6
- package/umd/react-test-renderer-shallow.development.js +785 -0
- package/umd/react-test-renderer-shallow.production.min.js +22 -0
- package/umd/react-test-renderer.development.js +12107 -0
- package/umd/react-test-renderer.production.min.js +121 -0
|
@@ -0,0 +1,785 @@
|
|
|
1
|
+
/** @license React v16.6.1
|
|
2
|
+
* react-test-renderer-shallow.development.js
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
(function (global, factory) {
|
|
13
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('react')) :
|
|
14
|
+
typeof define === 'function' && define.amd ? define(['react'], factory) :
|
|
15
|
+
(global.ReactShallowRenderer = factory(global.React));
|
|
16
|
+
}(this, (function (React) { 'use strict';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Use invariant() to assert state which your program assumes to be true.
|
|
20
|
+
*
|
|
21
|
+
* Provide sprintf-style format (only %s is supported) and arguments
|
|
22
|
+
* to provide information about what broke and what you were
|
|
23
|
+
* expecting.
|
|
24
|
+
*
|
|
25
|
+
* The invariant message will be stripped in production, but the invariant
|
|
26
|
+
* will remain to ensure logic does not differ in production.
|
|
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; // we don't care about invariant's own frame
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Relying on the `invariant()` implementation lets us
|
|
61
|
+
// preserve the format and params in the www builds.
|
|
62
|
+
|
|
63
|
+
var ReactInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
|
64
|
+
|
|
65
|
+
var _assign = ReactInternals.assign;
|
|
66
|
+
|
|
67
|
+
// The Symbol used to tag the ReactElement-like types. If there is no native Symbol
|
|
68
|
+
// nor polyfill, then a plain number is used for performance.
|
|
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
|
+
* Forked from fbjs/warning:
|
|
87
|
+
* https://github.com/facebook/fbjs/blob/e66ba20ad5be433eb54423f2b097d829324d9de6/packages/fbjs/src/__forks__/warning.js
|
|
88
|
+
*
|
|
89
|
+
* Only change is we use console.warn instead of console.error,
|
|
90
|
+
* and do nothing when 'console' is not supported.
|
|
91
|
+
* This really simplifies the code.
|
|
92
|
+
* ---
|
|
93
|
+
* Similar to invariant but only logs a warning if the condition is not met.
|
|
94
|
+
* This can be used to log issues in development environments in critical
|
|
95
|
+
* paths. Removing the logging code for production environments will keep the
|
|
96
|
+
* same logic and follow the same code paths.
|
|
97
|
+
*/
|
|
98
|
+
|
|
99
|
+
{
|
|
100
|
+
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function typeOf(object) {
|
|
104
|
+
if (typeof object === 'object' && object !== null) {
|
|
105
|
+
var $$typeof = object.$$typeof;
|
|
106
|
+
|
|
107
|
+
switch ($$typeof) {
|
|
108
|
+
case REACT_ELEMENT_TYPE:
|
|
109
|
+
var type = object.type;
|
|
110
|
+
|
|
111
|
+
switch (type) {
|
|
112
|
+
case REACT_ASYNC_MODE_TYPE:
|
|
113
|
+
case REACT_CONCURRENT_MODE_TYPE:
|
|
114
|
+
case REACT_FRAGMENT_TYPE:
|
|
115
|
+
case REACT_PROFILER_TYPE:
|
|
116
|
+
case REACT_STRICT_MODE_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_PORTAL_TYPE:
|
|
131
|
+
return $$typeof;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// AsyncMode is deprecated along with isAsyncMode
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
// AsyncMode should be deprecated
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
function isForwardRef(object) {
|
|
157
|
+
return typeOf(object) === REACT_FORWARD_REF_TYPE;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
var BEFORE_SLASH_RE = /^(.*)[\\\/]/;
|
|
161
|
+
|
|
162
|
+
var describeComponentFrame = function (name, source, ownerName) {
|
|
163
|
+
var sourceInfo = '';
|
|
164
|
+
if (source) {
|
|
165
|
+
var path = source.fileName;
|
|
166
|
+
var fileName = path.replace(BEFORE_SLASH_RE, '');
|
|
167
|
+
{
|
|
168
|
+
// In DEV, include code for a common special case:
|
|
169
|
+
// prefer "folder/index.js" instead of just "index.js".
|
|
170
|
+
if (/^index\./.test(fileName)) {
|
|
171
|
+
var match = path.match(BEFORE_SLASH_RE);
|
|
172
|
+
if (match) {
|
|
173
|
+
var pathBeforeSlash = match[1];
|
|
174
|
+
if (pathBeforeSlash) {
|
|
175
|
+
var folderName = pathBeforeSlash.replace(BEFORE_SLASH_RE, '');
|
|
176
|
+
fileName = folderName + '/' + fileName;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
sourceInfo = ' (at ' + fileName + ':' + source.lineNumber + ')';
|
|
182
|
+
} else if (ownerName) {
|
|
183
|
+
sourceInfo = ' (created by ' + ownerName + ')';
|
|
184
|
+
}
|
|
185
|
+
return '\n in ' + (name || 'Unknown') + sourceInfo;
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Similar to invariant but only logs a warning if the condition is not met.
|
|
190
|
+
* This can be used to log issues in development environments in critical
|
|
191
|
+
* paths. Removing the logging code for production environments will keep the
|
|
192
|
+
* same logic and follow the same code paths.
|
|
193
|
+
*/
|
|
194
|
+
|
|
195
|
+
var warningWithoutStack = function () {};
|
|
196
|
+
|
|
197
|
+
{
|
|
198
|
+
warningWithoutStack = function (condition, format) {
|
|
199
|
+
for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
200
|
+
args[_key - 2] = arguments[_key];
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (format === undefined) {
|
|
204
|
+
throw new Error('`warningWithoutStack(condition, format, ...args)` requires a warning ' + 'message argument');
|
|
205
|
+
}
|
|
206
|
+
if (args.length > 8) {
|
|
207
|
+
// Check before the condition to catch violations early.
|
|
208
|
+
throw new Error('warningWithoutStack() currently supports at most 8 arguments.');
|
|
209
|
+
}
|
|
210
|
+
if (condition) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
if (typeof console !== 'undefined') {
|
|
214
|
+
var argsWithFormat = args.map(function (item) {
|
|
215
|
+
return '' + item;
|
|
216
|
+
});
|
|
217
|
+
argsWithFormat.unshift('Warning: ' + format);
|
|
218
|
+
|
|
219
|
+
// We intentionally don't use spread (or .apply) directly because it
|
|
220
|
+
// breaks IE9: https://github.com/facebook/react/issues/13610
|
|
221
|
+
Function.prototype.apply.call(console.error, console, argsWithFormat);
|
|
222
|
+
}
|
|
223
|
+
try {
|
|
224
|
+
// --- Welcome to debugging React ---
|
|
225
|
+
// This error was thrown as a convenience so that you can use this stack
|
|
226
|
+
// to find the callsite that caused this warning to fire.
|
|
227
|
+
var argIndex = 0;
|
|
228
|
+
var message = 'Warning: ' + format.replace(/%s/g, function () {
|
|
229
|
+
return args[argIndex++];
|
|
230
|
+
});
|
|
231
|
+
throw new Error(message);
|
|
232
|
+
} catch (x) {}
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
var warningWithoutStack$1 = warningWithoutStack;
|
|
237
|
+
|
|
238
|
+
var Resolved = 1;
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
function refineResolvedLazyComponent(lazyComponent) {
|
|
242
|
+
return lazyComponent._status === Resolved ? lazyComponent._result : null;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function getWrappedName(outerType, innerType, wrapperName) {
|
|
246
|
+
var functionName = innerType.displayName || innerType.name || '';
|
|
247
|
+
return outerType.displayName || (functionName !== '' ? wrapperName + '(' + functionName + ')' : wrapperName);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function getComponentName(type) {
|
|
251
|
+
if (type == null) {
|
|
252
|
+
// Host root, text node or just invalid type.
|
|
253
|
+
return null;
|
|
254
|
+
}
|
|
255
|
+
{
|
|
256
|
+
if (typeof type.tag === 'number') {
|
|
257
|
+
warningWithoutStack$1(false, 'Received an unexpected object in getComponentName(). ' + 'This is likely a bug in React. Please file an issue.');
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
if (typeof type === 'function') {
|
|
261
|
+
return type.displayName || type.name || null;
|
|
262
|
+
}
|
|
263
|
+
if (typeof type === 'string') {
|
|
264
|
+
return type;
|
|
265
|
+
}
|
|
266
|
+
switch (type) {
|
|
267
|
+
case REACT_CONCURRENT_MODE_TYPE:
|
|
268
|
+
return 'ConcurrentMode';
|
|
269
|
+
case REACT_FRAGMENT_TYPE:
|
|
270
|
+
return 'Fragment';
|
|
271
|
+
case REACT_PORTAL_TYPE:
|
|
272
|
+
return 'Portal';
|
|
273
|
+
case REACT_PROFILER_TYPE:
|
|
274
|
+
return 'Profiler';
|
|
275
|
+
case REACT_STRICT_MODE_TYPE:
|
|
276
|
+
return 'StrictMode';
|
|
277
|
+
case REACT_SUSPENSE_TYPE:
|
|
278
|
+
return 'Suspense';
|
|
279
|
+
}
|
|
280
|
+
if (typeof type === 'object') {
|
|
281
|
+
switch (type.$$typeof) {
|
|
282
|
+
case REACT_CONTEXT_TYPE:
|
|
283
|
+
return 'Context.Consumer';
|
|
284
|
+
case REACT_PROVIDER_TYPE:
|
|
285
|
+
return 'Context.Provider';
|
|
286
|
+
case REACT_FORWARD_REF_TYPE:
|
|
287
|
+
return getWrappedName(type, type.render, 'ForwardRef');
|
|
288
|
+
case REACT_MEMO_TYPE:
|
|
289
|
+
return getComponentName(type.type);
|
|
290
|
+
case REACT_LAZY_TYPE:
|
|
291
|
+
{
|
|
292
|
+
var thenable = type;
|
|
293
|
+
var resolvedThenable = refineResolvedLazyComponent(thenable);
|
|
294
|
+
if (resolvedThenable) {
|
|
295
|
+
return getComponentName(resolvedThenable);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
return null;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/*eslint-disable no-self-compare */
|
|
304
|
+
|
|
305
|
+
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* inlined Object.is polyfill to avoid requiring consumers ship their own
|
|
309
|
+
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
|
|
310
|
+
*/
|
|
311
|
+
function is(x, y) {
|
|
312
|
+
// SameValue algorithm
|
|
313
|
+
if (x === y) {
|
|
314
|
+
// Steps 1-5, 7-10
|
|
315
|
+
// Steps 6.b-6.e: +0 != -0
|
|
316
|
+
// Added the nonzero y check to make Flow happy, but it is redundant
|
|
317
|
+
return x !== 0 || y !== 0 || 1 / x === 1 / y;
|
|
318
|
+
} else {
|
|
319
|
+
// Step 6.a: NaN == NaN
|
|
320
|
+
return x !== x && y !== y;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Performs equality by iterating through keys on an object and returning false
|
|
326
|
+
* when any key has values which are not strictly equal between the arguments.
|
|
327
|
+
* Returns true when the values of all keys are strictly equal.
|
|
328
|
+
*/
|
|
329
|
+
function shallowEqual(objA, objB) {
|
|
330
|
+
if (is(objA, objB)) {
|
|
331
|
+
return true;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
|
|
335
|
+
return false;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
var keysA = Object.keys(objA);
|
|
339
|
+
var keysB = Object.keys(objB);
|
|
340
|
+
|
|
341
|
+
if (keysA.length !== keysB.length) {
|
|
342
|
+
return false;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// Test for A's keys different from B.
|
|
346
|
+
for (var i = 0; i < keysA.length; i++) {
|
|
347
|
+
if (!hasOwnProperty.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) {
|
|
348
|
+
return false;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
return true;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Copyright (c) 2013-present, Facebook, Inc.
|
|
357
|
+
*
|
|
358
|
+
* This source code is licensed under the MIT license found in the
|
|
359
|
+
* LICENSE file in the root directory of this source tree.
|
|
360
|
+
*/
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
var ReactPropTypesSecret$1 = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
|
|
365
|
+
|
|
366
|
+
var ReactPropTypesSecret_1 = ReactPropTypesSecret$1;
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* Copyright (c) 2013-present, Facebook, Inc.
|
|
370
|
+
*
|
|
371
|
+
* This source code is licensed under the MIT license found in the
|
|
372
|
+
* LICENSE file in the root directory of this source tree.
|
|
373
|
+
*/
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
var printWarning$1 = function() {};
|
|
378
|
+
|
|
379
|
+
{
|
|
380
|
+
var ReactPropTypesSecret = ReactPropTypesSecret_1;
|
|
381
|
+
var loggedTypeFailures = {};
|
|
382
|
+
|
|
383
|
+
printWarning$1 = function(text) {
|
|
384
|
+
var message = 'Warning: ' + text;
|
|
385
|
+
if (typeof console !== 'undefined') {
|
|
386
|
+
console.error(message);
|
|
387
|
+
}
|
|
388
|
+
try {
|
|
389
|
+
// --- Welcome to debugging React ---
|
|
390
|
+
// This error was thrown as a convenience so that you can use this stack
|
|
391
|
+
// to find the callsite that caused this warning to fire.
|
|
392
|
+
throw new Error(message);
|
|
393
|
+
} catch (x) {}
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Assert that the values match with the type specs.
|
|
399
|
+
* Error messages are memorized and will only be shown once.
|
|
400
|
+
*
|
|
401
|
+
* @param {object} typeSpecs Map of name to a ReactPropType
|
|
402
|
+
* @param {object} values Runtime values that need to be type-checked
|
|
403
|
+
* @param {string} location e.g. "prop", "context", "child context"
|
|
404
|
+
* @param {string} componentName Name of the component for error messages.
|
|
405
|
+
* @param {?Function} getStack Returns the component stack.
|
|
406
|
+
* @private
|
|
407
|
+
*/
|
|
408
|
+
function checkPropTypes(typeSpecs, values, location, componentName, getStack) {
|
|
409
|
+
{
|
|
410
|
+
for (var typeSpecName in typeSpecs) {
|
|
411
|
+
if (typeSpecs.hasOwnProperty(typeSpecName)) {
|
|
412
|
+
var error;
|
|
413
|
+
// Prop type validation may throw. In case they do, we don't want to
|
|
414
|
+
// fail the render phase where it didn't fail before. So we log it.
|
|
415
|
+
// After these have been cleaned up, we'll let them throw.
|
|
416
|
+
try {
|
|
417
|
+
// This is intentionally an invariant that gets caught. It's the same
|
|
418
|
+
// behavior as without this statement except with a better message.
|
|
419
|
+
if (typeof typeSpecs[typeSpecName] !== 'function') {
|
|
420
|
+
var err = Error(
|
|
421
|
+
(componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' +
|
|
422
|
+
'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.'
|
|
423
|
+
);
|
|
424
|
+
err.name = 'Invariant Violation';
|
|
425
|
+
throw err;
|
|
426
|
+
}
|
|
427
|
+
error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret);
|
|
428
|
+
} catch (ex) {
|
|
429
|
+
error = ex;
|
|
430
|
+
}
|
|
431
|
+
if (error && !(error instanceof Error)) {
|
|
432
|
+
printWarning$1(
|
|
433
|
+
(componentName || 'React class') + ': type specification of ' +
|
|
434
|
+
location + ' `' + typeSpecName + '` is invalid; the type checker ' +
|
|
435
|
+
'function must return `null` or an `Error` but returned a ' + typeof error + '. ' +
|
|
436
|
+
'You may have forgotten to pass an argument to the type checker ' +
|
|
437
|
+
'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' +
|
|
438
|
+
'shape all require an argument).'
|
|
439
|
+
);
|
|
440
|
+
|
|
441
|
+
}
|
|
442
|
+
if (error instanceof Error && !(error.message in loggedTypeFailures)) {
|
|
443
|
+
// Only monitor this failure once because there tends to be a lot of the
|
|
444
|
+
// same error.
|
|
445
|
+
loggedTypeFailures[error.message] = true;
|
|
446
|
+
|
|
447
|
+
var stack = getStack ? getStack() : '';
|
|
448
|
+
|
|
449
|
+
printWarning$1(
|
|
450
|
+
'Failed ' + location + ' type: ' + error.message + (stack != null ? stack : '')
|
|
451
|
+
);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
var checkPropTypes_1 = checkPropTypes;
|
|
459
|
+
|
|
460
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
461
|
+
|
|
462
|
+
var emptyObject = {};
|
|
463
|
+
{
|
|
464
|
+
Object.freeze(emptyObject);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
var Updater = function () {
|
|
468
|
+
function Updater(renderer) {
|
|
469
|
+
_classCallCheck(this, Updater);
|
|
470
|
+
|
|
471
|
+
this._renderer = renderer;
|
|
472
|
+
this._callbacks = [];
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
Updater.prototype._enqueueCallback = function _enqueueCallback(callback, publicInstance) {
|
|
476
|
+
if (typeof callback === 'function' && publicInstance) {
|
|
477
|
+
this._callbacks.push({
|
|
478
|
+
callback: callback,
|
|
479
|
+
publicInstance: publicInstance
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
};
|
|
483
|
+
|
|
484
|
+
Updater.prototype._invokeCallbacks = function _invokeCallbacks() {
|
|
485
|
+
var callbacks = this._callbacks;
|
|
486
|
+
this._callbacks = [];
|
|
487
|
+
|
|
488
|
+
callbacks.forEach(function (_ref) {
|
|
489
|
+
var callback = _ref.callback,
|
|
490
|
+
publicInstance = _ref.publicInstance;
|
|
491
|
+
|
|
492
|
+
callback.call(publicInstance);
|
|
493
|
+
});
|
|
494
|
+
};
|
|
495
|
+
|
|
496
|
+
Updater.prototype.isMounted = function isMounted(publicInstance) {
|
|
497
|
+
return !!this._renderer._element;
|
|
498
|
+
};
|
|
499
|
+
|
|
500
|
+
Updater.prototype.enqueueForceUpdate = function enqueueForceUpdate(publicInstance, callback, callerName) {
|
|
501
|
+
this._enqueueCallback(callback, publicInstance);
|
|
502
|
+
this._renderer._forcedUpdate = true;
|
|
503
|
+
this._renderer.render(this._renderer._element, this._renderer._context);
|
|
504
|
+
};
|
|
505
|
+
|
|
506
|
+
Updater.prototype.enqueueReplaceState = function enqueueReplaceState(publicInstance, completeState, callback, callerName) {
|
|
507
|
+
this._enqueueCallback(callback, publicInstance);
|
|
508
|
+
this._renderer._newState = completeState;
|
|
509
|
+
this._renderer.render(this._renderer._element, this._renderer._context);
|
|
510
|
+
};
|
|
511
|
+
|
|
512
|
+
Updater.prototype.enqueueSetState = function enqueueSetState(publicInstance, partialState, callback, callerName) {
|
|
513
|
+
this._enqueueCallback(callback, publicInstance);
|
|
514
|
+
var currentState = this._renderer._newState || publicInstance.state;
|
|
515
|
+
|
|
516
|
+
if (typeof partialState === 'function') {
|
|
517
|
+
partialState = partialState.call(publicInstance, currentState, publicInstance.props);
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
// Null and undefined are treated as no-ops.
|
|
521
|
+
if (partialState === null || partialState === undefined) {
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
this._renderer._newState = _assign({}, currentState, partialState);
|
|
526
|
+
|
|
527
|
+
this._renderer.render(this._renderer._element, this._renderer._context);
|
|
528
|
+
};
|
|
529
|
+
|
|
530
|
+
return Updater;
|
|
531
|
+
}();
|
|
532
|
+
|
|
533
|
+
var ReactShallowRenderer = function () {
|
|
534
|
+
function ReactShallowRenderer() {
|
|
535
|
+
_classCallCheck(this, ReactShallowRenderer);
|
|
536
|
+
|
|
537
|
+
this._context = null;
|
|
538
|
+
this._element = null;
|
|
539
|
+
this._instance = null;
|
|
540
|
+
this._newState = null;
|
|
541
|
+
this._rendered = null;
|
|
542
|
+
this._rendering = false;
|
|
543
|
+
this._forcedUpdate = false;
|
|
544
|
+
this._updater = new Updater(this);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
ReactShallowRenderer.prototype.getMountedInstance = function getMountedInstance() {
|
|
548
|
+
return this._instance;
|
|
549
|
+
};
|
|
550
|
+
|
|
551
|
+
ReactShallowRenderer.prototype.getRenderOutput = function getRenderOutput() {
|
|
552
|
+
return this._rendered;
|
|
553
|
+
};
|
|
554
|
+
|
|
555
|
+
ReactShallowRenderer.prototype.render = function render(element) {
|
|
556
|
+
var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : emptyObject;
|
|
557
|
+
|
|
558
|
+
!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;
|
|
559
|
+
// Show a special message for host elements since it's a common case.
|
|
560
|
+
!(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;
|
|
561
|
+
!(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;
|
|
562
|
+
|
|
563
|
+
if (this._rendering) {
|
|
564
|
+
return;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
this._rendering = true;
|
|
568
|
+
this._element = element;
|
|
569
|
+
this._context = getMaskedContext(element.type.contextTypes, context);
|
|
570
|
+
|
|
571
|
+
if (this._instance) {
|
|
572
|
+
this._updateClassComponent(element, this._context);
|
|
573
|
+
} else {
|
|
574
|
+
if (isForwardRef(element)) {
|
|
575
|
+
this._rendered = element.type.render(element.props, element.ref);
|
|
576
|
+
} else if (shouldConstruct(element.type)) {
|
|
577
|
+
this._instance = new element.type(element.props, this._context, this._updater);
|
|
578
|
+
|
|
579
|
+
this._updateStateFromStaticLifecycle(element.props);
|
|
580
|
+
|
|
581
|
+
if (element.type.hasOwnProperty('contextTypes')) {
|
|
582
|
+
currentlyValidatingElement = element;
|
|
583
|
+
|
|
584
|
+
checkPropTypes_1(element.type.contextTypes, this._context, 'context', getName(element.type, this._instance), getStackAddendum);
|
|
585
|
+
|
|
586
|
+
currentlyValidatingElement = null;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
this._mountClassComponent(element, this._context);
|
|
590
|
+
} else {
|
|
591
|
+
this._rendered = element.type.call(undefined, element.props, this._context);
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
this._rendering = false;
|
|
596
|
+
this._updater._invokeCallbacks();
|
|
597
|
+
|
|
598
|
+
return this.getRenderOutput();
|
|
599
|
+
};
|
|
600
|
+
|
|
601
|
+
ReactShallowRenderer.prototype.unmount = function unmount() {
|
|
602
|
+
if (this._instance) {
|
|
603
|
+
if (typeof this._instance.componentWillUnmount === 'function') {
|
|
604
|
+
this._instance.componentWillUnmount();
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
this._context = null;
|
|
609
|
+
this._element = null;
|
|
610
|
+
this._newState = null;
|
|
611
|
+
this._rendered = null;
|
|
612
|
+
this._instance = null;
|
|
613
|
+
};
|
|
614
|
+
|
|
615
|
+
ReactShallowRenderer.prototype._mountClassComponent = function _mountClassComponent(element, context) {
|
|
616
|
+
this._instance.context = context;
|
|
617
|
+
this._instance.props = element.props;
|
|
618
|
+
this._instance.state = this._instance.state || null;
|
|
619
|
+
this._instance.updater = this._updater;
|
|
620
|
+
|
|
621
|
+
if (typeof this._instance.UNSAFE_componentWillMount === 'function' || typeof this._instance.componentWillMount === 'function') {
|
|
622
|
+
var beforeState = this._newState;
|
|
623
|
+
|
|
624
|
+
// In order to support react-lifecycles-compat polyfilled components,
|
|
625
|
+
// Unsafe lifecycles should not be invoked for components using the new APIs.
|
|
626
|
+
if (typeof element.type.getDerivedStateFromProps !== 'function' && typeof this._instance.getSnapshotBeforeUpdate !== 'function') {
|
|
627
|
+
if (typeof this._instance.componentWillMount === 'function') {
|
|
628
|
+
this._instance.componentWillMount();
|
|
629
|
+
}
|
|
630
|
+
if (typeof this._instance.UNSAFE_componentWillMount === 'function') {
|
|
631
|
+
this._instance.UNSAFE_componentWillMount();
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
// setState may have been called during cWM
|
|
636
|
+
if (beforeState !== this._newState) {
|
|
637
|
+
this._instance.state = this._newState || emptyObject;
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
this._rendered = this._instance.render();
|
|
642
|
+
// Intentionally do not call componentDidMount()
|
|
643
|
+
// because DOM refs are not available.
|
|
644
|
+
};
|
|
645
|
+
|
|
646
|
+
ReactShallowRenderer.prototype._updateClassComponent = function _updateClassComponent(element, context) {
|
|
647
|
+
var props = element.props,
|
|
648
|
+
type = element.type;
|
|
649
|
+
|
|
650
|
+
|
|
651
|
+
var oldState = this._instance.state || emptyObject;
|
|
652
|
+
var oldProps = this._instance.props;
|
|
653
|
+
|
|
654
|
+
if (oldProps !== props) {
|
|
655
|
+
// In order to support react-lifecycles-compat polyfilled components,
|
|
656
|
+
// Unsafe lifecycles should not be invoked for components using the new APIs.
|
|
657
|
+
if (typeof element.type.getDerivedStateFromProps !== 'function' && typeof this._instance.getSnapshotBeforeUpdate !== 'function') {
|
|
658
|
+
if (typeof this._instance.componentWillReceiveProps === 'function') {
|
|
659
|
+
this._instance.componentWillReceiveProps(props, context);
|
|
660
|
+
}
|
|
661
|
+
if (typeof this._instance.UNSAFE_componentWillReceiveProps === 'function') {
|
|
662
|
+
this._instance.UNSAFE_componentWillReceiveProps(props, context);
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
this._updateStateFromStaticLifecycle(props);
|
|
667
|
+
|
|
668
|
+
// Read state after cWRP in case it calls setState
|
|
669
|
+
var state = this._newState || oldState;
|
|
670
|
+
|
|
671
|
+
var shouldUpdate = true;
|
|
672
|
+
if (this._forcedUpdate) {
|
|
673
|
+
shouldUpdate = true;
|
|
674
|
+
this._forcedUpdate = false;
|
|
675
|
+
} else if (typeof this._instance.shouldComponentUpdate === 'function') {
|
|
676
|
+
shouldUpdate = !!this._instance.shouldComponentUpdate(props, state, context);
|
|
677
|
+
} else if (type.prototype && type.prototype.isPureReactComponent) {
|
|
678
|
+
shouldUpdate = !shallowEqual(oldProps, props) || !shallowEqual(oldState, state);
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
if (shouldUpdate) {
|
|
682
|
+
// In order to support react-lifecycles-compat polyfilled components,
|
|
683
|
+
// Unsafe lifecycles should not be invoked for components using the new APIs.
|
|
684
|
+
if (typeof element.type.getDerivedStateFromProps !== 'function' && typeof this._instance.getSnapshotBeforeUpdate !== 'function') {
|
|
685
|
+
if (typeof this._instance.componentWillUpdate === 'function') {
|
|
686
|
+
this._instance.componentWillUpdate(props, state, context);
|
|
687
|
+
}
|
|
688
|
+
if (typeof this._instance.UNSAFE_componentWillUpdate === 'function') {
|
|
689
|
+
this._instance.UNSAFE_componentWillUpdate(props, state, context);
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
this._instance.context = context;
|
|
695
|
+
this._instance.props = props;
|
|
696
|
+
this._instance.state = state;
|
|
697
|
+
|
|
698
|
+
if (shouldUpdate) {
|
|
699
|
+
this._rendered = this._instance.render();
|
|
700
|
+
}
|
|
701
|
+
// Intentionally do not call componentDidUpdate()
|
|
702
|
+
// because DOM refs are not available.
|
|
703
|
+
};
|
|
704
|
+
|
|
705
|
+
ReactShallowRenderer.prototype._updateStateFromStaticLifecycle = function _updateStateFromStaticLifecycle(props) {
|
|
706
|
+
var type = this._element.type;
|
|
707
|
+
|
|
708
|
+
|
|
709
|
+
if (typeof type.getDerivedStateFromProps === 'function') {
|
|
710
|
+
var oldState = this._newState || this._instance.state;
|
|
711
|
+
var partialState = type.getDerivedStateFromProps.call(null, props, oldState);
|
|
712
|
+
|
|
713
|
+
if (partialState != null) {
|
|
714
|
+
var newState = _assign({}, oldState, partialState);
|
|
715
|
+
this._instance.state = this._newState = newState;
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
};
|
|
719
|
+
|
|
720
|
+
return ReactShallowRenderer;
|
|
721
|
+
}();
|
|
722
|
+
|
|
723
|
+
ReactShallowRenderer.createRenderer = function () {
|
|
724
|
+
return new ReactShallowRenderer();
|
|
725
|
+
};
|
|
726
|
+
|
|
727
|
+
var currentlyValidatingElement = null;
|
|
728
|
+
|
|
729
|
+
function getDisplayName(element) {
|
|
730
|
+
if (element == null) {
|
|
731
|
+
return '#empty';
|
|
732
|
+
} else if (typeof element === 'string' || typeof element === 'number') {
|
|
733
|
+
return '#text';
|
|
734
|
+
} else if (typeof element.type === 'string') {
|
|
735
|
+
return element.type;
|
|
736
|
+
} else {
|
|
737
|
+
return element.type.displayName || element.type.name || 'Unknown';
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
function getStackAddendum() {
|
|
742
|
+
var stack = '';
|
|
743
|
+
if (currentlyValidatingElement) {
|
|
744
|
+
var name = getDisplayName(currentlyValidatingElement);
|
|
745
|
+
var owner = currentlyValidatingElement._owner;
|
|
746
|
+
stack += describeComponentFrame(name, currentlyValidatingElement._source, owner && getComponentName(owner.type));
|
|
747
|
+
}
|
|
748
|
+
return stack;
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
function getName(type, instance) {
|
|
752
|
+
var constructor = instance && instance.constructor;
|
|
753
|
+
return type.displayName || constructor && constructor.displayName || type.name || constructor && constructor.name || null;
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
function shouldConstruct(Component) {
|
|
757
|
+
return !!(Component.prototype && Component.prototype.isReactComponent);
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
function getMaskedContext(contextTypes, unmaskedContext) {
|
|
761
|
+
if (!contextTypes) {
|
|
762
|
+
return emptyObject;
|
|
763
|
+
}
|
|
764
|
+
var context = {};
|
|
765
|
+
for (var key in contextTypes) {
|
|
766
|
+
context[key] = unmaskedContext[key];
|
|
767
|
+
}
|
|
768
|
+
return context;
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
|
|
772
|
+
|
|
773
|
+
var ReactShallowRenderer$2 = Object.freeze({
|
|
774
|
+
default: ReactShallowRenderer
|
|
775
|
+
});
|
|
776
|
+
|
|
777
|
+
var ReactShallowRenderer$3 = ( ReactShallowRenderer$2 && ReactShallowRenderer ) || ReactShallowRenderer$2;
|
|
778
|
+
|
|
779
|
+
// TODO: decide on the top-level export form.
|
|
780
|
+
// This is hacky but makes it work with both Rollup and Jest.
|
|
781
|
+
var shallow = ReactShallowRenderer$3.default || ReactShallowRenderer$3;
|
|
782
|
+
|
|
783
|
+
return shallow;
|
|
784
|
+
|
|
785
|
+
})));
|