react-test-renderer 16.4.0-alpha.7926752 → 16.5.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/README.md +4 -0
- package/cjs/react-test-renderer-shallow.development.js +241 -202
- package/cjs/react-test-renderer-shallow.production.min.js +18 -16
- package/cjs/react-test-renderer.development.js +6747 -5734
- package/cjs/react-test-renderer.production.min.js +124 -132
- package/package.json +7 -5
- package/umd/react-test-renderer-shallow.development.js +749 -0
- package/umd/react-test-renderer-shallow.production.min.js +22 -0
- package/umd/react-test-renderer.development.js +10598 -0
- package/umd/react-test-renderer.production.min.js +110 -0
package/README.md
CHANGED
|
@@ -4,6 +4,10 @@ This package provides an experimental React renderer that can be used to render
|
|
|
4
4
|
|
|
5
5
|
Essentially, this package makes it easy to grab a snapshot of the "DOM tree" rendered by a React DOM or React Native component without using a browser or jsdom.
|
|
6
6
|
|
|
7
|
+
Documentation:
|
|
8
|
+
|
|
9
|
+
[https://reactjs.org/docs/test-renderer.html](https://reactjs.org/docs/test-renderer.html)
|
|
10
|
+
|
|
7
11
|
Usage:
|
|
8
12
|
|
|
9
13
|
```jsx
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license React v16.
|
|
1
|
+
/** @license React v16.5.0
|
|
2
2
|
* react-test-renderer-shallow.development.js
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
@@ -17,157 +17,259 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
17
17
|
|
|
18
18
|
var _assign = require('object-assign');
|
|
19
19
|
var React = require('react');
|
|
20
|
-
var
|
|
21
|
-
var emptyObject = require('fbjs/lib/emptyObject');
|
|
22
|
-
var shallowEqual = require('fbjs/lib/shallowEqual');
|
|
20
|
+
var reactIs = require('react-is');
|
|
23
21
|
var checkPropTypes = require('prop-types/checkPropTypes');
|
|
24
|
-
var warning = require('fbjs/lib/warning');
|
|
25
22
|
|
|
26
23
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
24
|
+
* Use invariant() to assert state which your program assumes to be true.
|
|
25
|
+
*
|
|
26
|
+
* Provide sprintf-style format (only %s is supported) and arguments
|
|
27
|
+
* to provide information about what broke and what you were
|
|
28
|
+
* expecting.
|
|
29
|
+
*
|
|
30
|
+
* The invariant message will be stripped in production, but the invariant
|
|
31
|
+
* will remain to ensure logic does not differ in production.
|
|
31
32
|
*/
|
|
32
33
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
var validateFormat = function () {};
|
|
36
35
|
|
|
37
|
-
|
|
36
|
+
{
|
|
37
|
+
validateFormat = function (format) {
|
|
38
|
+
if (format === undefined) {
|
|
39
|
+
throw new Error('invariant requires an error message argument');
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
38
43
|
|
|
39
|
-
|
|
44
|
+
function invariant(condition, format, a, b, c, d, e, f) {
|
|
45
|
+
validateFormat(format);
|
|
40
46
|
|
|
41
|
-
|
|
47
|
+
if (!condition) {
|
|
48
|
+
var error = void 0;
|
|
49
|
+
if (format === undefined) {
|
|
50
|
+
error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
|
|
51
|
+
} else {
|
|
52
|
+
var args = [a, b, c, d, e, f];
|
|
53
|
+
var argIndex = 0;
|
|
54
|
+
error = new Error(format.replace(/%s/g, function () {
|
|
55
|
+
return args[argIndex++];
|
|
56
|
+
}));
|
|
57
|
+
error.name = 'Invariant Violation';
|
|
58
|
+
}
|
|
42
59
|
|
|
43
|
-
|
|
44
|
-
|
|
60
|
+
error.framesToPop = 1; // we don't care about invariant's own frame
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
45
64
|
|
|
46
|
-
//
|
|
65
|
+
// Relying on the `invariant()` implementation lets us
|
|
66
|
+
// preserve the format and params in the www builds.
|
|
47
67
|
|
|
68
|
+
var BEFORE_SLASH_RE = /^(.*)[\\\/]/;
|
|
48
69
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
70
|
+
var describeComponentFrame = function (name, source, ownerName) {
|
|
71
|
+
var sourceInfo = '';
|
|
72
|
+
if (source) {
|
|
73
|
+
var path = source.fileName;
|
|
74
|
+
var fileName = path.replace(BEFORE_SLASH_RE, '');
|
|
75
|
+
{
|
|
76
|
+
// In DEV, include code for a common special case:
|
|
77
|
+
// prefer "folder/index.js" instead of just "index.js".
|
|
78
|
+
if (/^index\./.test(fileName)) {
|
|
79
|
+
var match = path.match(BEFORE_SLASH_RE);
|
|
80
|
+
if (match) {
|
|
81
|
+
var pathBeforeSlash = match[1];
|
|
82
|
+
if (pathBeforeSlash) {
|
|
83
|
+
var folderName = pathBeforeSlash.replace(BEFORE_SLASH_RE, '');
|
|
84
|
+
fileName = folderName + '/' + fileName;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
sourceInfo = ' (at ' + fileName + ':' + source.lineNumber + ')';
|
|
90
|
+
} else if (ownerName) {
|
|
91
|
+
sourceInfo = ' (created by ' + ownerName + ')';
|
|
92
|
+
}
|
|
93
|
+
return '\n in ' + (name || 'Unknown') + sourceInfo;
|
|
94
|
+
};
|
|
53
95
|
|
|
96
|
+
/**
|
|
97
|
+
* Similar to invariant but only logs a warning if the condition is not met.
|
|
98
|
+
* This can be used to log issues in development environments in critical
|
|
99
|
+
* paths. Removing the logging code for production environments will keep the
|
|
100
|
+
* same logic and follow the same code paths.
|
|
101
|
+
*/
|
|
54
102
|
|
|
55
|
-
|
|
56
|
-
// replay the begin phase of a failed component inside invokeGuardedCallback.
|
|
103
|
+
var warningWithoutStack = function () {};
|
|
57
104
|
|
|
105
|
+
{
|
|
106
|
+
warningWithoutStack = function (condition, format) {
|
|
107
|
+
for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
108
|
+
args[_key - 2] = arguments[_key];
|
|
109
|
+
}
|
|
58
110
|
|
|
59
|
-
|
|
60
|
-
|
|
111
|
+
if (format === undefined) {
|
|
112
|
+
throw new Error('`warningWithoutStack(condition, format, ...args)` requires a warning ' + 'message argument');
|
|
113
|
+
}
|
|
114
|
+
if (condition) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (typeof console !== 'undefined') {
|
|
118
|
+
var _console;
|
|
61
119
|
|
|
62
|
-
|
|
120
|
+
var stringArgs = args.map(function (item) {
|
|
121
|
+
return '' + item;
|
|
122
|
+
});
|
|
123
|
+
(_console = console).error.apply(_console, ['Warning: ' + format].concat(stringArgs));
|
|
124
|
+
}
|
|
125
|
+
try {
|
|
126
|
+
// --- Welcome to debugging React ---
|
|
127
|
+
// This error was thrown as a convenience so that you can use this stack
|
|
128
|
+
// to find the callsite that caused this warning to fire.
|
|
129
|
+
var argIndex = 0;
|
|
130
|
+
var message = 'Warning: ' + format.replace(/%s/g, function () {
|
|
131
|
+
return args[argIndex++];
|
|
132
|
+
});
|
|
133
|
+
throw new Error(message);
|
|
134
|
+
} catch (x) {}
|
|
135
|
+
};
|
|
136
|
+
}
|
|
63
137
|
|
|
64
|
-
var
|
|
65
|
-
return '\n in ' + (name || 'Unknown') + (source ? ' (at ' + source.fileName.replace(/^.*[\\\/]/, '') + ':' + source.lineNumber + ')' : ownerName ? ' (created by ' + ownerName + ')' : '');
|
|
66
|
-
};
|
|
138
|
+
var warningWithoutStack$1 = warningWithoutStack;
|
|
67
139
|
|
|
68
140
|
// The Symbol used to tag the ReactElement-like types. If there is no native Symbol
|
|
69
141
|
// nor polyfill, then a plain number is used for performance.
|
|
70
|
-
var hasSymbol = typeof Symbol === 'function' && Symbol
|
|
142
|
+
var hasSymbol = typeof Symbol === 'function' && Symbol.for;
|
|
71
143
|
|
|
72
144
|
|
|
73
|
-
var
|
|
74
|
-
var
|
|
75
|
-
var
|
|
76
|
-
var
|
|
145
|
+
var REACT_PORTAL_TYPE = hasSymbol ? Symbol.for('react.portal') : 0xeaca;
|
|
146
|
+
var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for('react.fragment') : 0xeacb;
|
|
147
|
+
var REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol.for('react.strict_mode') : 0xeacc;
|
|
148
|
+
var REACT_PROFILER_TYPE = hasSymbol ? Symbol.for('react.profiler') : 0xead2;
|
|
149
|
+
var REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for('react.provider') : 0xeacd;
|
|
150
|
+
var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace;
|
|
151
|
+
var REACT_ASYNC_MODE_TYPE = hasSymbol ? Symbol.for('react.async_mode') : 0xeacf;
|
|
152
|
+
var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0;
|
|
153
|
+
var REACT_PLACEHOLDER_TYPE = hasSymbol ? Symbol.for('react.placeholder') : 0xead1;
|
|
77
154
|
|
|
78
|
-
|
|
79
|
-
var type = fiber.type;
|
|
155
|
+
var Resolved = 1;
|
|
80
156
|
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
function refineResolvedThenable(thenable) {
|
|
161
|
+
return thenable._reactStatus === Resolved ? thenable._reactResult : null;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function getComponentName(type) {
|
|
165
|
+
if (type == null) {
|
|
166
|
+
// Host root, text node or just invalid type.
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
{
|
|
170
|
+
if (typeof type.tag === 'number') {
|
|
171
|
+
warningWithoutStack$1(false, 'Received an unexpected object in getComponentName(). ' + 'This is likely a bug in React. Please file an issue.');
|
|
172
|
+
}
|
|
173
|
+
}
|
|
81
174
|
if (typeof type === 'function') {
|
|
82
|
-
return type.displayName || type.name;
|
|
175
|
+
return type.displayName || type.name || null;
|
|
83
176
|
}
|
|
84
177
|
if (typeof type === 'string') {
|
|
85
178
|
return type;
|
|
86
179
|
}
|
|
87
180
|
switch (type) {
|
|
181
|
+
case REACT_ASYNC_MODE_TYPE:
|
|
182
|
+
return 'AsyncMode';
|
|
88
183
|
case REACT_FRAGMENT_TYPE:
|
|
89
|
-
return '
|
|
184
|
+
return 'Fragment';
|
|
90
185
|
case REACT_PORTAL_TYPE:
|
|
91
|
-
return '
|
|
92
|
-
case
|
|
93
|
-
return '
|
|
94
|
-
case
|
|
95
|
-
return '
|
|
186
|
+
return 'Portal';
|
|
187
|
+
case REACT_PROFILER_TYPE:
|
|
188
|
+
return 'Profiler';
|
|
189
|
+
case REACT_STRICT_MODE_TYPE:
|
|
190
|
+
return 'StrictMode';
|
|
191
|
+
case REACT_PLACEHOLDER_TYPE:
|
|
192
|
+
return 'Placeholder';
|
|
193
|
+
}
|
|
194
|
+
if (typeof type === 'object') {
|
|
195
|
+
switch (type.$$typeof) {
|
|
196
|
+
case REACT_CONTEXT_TYPE:
|
|
197
|
+
return 'Context.Consumer';
|
|
198
|
+
case REACT_PROVIDER_TYPE:
|
|
199
|
+
return 'Context.Provider';
|
|
200
|
+
case REACT_FORWARD_REF_TYPE:
|
|
201
|
+
var renderFn = type.render;
|
|
202
|
+
var functionName = renderFn.displayName || renderFn.name || '';
|
|
203
|
+
return functionName !== '' ? 'ForwardRef(' + functionName + ')' : 'ForwardRef';
|
|
204
|
+
}
|
|
205
|
+
if (typeof type.then === 'function') {
|
|
206
|
+
var thenable = type;
|
|
207
|
+
var resolvedThenable = refineResolvedThenable(thenable);
|
|
208
|
+
if (resolvedThenable) {
|
|
209
|
+
return getComponentName(resolvedThenable);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
96
212
|
}
|
|
97
213
|
return null;
|
|
98
214
|
}
|
|
99
215
|
|
|
216
|
+
/*eslint-disable no-self-compare */
|
|
217
|
+
|
|
218
|
+
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
219
|
+
|
|
100
220
|
/**
|
|
101
|
-
*
|
|
102
|
-
* https://
|
|
103
|
-
*
|
|
104
|
-
* Only change is we use console.warn instead of console.error,
|
|
105
|
-
* and do nothing when 'console' is not supported.
|
|
106
|
-
* This really simplifies the code.
|
|
107
|
-
* ---
|
|
108
|
-
* Similar to invariant but only logs a warning if the condition is not met.
|
|
109
|
-
* This can be used to log issues in development environments in critical
|
|
110
|
-
* paths. Removing the logging code for production environments will keep the
|
|
111
|
-
* same logic and follow the same code paths.
|
|
221
|
+
* inlined Object.is polyfill to avoid requiring consumers ship their own
|
|
222
|
+
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
|
|
112
223
|
*/
|
|
224
|
+
function is(x, y) {
|
|
225
|
+
// SameValue algorithm
|
|
226
|
+
if (x === y) {
|
|
227
|
+
// Steps 1-5, 7-10
|
|
228
|
+
// Steps 6.b-6.e: +0 != -0
|
|
229
|
+
// Added the nonzero y check to make Flow happy, but it is redundant
|
|
230
|
+
return x !== 0 || y !== 0 || 1 / x === 1 / y;
|
|
231
|
+
} else {
|
|
232
|
+
// Step 6.a: NaN == NaN
|
|
233
|
+
return x !== x && y !== y;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
113
236
|
|
|
114
|
-
|
|
237
|
+
/**
|
|
238
|
+
* Performs equality by iterating through keys on an object and returning false
|
|
239
|
+
* when any key has values which are not strictly equal between the arguments.
|
|
240
|
+
* Returns true when the values of all keys are strictly equal.
|
|
241
|
+
*/
|
|
242
|
+
function shallowEqual(objA, objB) {
|
|
243
|
+
if (is(objA, objB)) {
|
|
244
|
+
return true;
|
|
245
|
+
}
|
|
115
246
|
|
|
116
|
-
{
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
args[_key - 1] = arguments[_key];
|
|
120
|
-
}
|
|
247
|
+
if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
|
|
248
|
+
return false;
|
|
249
|
+
}
|
|
121
250
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
return args[argIndex++];
|
|
125
|
-
});
|
|
126
|
-
if (typeof console !== 'undefined') {
|
|
127
|
-
console.warn(message);
|
|
128
|
-
}
|
|
129
|
-
try {
|
|
130
|
-
// --- Welcome to debugging React ---
|
|
131
|
-
// This error was thrown as a convenience so that you can use this stack
|
|
132
|
-
// to find the callsite that caused this warning to fire.
|
|
133
|
-
throw new Error(message);
|
|
134
|
-
} catch (x) {}
|
|
135
|
-
};
|
|
251
|
+
var keysA = Object.keys(objA);
|
|
252
|
+
var keysB = Object.keys(objB);
|
|
136
253
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
if (!condition) {
|
|
142
|
-
for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
|
|
143
|
-
args[_key2 - 2] = arguments[_key2];
|
|
144
|
-
}
|
|
254
|
+
if (keysA.length !== keysB.length) {
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
145
257
|
|
|
146
|
-
|
|
258
|
+
// Test for A's keys different from B.
|
|
259
|
+
for (var i = 0; i < keysA.length; i++) {
|
|
260
|
+
if (!hasOwnProperty.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) {
|
|
261
|
+
return false;
|
|
147
262
|
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
263
|
+
}
|
|
150
264
|
|
|
151
|
-
|
|
265
|
+
return true;
|
|
266
|
+
}
|
|
152
267
|
|
|
153
268
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
154
269
|
|
|
155
|
-
var
|
|
156
|
-
var didWarnAboutLegacyWillReceiveProps = void 0;
|
|
157
|
-
var didWarnAboutLegacyWillUpdate = void 0;
|
|
158
|
-
var didWarnAboutUndefinedDerivedState = void 0;
|
|
159
|
-
var didWarnAboutUninitializedState = void 0;
|
|
160
|
-
var didWarnAboutWillReceivePropsAndDerivedState = void 0;
|
|
161
|
-
|
|
270
|
+
var emptyObject = {};
|
|
162
271
|
{
|
|
163
|
-
|
|
164
|
-
didWarnAboutLegacyWillMount = {};
|
|
165
|
-
didWarnAboutLegacyWillReceiveProps = {};
|
|
166
|
-
didWarnAboutLegacyWillUpdate = {};
|
|
167
|
-
}
|
|
168
|
-
didWarnAboutUndefinedDerivedState = {};
|
|
169
|
-
didWarnAboutUninitializedState = {};
|
|
170
|
-
didWarnAboutWillReceivePropsAndDerivedState = {};
|
|
272
|
+
Object.freeze(emptyObject);
|
|
171
273
|
}
|
|
172
274
|
|
|
173
275
|
var ReactShallowRenderer = function () {
|
|
@@ -198,7 +300,7 @@ var ReactShallowRenderer = function () {
|
|
|
198
300
|
!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;
|
|
199
301
|
// Show a special message for host elements since it's a common case.
|
|
200
302
|
!(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;
|
|
201
|
-
!(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;
|
|
303
|
+
!(reactIs.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;
|
|
202
304
|
|
|
203
305
|
if (this._rendering) {
|
|
204
306
|
return;
|
|
@@ -211,21 +313,11 @@ var ReactShallowRenderer = function () {
|
|
|
211
313
|
if (this._instance) {
|
|
212
314
|
this._updateClassComponent(element, this._context);
|
|
213
315
|
} else {
|
|
214
|
-
if (
|
|
316
|
+
if (reactIs.isForwardRef(element)) {
|
|
317
|
+
this._rendered = element.type.render(element.props, element.ref);
|
|
318
|
+
} else if (shouldConstruct(element.type)) {
|
|
215
319
|
this._instance = new element.type(element.props, this._context, this._updater);
|
|
216
320
|
|
|
217
|
-
{
|
|
218
|
-
if (typeof element.type.getDerivedStateFromProps === 'function') {
|
|
219
|
-
if (this._instance.state === null || this._instance.state === undefined) {
|
|
220
|
-
var componentName = getName(element.type, this._instance) || 'Unknown';
|
|
221
|
-
if (!didWarnAboutUninitializedState[componentName]) {
|
|
222
|
-
warning(false, '%s: Did not properly initialize state during construction. ' + 'Expected state to be an object, but it was %s.', componentName, this._instance.state === null ? 'null' : 'undefined');
|
|
223
|
-
didWarnAboutUninitializedState[componentName] = true;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
321
|
this._updateStateFromStaticLifecycle(element.props);
|
|
230
322
|
|
|
231
323
|
if (element.type.hasOwnProperty('contextTypes')) {
|
|
@@ -238,7 +330,7 @@ var ReactShallowRenderer = function () {
|
|
|
238
330
|
|
|
239
331
|
this._mountClassComponent(element, this._context);
|
|
240
332
|
} else {
|
|
241
|
-
this._rendered = element.type(element.props, this._context);
|
|
333
|
+
this._rendered = element.type.call(undefined, element.props, this._context);
|
|
242
334
|
}
|
|
243
335
|
}
|
|
244
336
|
|
|
@@ -271,28 +363,15 @@ var ReactShallowRenderer = function () {
|
|
|
271
363
|
if (typeof this._instance.UNSAFE_componentWillMount === 'function' || typeof this._instance.componentWillMount === 'function') {
|
|
272
364
|
var beforeState = this._newState;
|
|
273
365
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
var componentName = getName(element.type, this._instance);
|
|
279
|
-
if (!didWarnAboutLegacyWillMount[componentName]) {
|
|
280
|
-
lowPriorityWarning$1(false, '%s: componentWillMount() is deprecated and will be ' + 'removed in the next major version. Read about the motivations ' + 'behind this change: ' + 'https://fb.me/react-async-component-lifecycle-hooks' + '\n\n' + 'As a temporary workaround, you can rename to ' + 'UNSAFE_componentWillMount instead.', componentName);
|
|
281
|
-
didWarnAboutLegacyWillMount[componentName] = true;
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
// In order to support react-lifecycles-compat polyfilled components,
|
|
287
|
-
// Unsafe lifecycles should not be invoked for any component with the new gDSFP.
|
|
288
|
-
if (typeof element.type.getDerivedStateFromProps !== 'function') {
|
|
366
|
+
// In order to support react-lifecycles-compat polyfilled components,
|
|
367
|
+
// Unsafe lifecycles should not be invoked for components using the new APIs.
|
|
368
|
+
if (typeof element.type.getDerivedStateFromProps !== 'function' && typeof this._instance.getSnapshotBeforeUpdate !== 'function') {
|
|
369
|
+
if (typeof this._instance.componentWillMount === 'function') {
|
|
289
370
|
this._instance.componentWillMount();
|
|
290
371
|
}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
// Unsafe lifecycles should not be invoked for any component with the new gDSFP.
|
|
295
|
-
this._instance.UNSAFE_componentWillMount();
|
|
372
|
+
if (typeof this._instance.UNSAFE_componentWillMount === 'function') {
|
|
373
|
+
this._instance.UNSAFE_componentWillMount();
|
|
374
|
+
}
|
|
296
375
|
}
|
|
297
376
|
|
|
298
377
|
// setState may have been called during cWM
|
|
@@ -315,30 +394,18 @@ var ReactShallowRenderer = function () {
|
|
|
315
394
|
var oldProps = this._instance.props;
|
|
316
395
|
|
|
317
396
|
if (oldProps !== props) {
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
if (!didWarnAboutLegacyWillReceiveProps[componentName]) {
|
|
323
|
-
lowPriorityWarning$1(false, '%s: componentWillReceiveProps() is deprecated and ' + 'will be removed in the next major version. Use ' + 'static getDerivedStateFromProps() instead. Read about the ' + 'motivations behind this change: ' + 'https://fb.me/react-async-component-lifecycle-hooks' + '\n\n' + 'As a temporary workaround, you can rename to ' + 'UNSAFE_componentWillReceiveProps instead.', componentName);
|
|
324
|
-
didWarnAboutLegacyWillReceiveProps[componentName] = true;
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
// In order to support react-lifecycles-compat polyfilled components,
|
|
329
|
-
// Unsafe lifecycles should not be invoked for any component with the new gDSFP.
|
|
330
|
-
if (typeof element.type.getDerivedStateFromProps !== 'function') {
|
|
397
|
+
// In order to support react-lifecycles-compat polyfilled components,
|
|
398
|
+
// Unsafe lifecycles should not be invoked for components using the new APIs.
|
|
399
|
+
if (typeof element.type.getDerivedStateFromProps !== 'function' && typeof this._instance.getSnapshotBeforeUpdate !== 'function') {
|
|
400
|
+
if (typeof this._instance.componentWillReceiveProps === 'function') {
|
|
331
401
|
this._instance.componentWillReceiveProps(props, context);
|
|
332
402
|
}
|
|
403
|
+
if (typeof this._instance.UNSAFE_componentWillReceiveProps === 'function') {
|
|
404
|
+
this._instance.UNSAFE_componentWillReceiveProps(props, context);
|
|
405
|
+
}
|
|
333
406
|
}
|
|
334
|
-
if (typeof this._instance.UNSAFE_componentWillReceiveProps === 'function' && typeof element.type.getDerivedStateFromProps !== 'function') {
|
|
335
|
-
// In order to support react-lifecycles-compat polyfilled components,
|
|
336
|
-
// Unsafe lifecycles should not be invoked for any component with the new gDSFP.
|
|
337
|
-
this._instance.UNSAFE_componentWillReceiveProps(props, context);
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
this._updateStateFromStaticLifecycle(props);
|
|
341
407
|
}
|
|
408
|
+
this._updateStateFromStaticLifecycle(props);
|
|
342
409
|
|
|
343
410
|
// Read state after cWRP in case it calls setState
|
|
344
411
|
var state = this._newState || oldState;
|
|
@@ -354,27 +421,15 @@ var ReactShallowRenderer = function () {
|
|
|
354
421
|
}
|
|
355
422
|
|
|
356
423
|
if (shouldUpdate) {
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
if (!didWarnAboutLegacyWillUpdate[_componentName]) {
|
|
362
|
-
lowPriorityWarning$1(false, '%s: componentWillUpdate() is deprecated and will be ' + 'removed in the next major version. Read about the motivations ' + 'behind this change: ' + 'https://fb.me/react-async-component-lifecycle-hooks' + '\n\n' + 'As a temporary workaround, you can rename to ' + 'UNSAFE_componentWillUpdate instead.', _componentName);
|
|
363
|
-
didWarnAboutLegacyWillUpdate[_componentName] = true;
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
// In order to support react-lifecycles-compat polyfilled components,
|
|
369
|
-
// Unsafe lifecycles should not be invoked for any component with the new gDSFP.
|
|
370
|
-
if (typeof type.getDerivedStateFromProps !== 'function') {
|
|
424
|
+
// In order to support react-lifecycles-compat polyfilled components,
|
|
425
|
+
// Unsafe lifecycles should not be invoked for components using the new APIs.
|
|
426
|
+
if (typeof element.type.getDerivedStateFromProps !== 'function' && typeof this._instance.getSnapshotBeforeUpdate !== 'function') {
|
|
427
|
+
if (typeof this._instance.componentWillUpdate === 'function') {
|
|
371
428
|
this._instance.componentWillUpdate(props, state, context);
|
|
372
429
|
}
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
// Unsafe lifecycles should not be invoked for any component with the new gDSFP.
|
|
377
|
-
this._instance.UNSAFE_componentWillUpdate(props, state, context);
|
|
430
|
+
if (typeof this._instance.UNSAFE_componentWillUpdate === 'function') {
|
|
431
|
+
this._instance.UNSAFE_componentWillUpdate(props, state, context);
|
|
432
|
+
}
|
|
378
433
|
}
|
|
379
434
|
}
|
|
380
435
|
|
|
@@ -394,31 +449,10 @@ var ReactShallowRenderer = function () {
|
|
|
394
449
|
|
|
395
450
|
|
|
396
451
|
if (typeof type.getDerivedStateFromProps === 'function') {
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
if (typeof this._instance.componentWillReceiveProps === 'function' && this._instance.componentWillReceiveProps.__suppressDeprecationWarning !== true || typeof this._instance.UNSAFE_componentWillReceiveProps === 'function') {
|
|
400
|
-
var componentName = getName(type, this._instance);
|
|
401
|
-
if (!didWarnAboutWillReceivePropsAndDerivedState[componentName]) {
|
|
402
|
-
warning(false, '%s: Defines both componentWillReceiveProps() and static ' + 'getDerivedStateFromProps() methods. We recommend using ' + 'only getDerivedStateFromProps().', componentName);
|
|
403
|
-
didWarnAboutWillReceivePropsAndDerivedState[componentName] = true;
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
var partialState = type.getDerivedStateFromProps.call(null, props, this._instance.state);
|
|
409
|
-
|
|
410
|
-
{
|
|
411
|
-
if (partialState === undefined) {
|
|
412
|
-
var _componentName2 = getName(type, this._instance);
|
|
413
|
-
if (!didWarnAboutUndefinedDerivedState[_componentName2]) {
|
|
414
|
-
warning(false, '%s.getDerivedStateFromProps(): A valid state object (or null) must be returned. ' + 'You have returned undefined.', _componentName2);
|
|
415
|
-
didWarnAboutUndefinedDerivedState[_componentName2] = _componentName2;
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
}
|
|
452
|
+
var oldState = this._newState || this._instance.state;
|
|
453
|
+
var partialState = type.getDerivedStateFromProps.call(null, props, oldState);
|
|
419
454
|
|
|
420
455
|
if (partialState != null) {
|
|
421
|
-
var oldState = this._newState || this._instance.state;
|
|
422
456
|
var newState = _assign({}, oldState, partialState);
|
|
423
457
|
this._instance.state = this._newState = newState;
|
|
424
458
|
}
|
|
@@ -482,7 +516,12 @@ var Updater = function () {
|
|
|
482
516
|
var currentState = this._renderer._newState || publicInstance.state;
|
|
483
517
|
|
|
484
518
|
if (typeof partialState === 'function') {
|
|
485
|
-
partialState = partialState(currentState, publicInstance.props);
|
|
519
|
+
partialState = partialState.call(publicInstance, currentState, publicInstance.props);
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
// Null and undefined are treated as no-ops.
|
|
523
|
+
if (partialState === null || partialState === undefined) {
|
|
524
|
+
return;
|
|
486
525
|
}
|
|
487
526
|
|
|
488
527
|
this._renderer._newState = _assign({}, currentState, partialState);
|
|
@@ -512,7 +551,7 @@ function getStackAddendum() {
|
|
|
512
551
|
if (currentlyValidatingElement) {
|
|
513
552
|
var name = getDisplayName(currentlyValidatingElement);
|
|
514
553
|
var owner = currentlyValidatingElement._owner;
|
|
515
|
-
stack += describeComponentFrame(name, currentlyValidatingElement._source, owner && getComponentName(owner));
|
|
554
|
+
stack += describeComponentFrame(name, currentlyValidatingElement._source, owner && getComponentName(owner.type));
|
|
516
555
|
}
|
|
517
556
|
return stack;
|
|
518
557
|
}
|
|
@@ -547,7 +586,7 @@ var ReactShallowRenderer$3 = ( ReactShallowRenderer$2 && ReactShallowRenderer )
|
|
|
547
586
|
|
|
548
587
|
// TODO: decide on the top-level export form.
|
|
549
588
|
// This is hacky but makes it work with both Rollup and Jest.
|
|
550
|
-
var shallow = ReactShallowRenderer$3
|
|
589
|
+
var shallow = ReactShallowRenderer$3.default || ReactShallowRenderer$3;
|
|
551
590
|
|
|
552
591
|
module.exports = shallow;
|
|
553
592
|
})();
|