react-test-renderer 16.9.0-rc.0 → 16.10.2

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.
@@ -1,4 +1,4 @@
1
- /** @license React v16.9.0-rc.0
1
+ /** @license React v16.10.2
2
2
  * react-test-renderer-shallow.development.js
3
3
  *
4
4
  * Copyright (c) Facebook, Inc. and its affiliates.
@@ -27,26 +27,28 @@ var checkPropTypes = require('prop-types/checkPropTypes');
27
27
  // Do not require this module directly! Use normal `invariant` calls with
28
28
  // template literal strings. The messages will be converted to ReactError during
29
29
  // build, and in production they will be minified.
30
-
31
30
  function ReactError(error) {
32
31
  error.name = 'Invariant Violation';
33
32
  return error;
34
33
  }
35
34
 
36
35
  var BEFORE_SLASH_RE = /^(.*)[\\\/]/;
37
-
38
36
  var describeComponentFrame = function (name, source, ownerName) {
39
37
  var sourceInfo = '';
38
+
40
39
  if (source) {
41
40
  var path = source.fileName;
42
41
  var fileName = path.replace(BEFORE_SLASH_RE, '');
42
+
43
43
  {
44
44
  // In DEV, include code for a common special case:
45
45
  // prefer "folder/index.js" instead of just "index.js".
46
46
  if (/^index\./.test(fileName)) {
47
47
  var match = path.match(BEFORE_SLASH_RE);
48
+
48
49
  if (match) {
49
50
  var pathBeforeSlash = match[1];
51
+
50
52
  if (pathBeforeSlash) {
51
53
  var folderName = pathBeforeSlash.replace(BEFORE_SLASH_RE, '');
52
54
  fileName = folderName + '/' + fileName;
@@ -54,10 +56,12 @@ var describeComponentFrame = function (name, source, ownerName) {
54
56
  }
55
57
  }
56
58
  }
59
+
57
60
  sourceInfo = ' (at ' + fileName + ':' + source.lineNumber + ')';
58
61
  } else if (ownerName) {
59
62
  sourceInfo = ' (created by ' + ownerName + ')';
60
63
  }
64
+
61
65
  return '\n in ' + (name || 'Unknown') + sourceInfo;
62
66
  };
63
67
 
@@ -67,35 +71,37 @@ var describeComponentFrame = function (name, source, ownerName) {
67
71
  * paths. Removing the logging code for production environments will keep the
68
72
  * same logic and follow the same code paths.
69
73
  */
70
-
71
74
  var warningWithoutStack = function () {};
72
75
 
73
76
  {
74
77
  warningWithoutStack = function (condition, format) {
75
- for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
78
+ for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
76
79
  args[_key - 2] = arguments[_key];
77
80
  }
78
81
 
79
82
  if (format === undefined) {
80
83
  throw new Error('`warningWithoutStack(condition, format, ...args)` requires a warning ' + 'message argument');
81
84
  }
85
+
82
86
  if (args.length > 8) {
83
87
  // Check before the condition to catch violations early.
84
88
  throw new Error('warningWithoutStack() currently supports at most 8 arguments.');
85
89
  }
90
+
86
91
  if (condition) {
87
92
  return;
88
93
  }
94
+
89
95
  if (typeof console !== 'undefined') {
90
96
  var argsWithFormat = args.map(function (item) {
91
97
  return '' + item;
92
98
  });
93
- argsWithFormat.unshift('Warning: ' + format);
94
-
95
- // We intentionally don't use spread (or .apply) directly because it
99
+ argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
96
100
  // breaks IE9: https://github.com/facebook/react/issues/13610
101
+
97
102
  Function.prototype.apply.call(console.error, console, argsWithFormat);
98
103
  }
104
+
99
105
  try {
100
106
  // --- Welcome to debugging React ---
101
107
  // This error was thrown as a convenience so that you can use this stack
@@ -115,25 +121,67 @@ var warningWithoutStack$1 = warningWithoutStack;
115
121
  // nor polyfill, then a plain number is used for performance.
116
122
  var hasSymbol = typeof Symbol === 'function' && Symbol.for;
117
123
 
118
-
119
124
  var REACT_PORTAL_TYPE = hasSymbol ? Symbol.for('react.portal') : 0xeaca;
120
125
  var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for('react.fragment') : 0xeacb;
121
126
  var REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol.for('react.strict_mode') : 0xeacc;
122
127
  var REACT_PROFILER_TYPE = hasSymbol ? Symbol.for('react.profiler') : 0xead2;
123
128
  var REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for('react.provider') : 0xeacd;
124
- var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace;
125
- // TODO: We don't use AsyncMode or ConcurrentMode anymore. They were temporary
129
+ var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace; // TODO: We don't use AsyncMode or ConcurrentMode anymore. They were temporary
126
130
  // (unstable) APIs that have been removed. Can we remove the symbols?
127
131
 
128
132
 
133
+
129
134
  var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0;
130
135
  var REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for('react.suspense') : 0xead1;
131
136
  var REACT_SUSPENSE_LIST_TYPE = hasSymbol ? Symbol.for('react.suspense_list') : 0xead8;
132
137
  var REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3;
133
138
  var REACT_LAZY_TYPE = hasSymbol ? Symbol.for('react.lazy') : 0xead4;
134
139
 
135
- var Resolved = 1;
140
+ 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.
141
+ // Current owner and dispatcher used to share the same ref,
142
+ // but PR #14548 split them out to better support the react-debug-tools package.
136
143
 
144
+ if (!ReactSharedInternals.hasOwnProperty('ReactCurrentDispatcher')) {
145
+ ReactSharedInternals.ReactCurrentDispatcher = {
146
+ current: null
147
+ };
148
+ }
149
+
150
+ if (!ReactSharedInternals.hasOwnProperty('ReactCurrentBatchConfig')) {
151
+ ReactSharedInternals.ReactCurrentBatchConfig = {
152
+ suspense: null
153
+ };
154
+ }
155
+
156
+ /**
157
+ * Similar to invariant but only logs a warning if the condition is not met.
158
+ * This can be used to log issues in development environments in critical
159
+ * paths. Removing the logging code for production environments will keep the
160
+ * same logic and follow the same code paths.
161
+ */
162
+
163
+ var warning = warningWithoutStack$1;
164
+
165
+ {
166
+ warning = function (condition, format) {
167
+ if (condition) {
168
+ return;
169
+ }
170
+
171
+ var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
172
+ var stack = ReactDebugCurrentFrame.getStackAddendum(); // eslint-disable-next-line react-internal/warning-and-invariant-args
173
+
174
+ for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
175
+ args[_key - 2] = arguments[_key];
176
+ }
177
+
178
+ warningWithoutStack$1.apply(void 0, [false, format + '%s'].concat(args, [stack]));
179
+ };
180
+ }
181
+
182
+ var warning$1 = warning;
183
+
184
+ var Resolved = 1;
137
185
 
138
186
  function refineResolvedLazyComponent(lazyComponent) {
139
187
  return lazyComponent._status === Resolved ? lazyComponent._result : null;
@@ -141,7 +189,7 @@ function refineResolvedLazyComponent(lazyComponent) {
141
189
 
142
190
  function getWrappedName(outerType, innerType, wrapperName) {
143
191
  var functionName = innerType.displayName || innerType.name || '';
144
- return outerType.displayName || (functionName !== '' ? wrapperName + '(' + functionName + ')' : wrapperName);
192
+ return outerType.displayName || (functionName !== '' ? wrapperName + "(" + functionName + ")" : wrapperName);
145
193
  }
146
194
 
147
195
  function getComponentName(type) {
@@ -149,52 +197,69 @@ function getComponentName(type) {
149
197
  // Host root, text node or just invalid type.
150
198
  return null;
151
199
  }
200
+
152
201
  {
153
202
  if (typeof type.tag === 'number') {
154
203
  warningWithoutStack$1(false, 'Received an unexpected object in getComponentName(). ' + 'This is likely a bug in React. Please file an issue.');
155
204
  }
156
205
  }
206
+
157
207
  if (typeof type === 'function') {
158
208
  return type.displayName || type.name || null;
159
209
  }
210
+
160
211
  if (typeof type === 'string') {
161
212
  return type;
162
213
  }
214
+
163
215
  switch (type) {
164
216
  case REACT_FRAGMENT_TYPE:
165
217
  return 'Fragment';
218
+
166
219
  case REACT_PORTAL_TYPE:
167
220
  return 'Portal';
221
+
168
222
  case REACT_PROFILER_TYPE:
169
- return 'Profiler';
223
+ return "Profiler";
224
+
170
225
  case REACT_STRICT_MODE_TYPE:
171
226
  return 'StrictMode';
227
+
172
228
  case REACT_SUSPENSE_TYPE:
173
229
  return 'Suspense';
230
+
174
231
  case REACT_SUSPENSE_LIST_TYPE:
175
232
  return 'SuspenseList';
176
233
  }
234
+
177
235
  if (typeof type === 'object') {
178
236
  switch (type.$$typeof) {
179
237
  case REACT_CONTEXT_TYPE:
180
238
  return 'Context.Consumer';
239
+
181
240
  case REACT_PROVIDER_TYPE:
182
241
  return 'Context.Provider';
242
+
183
243
  case REACT_FORWARD_REF_TYPE:
184
244
  return getWrappedName(type, type.render, 'ForwardRef');
245
+
185
246
  case REACT_MEMO_TYPE:
186
247
  return getComponentName(type.type);
248
+
187
249
  case REACT_LAZY_TYPE:
188
250
  {
189
251
  var thenable = type;
190
252
  var resolvedThenable = refineResolvedLazyComponent(thenable);
253
+
191
254
  if (resolvedThenable) {
192
255
  return getComponentName(resolvedThenable);
193
256
  }
257
+
194
258
  break;
195
259
  }
196
260
  }
197
261
  }
262
+
198
263
  return null;
199
264
  }
200
265
 
@@ -207,15 +272,17 @@ function is(x, y) {
207
272
  ;
208
273
  }
209
274
 
210
- var hasOwnProperty = Object.prototype.hasOwnProperty;
275
+ var is$1 = typeof Object.is === 'function' ? Object.is : is;
211
276
 
277
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
212
278
  /**
213
279
  * Performs equality by iterating through keys on an object and returning false
214
280
  * when any key has values which are not strictly equal between the arguments.
215
281
  * Returns true when the values of all keys are strictly equal.
216
282
  */
283
+
217
284
  function shallowEqual(objA, objB) {
218
- if (is(objA, objB)) {
285
+ if (is$1(objA, objB)) {
219
286
  return true;
220
287
  }
221
288
 
@@ -228,11 +295,11 @@ function shallowEqual(objA, objB) {
228
295
 
229
296
  if (keysA.length !== keysB.length) {
230
297
  return false;
231
- }
298
+ } // Test for A's keys different from B.
299
+
232
300
 
233
- // Test for A's keys different from B.
234
301
  for (var i = 0; i < keysA.length; i++) {
235
- if (!hasOwnProperty.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) {
302
+ if (!hasOwnProperty.call(objB, keysA[i]) || !is$1(objA[keysA[i]], objB[keysA[i]])) {
236
303
  return false;
237
304
  }
238
305
  }
@@ -251,94 +318,51 @@ function shallowEqual(objA, objB) {
251
318
  * will remain to ensure logic does not differ in production.
252
319
  */
253
320
 
254
- var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
255
-
256
- // Prevent newer renderers from RTE when used with older react package versions.
257
- // Current owner and dispatcher used to share the same ref,
258
- // but PR #14548 split them out to better support the react-debug-tools package.
259
- if (!ReactSharedInternals.hasOwnProperty('ReactCurrentDispatcher')) {
260
- ReactSharedInternals.ReactCurrentDispatcher = {
261
- current: null
262
- };
263
- }
264
- if (!ReactSharedInternals.hasOwnProperty('ReactCurrentBatchConfig')) {
265
- ReactSharedInternals.ReactCurrentBatchConfig = {
266
- suspense: null
267
- };
268
- }
269
-
270
- /**
271
- * Similar to invariant but only logs a warning if the condition is not met.
272
- * This can be used to log issues in development environments in critical
273
- * paths. Removing the logging code for production environments will keep the
274
- * same logic and follow the same code paths.
275
- */
276
-
277
- var warning = warningWithoutStack$1;
278
-
279
- {
280
- warning = function (condition, format) {
281
- if (condition) {
282
- return;
283
- }
284
- var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
285
- var stack = ReactDebugCurrentFrame.getStackAddendum();
286
- // eslint-disable-next-line react-internal/warning-and-invariant-args
287
-
288
- for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
289
- args[_key - 2] = arguments[_key];
290
- }
291
-
292
- warningWithoutStack$1.apply(undefined, [false, format + '%s'].concat(args, [stack]));
293
- };
294
- }
295
-
296
- var warning$1 = warning;
297
-
298
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
299
-
300
321
  var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
301
-
302
-
303
322
  var RE_RENDER_LIMIT = 25;
304
-
305
323
  var emptyObject = {};
324
+
306
325
  {
307
326
  Object.freeze(emptyObject);
308
- }
327
+ } // In DEV, this is the name of the currently executing primitive hook
328
+
309
329
 
310
- // In DEV, this is the name of the currently executing primitive hook
311
- var currentHookNameInDev = void 0;
330
+ var currentHookNameInDev;
312
331
 
313
332
  function areHookInputsEqual(nextDeps, prevDeps) {
314
333
  if (prevDeps === null) {
315
334
  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);
316
335
  return false;
317
- }
318
-
319
- // Don't bother comparing lengths in prod because these arrays should be
336
+ } // Don't bother comparing lengths in prod because these arrays should be
320
337
  // passed inline.
338
+
339
+
321
340
  if (nextDeps.length !== prevDeps.length) {
322
- 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(', ') + ']');
341
+ 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(', ') + "]");
323
342
  }
343
+
324
344
  for (var i = 0; i < prevDeps.length && i < nextDeps.length; i++) {
325
- if (is(nextDeps[i], prevDeps[i])) {
345
+ if (is$1(nextDeps[i], prevDeps[i])) {
326
346
  continue;
327
347
  }
348
+
328
349
  return false;
329
350
  }
351
+
330
352
  return true;
331
353
  }
332
354
 
333
- var Updater = function () {
355
+ var Updater =
356
+ /*#__PURE__*/
357
+ function () {
334
358
  function Updater(renderer) {
335
- _classCallCheck(this, Updater);
336
-
337
359
  this._renderer = renderer;
338
360
  this._callbacks = [];
339
361
  }
340
362
 
341
- Updater.prototype._enqueueCallback = function _enqueueCallback(callback, publicInstance) {
363
+ var _proto = Updater.prototype;
364
+
365
+ _proto._enqueueCallback = function _enqueueCallback(callback, publicInstance) {
342
366
  if (typeof callback === 'function' && publicInstance) {
343
367
  this._callbacks.push({
344
368
  callback: callback,
@@ -347,48 +371,51 @@ var Updater = function () {
347
371
  }
348
372
  };
349
373
 
350
- Updater.prototype._invokeCallbacks = function _invokeCallbacks() {
374
+ _proto._invokeCallbacks = function _invokeCallbacks() {
351
375
  var callbacks = this._callbacks;
352
376
  this._callbacks = [];
353
-
354
377
  callbacks.forEach(function (_ref) {
355
378
  var callback = _ref.callback,
356
379
  publicInstance = _ref.publicInstance;
357
-
358
380
  callback.call(publicInstance);
359
381
  });
360
382
  };
361
383
 
362
- Updater.prototype.isMounted = function isMounted(publicInstance) {
384
+ _proto.isMounted = function isMounted(publicInstance) {
363
385
  return !!this._renderer._element;
364
386
  };
365
387
 
366
- Updater.prototype.enqueueForceUpdate = function enqueueForceUpdate(publicInstance, callback, callerName) {
388
+ _proto.enqueueForceUpdate = function enqueueForceUpdate(publicInstance, callback, callerName) {
367
389
  this._enqueueCallback(callback, publicInstance);
390
+
368
391
  this._renderer._forcedUpdate = true;
392
+
369
393
  this._renderer.render(this._renderer._element, this._renderer._context);
370
394
  };
371
395
 
372
- Updater.prototype.enqueueReplaceState = function enqueueReplaceState(publicInstance, completeState, callback, callerName) {
396
+ _proto.enqueueReplaceState = function enqueueReplaceState(publicInstance, completeState, callback, callerName) {
373
397
  this._enqueueCallback(callback, publicInstance);
398
+
374
399
  this._renderer._newState = completeState;
400
+
375
401
  this._renderer.render(this._renderer._element, this._renderer._context);
376
402
  };
377
403
 
378
- Updater.prototype.enqueueSetState = function enqueueSetState(publicInstance, partialState, callback, callerName) {
404
+ _proto.enqueueSetState = function enqueueSetState(publicInstance, partialState, callback, callerName) {
379
405
  this._enqueueCallback(callback, publicInstance);
406
+
380
407
  var currentState = this._renderer._newState || publicInstance.state;
381
408
 
382
409
  if (typeof partialState === 'function') {
383
410
  partialState = partialState.call(publicInstance, currentState, publicInstance.props);
384
- }
411
+ } // Null and undefined are treated as no-ops.
412
+
385
413
 
386
- // Null and undefined are treated as no-ops.
387
414
  if (partialState === null || partialState === undefined) {
388
415
  return;
389
416
  }
390
417
 
391
- this._renderer._newState = _assign({}, currentState, partialState);
418
+ this._renderer._newState = _assign({}, currentState, {}, partialState);
392
419
 
393
420
  this._renderer.render(this._renderer._element, this._renderer._context);
394
421
  };
@@ -408,14 +435,16 @@ function basicStateReducer(state, action) {
408
435
  return typeof action === 'function' ? action(state) : action;
409
436
  }
410
437
 
411
- var ReactShallowRenderer = function () {
438
+ var ReactShallowRenderer =
439
+ /*#__PURE__*/
440
+ function () {
412
441
  function ReactShallowRenderer() {
413
- _classCallCheck(this, ReactShallowRenderer);
414
-
415
442
  this._reset();
416
443
  }
417
444
 
418
- ReactShallowRenderer.prototype._reset = function _reset() {
445
+ var _proto2 = ReactShallowRenderer.prototype;
446
+
447
+ _proto2._reset = function _reset() {
419
448
  this._context = null;
420
449
  this._element = null;
421
450
  this._instance = null;
@@ -433,89 +462,106 @@ var ReactShallowRenderer = function () {
433
462
  this._numberOfReRenders = 0;
434
463
  };
435
464
 
436
- ReactShallowRenderer.prototype._validateCurrentlyRenderingComponent = function _validateCurrentlyRenderingComponent() {
465
+ _proto2._validateCurrentlyRenderingComponent = function _validateCurrentlyRenderingComponent() {
437
466
  var _this = this;
438
467
 
439
468
  (function () {
440
469
  if (!(_this._rendering && !_this._instance)) {
441
470
  {
442
- 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.'));
471
+ 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."));
443
472
  }
444
473
  }
445
474
  })();
446
475
  };
447
476
 
448
- ReactShallowRenderer.prototype._createDispatcher = function _createDispatcher() {
477
+ _proto2._createDispatcher = function _createDispatcher() {
449
478
  var _this2 = this;
450
479
 
451
480
  var useReducer = function (reducer, initialArg, init) {
452
481
  _this2._validateCurrentlyRenderingComponent();
482
+
453
483
  _this2._createWorkInProgressHook();
484
+
454
485
  var workInProgressHook = _this2._workInProgressHook;
455
486
 
456
487
  if (_this2._isReRender) {
457
488
  // This is a re-render.
458
- var _queue = workInProgressHook.queue;
459
- var _dispatch = _queue.dispatch;
489
+ var queue = workInProgressHook.queue;
490
+ var dispatch = queue.dispatch;
491
+
460
492
  if (_this2._numberOfReRenders > 0) {
461
493
  // Apply the new render phase updates to the previous current hook.
462
494
  if (_this2._renderPhaseUpdates !== null) {
463
495
  // Render phase updates are stored in a map of queue -> linked list
464
- var firstRenderPhaseUpdate = _this2._renderPhaseUpdates.get(_queue);
496
+ var firstRenderPhaseUpdate = _this2._renderPhaseUpdates.get(queue);
497
+
465
498
  if (firstRenderPhaseUpdate !== undefined) {
466
- _this2._renderPhaseUpdates.delete(_queue);
499
+ _this2._renderPhaseUpdates.delete(queue);
500
+
467
501
  var _newState = workInProgressHook.memoizedState;
468
502
  var _update = firstRenderPhaseUpdate;
503
+
469
504
  do {
470
- var _action = _update.action;
471
- _newState = reducer(_newState, _action);
505
+ var action = _update.action;
506
+ _newState = reducer(_newState, action);
472
507
  _update = _update.next;
473
508
  } while (_update !== null);
509
+
474
510
  workInProgressHook.memoizedState = _newState;
475
- return [_newState, _dispatch];
511
+ return [_newState, dispatch];
476
512
  }
477
513
  }
478
- return [workInProgressHook.memoizedState, _dispatch];
479
- }
480
- // Process updates outside of render
514
+
515
+ return [workInProgressHook.memoizedState, dispatch];
516
+ } // Process updates outside of render
517
+
518
+
481
519
  var newState = workInProgressHook.memoizedState;
482
- var update = _queue.first;
520
+ var update = queue.first;
521
+
483
522
  if (update !== null) {
484
523
  do {
485
- var _action2 = update.action;
486
- newState = reducer(newState, _action2);
524
+ var _action = update.action;
525
+ newState = reducer(newState, _action);
487
526
  update = update.next;
488
527
  } while (update !== null);
489
- _queue.first = null;
528
+
529
+ queue.first = null;
490
530
  workInProgressHook.memoizedState = newState;
491
531
  }
492
- return [newState, _dispatch];
532
+
533
+ return [newState, dispatch];
493
534
  } else {
494
- var initialState = void 0;
535
+ var initialState;
536
+
495
537
  if (reducer === basicStateReducer) {
496
538
  // Special case for `useState`.
497
539
  initialState = typeof initialArg === 'function' ? initialArg() : initialArg;
498
540
  } else {
499
541
  initialState = init !== undefined ? init(initialArg) : initialArg;
500
542
  }
543
+
501
544
  workInProgressHook.memoizedState = initialState;
502
- var _queue2 = workInProgressHook.queue = {
545
+
546
+ var _queue = workInProgressHook.queue = {
503
547
  first: null,
504
548
  dispatch: null
505
549
  };
506
- var _dispatch2 = _queue2.dispatch = _this2._dispatchAction.bind(_this2, _queue2);
507
- return [workInProgressHook.memoizedState, _dispatch2];
550
+
551
+ var _dispatch = _queue.dispatch = _this2._dispatchAction.bind(_this2, _queue);
552
+
553
+ return [workInProgressHook.memoizedState, _dispatch];
508
554
  }
509
555
  };
510
556
 
511
557
  var useState = function (initialState) {
512
- return useReducer(basicStateReducer,
513
- // useReducer has a special case to support lazy useState initializers
558
+ return useReducer(basicStateReducer, // useReducer has a special case to support lazy useState initializers
514
559
  initialState);
515
560
  };
516
561
 
517
562
  var useMemo = function (nextCreate, deps) {
518
563
  _this2._validateCurrentlyRenderingComponent();
564
+
519
565
  _this2._createWorkInProgressHook();
520
566
 
521
567
  var nextDeps = deps !== undefined ? deps : null;
@@ -523,6 +569,7 @@ var ReactShallowRenderer = function () {
523
569
  if (_this2._workInProgressHook !== null && _this2._workInProgressHook.memoizedState !== null) {
524
570
  var prevState = _this2._workInProgressHook.memoizedState;
525
571
  var prevDeps = prevState[1];
572
+
526
573
  if (nextDeps !== null) {
527
574
  if (areHookInputsEqual(nextDeps, prevDeps)) {
528
575
  return prevState[0];
@@ -537,13 +584,20 @@ var ReactShallowRenderer = function () {
537
584
 
538
585
  var useRef = function (initialValue) {
539
586
  _this2._validateCurrentlyRenderingComponent();
587
+
540
588
  _this2._createWorkInProgressHook();
589
+
541
590
  var previousRef = _this2._workInProgressHook.memoizedState;
591
+
542
592
  if (previousRef === null) {
543
- var ref = { current: initialValue };
593
+ var ref = {
594
+ current: initialValue
595
+ };
596
+
544
597
  {
545
598
  Object.seal(ref);
546
599
  }
600
+
547
601
  _this2._workInProgressHook.memoizedState = ref;
548
602
  return ref;
549
603
  } else {
@@ -575,6 +629,7 @@ var ReactShallowRenderer = function () {
575
629
  useCallback: identity,
576
630
  useContext: function (context) {
577
631
  _this2._validateCurrentlyRenderingComponent();
632
+
578
633
  return readContext(context);
579
634
  },
580
635
  useDebugValue: noOp,
@@ -589,13 +644,13 @@ var ReactShallowRenderer = function () {
589
644
  };
590
645
  };
591
646
 
592
- ReactShallowRenderer.prototype._dispatchAction = function _dispatchAction(queue, action) {
647
+ _proto2._dispatchAction = function _dispatchAction(queue, action) {
593
648
  var _this3 = this;
594
649
 
595
650
  (function () {
596
651
  if (!(_this3._numberOfReRenders < RE_RENDER_LIMIT)) {
597
652
  {
598
- throw ReactError(Error('Too many re-renders. React limits the number of renders to prevent an infinite loop.'));
653
+ throw ReactError(Error("Too many re-renders. React limits the number of renders to prevent an infinite loop."));
599
654
  }
600
655
  }
601
656
  })();
@@ -610,43 +665,49 @@ var ReactShallowRenderer = function () {
610
665
  next: null
611
666
  };
612
667
  var renderPhaseUpdates = this._renderPhaseUpdates;
668
+
613
669
  if (renderPhaseUpdates === null) {
614
670
  this._renderPhaseUpdates = renderPhaseUpdates = new Map();
615
671
  }
672
+
616
673
  var firstRenderPhaseUpdate = renderPhaseUpdates.get(queue);
674
+
617
675
  if (firstRenderPhaseUpdate === undefined) {
618
676
  renderPhaseUpdates.set(queue, update);
619
677
  } else {
620
678
  // Append the update to the end of the list.
621
679
  var lastRenderPhaseUpdate = firstRenderPhaseUpdate;
680
+
622
681
  while (lastRenderPhaseUpdate.next !== null) {
623
682
  lastRenderPhaseUpdate = lastRenderPhaseUpdate.next;
624
683
  }
684
+
625
685
  lastRenderPhaseUpdate.next = update;
626
686
  }
627
687
  } else {
628
688
  var _update2 = {
629
689
  action: action,
630
690
  next: null
631
- };
691
+ }; // Append the update to the end of the list.
632
692
 
633
- // Append the update to the end of the list.
634
693
  var last = queue.first;
694
+
635
695
  if (last === null) {
636
696
  queue.first = _update2;
637
697
  } else {
638
698
  while (last.next !== null) {
639
699
  last = last.next;
640
700
  }
701
+
641
702
  last.next = _update2;
642
- }
703
+ } // Re-render now.
704
+
643
705
 
644
- // Re-render now.
645
706
  this.render(this._element, this._context);
646
707
  }
647
708
  };
648
709
 
649
- ReactShallowRenderer.prototype._createWorkInProgressHook = function _createWorkInProgressHook() {
710
+ _proto2._createWorkInProgressHook = function _createWorkInProgressHook() {
650
711
  if (this._workInProgressHook === null) {
651
712
  // This is the first hook in the list
652
713
  if (this._firstWorkInProgressHook === null) {
@@ -659,8 +720,8 @@ var ReactShallowRenderer = function () {
659
720
  }
660
721
  } else {
661
722
  if (this._workInProgressHook.next === null) {
662
- this._isReRender = false;
663
- // Append to the end of the list
723
+ this._isReRender = false; // Append to the end of the list
724
+
664
725
  this._workInProgressHook = this._workInProgressHook.next = createHook();
665
726
  } else {
666
727
  // There's already a work-in-progress. Reuse it.
@@ -668,19 +729,19 @@ var ReactShallowRenderer = function () {
668
729
  this._workInProgressHook = this._workInProgressHook.next;
669
730
  }
670
731
  }
732
+
671
733
  return this._workInProgressHook;
672
734
  };
673
735
 
674
- ReactShallowRenderer.prototype._finishHooks = function _finishHooks(element, context) {
736
+ _proto2._finishHooks = function _finishHooks(element, context) {
675
737
  if (this._didScheduleRenderPhaseUpdate) {
676
738
  // Updates were scheduled during the render phase. They are stored in
677
739
  // the `renderPhaseUpdates` map. Call the component again, reusing the
678
740
  // work-in-progress hooks and applying the additional updates on top. Keep
679
741
  // restarting until no more updates are scheduled.
680
742
  this._didScheduleRenderPhaseUpdate = false;
681
- this._numberOfReRenders += 1;
743
+ this._numberOfReRenders += 1; // Start over from the beginning of the list
682
744
 
683
- // Start over from the beginning of the list
684
745
  this._workInProgressHook = null;
685
746
  this._rendering = false;
686
747
  this.render(element, context);
@@ -691,37 +752,39 @@ var ReactShallowRenderer = function () {
691
752
  }
692
753
  };
693
754
 
694
- ReactShallowRenderer.prototype.getMountedInstance = function getMountedInstance() {
755
+ _proto2.getMountedInstance = function getMountedInstance() {
695
756
  return this._instance;
696
757
  };
697
758
 
698
- ReactShallowRenderer.prototype.getRenderOutput = function getRenderOutput() {
759
+ _proto2.getRenderOutput = function getRenderOutput() {
699
760
  return this._rendered;
700
761
  };
701
762
 
702
- ReactShallowRenderer.prototype.render = function render(element) {
763
+ _proto2.render = function render(element) {
703
764
  var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : emptyObject;
704
765
 
705
766
  (function () {
706
767
  if (!React.isValidElement(element)) {
707
768
  {
708
- 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.' : '')));
769
+ 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.' : '')));
709
770
  }
710
771
  }
711
772
  })();
712
- element = element;
713
- // Show a special message for host elements since it's a common case.
773
+
774
+ element = element; // Show a special message for host elements since it's a common case.
775
+
714
776
  (function () {
715
777
  if (!(typeof element.type !== 'string')) {
716
778
  {
717
- throw ReactError(Error('ReactShallowRenderer render(): Shallow rendering works only with custom components, not primitives (' + element.type + '). Instead of calling `.render(el)` and inspecting the rendered output, look at `el.props` directly instead.'));
779
+ throw ReactError(Error("ReactShallowRenderer render(): Shallow rendering works only with custom components, not primitives (" + element.type + "). Instead of calling `.render(el)` and inspecting the rendered output, look at `el.props` directly instead."));
718
780
  }
719
781
  }
720
782
  })();
783
+
721
784
  (function () {
722
785
  if (!(reactIs.isForwardRef(element) || typeof element.type === 'function' || reactIs.isMemo(element.type))) {
723
786
  {
724
- throw ReactError(Error('ReactShallowRenderer render(): Shallow rendering works only with custom components, but the provided element type was `' + (Array.isArray(element.type) ? 'array' : element.type === null ? 'null' : typeof element.type) + '`.'));
787
+ throw ReactError(Error("ReactShallowRenderer render(): Shallow rendering works only with custom components, but the provided element type was `" + (Array.isArray(element.type) ? 'array' : element.type === null ? 'null' : typeof element.type) + "`."));
725
788
  }
726
789
  }
727
790
  })();
@@ -729,18 +792,17 @@ var ReactShallowRenderer = function () {
729
792
  if (this._rendering) {
730
793
  return;
731
794
  }
795
+
732
796
  if (this._element != null && this._element.type !== element.type) {
733
797
  this._reset();
734
798
  }
735
799
 
736
800
  var elementType = reactIs.isMemo(element.type) ? element.type.type : element.type;
737
801
  var previousElement = this._element;
738
-
739
802
  this._rendering = true;
740
803
  this._element = element;
741
- this._context = getMaskedContext(elementType.contextTypes, context);
804
+ this._context = getMaskedContext(elementType.contextTypes, context); // Inner memo component props aren't currently validated in createElement.
742
805
 
743
- // Inner memo component props aren't currently validated in createElement.
744
806
  if (reactIs.isMemo(element.type) && elementType.propTypes) {
745
807
  currentlyValidatingElement = element;
746
808
  checkPropTypes(elementType.propTypes, element.props, 'prop', getComponentName(elementType), getStackAddendum);
@@ -751,8 +813,10 @@ var ReactShallowRenderer = function () {
751
813
  } else {
752
814
  if (shouldConstruct(elementType)) {
753
815
  this._instance = new elementType(element.props, this._context, this._updater);
816
+
754
817
  if (typeof elementType.getDerivedStateFromProps === 'function') {
755
818
  var partialState = elementType.getDerivedStateFromProps.call(null, element.props, this._instance.state);
819
+
756
820
  if (partialState != null) {
757
821
  this._instance.state = _assign({}, this._instance.state, partialState);
758
822
  }
@@ -761,23 +825,26 @@ var ReactShallowRenderer = function () {
761
825
  if (elementType.contextTypes) {
762
826
  currentlyValidatingElement = element;
763
827
  checkPropTypes(elementType.contextTypes, this._context, 'context', getName(elementType, this._instance), getStackAddendum);
764
-
765
828
  currentlyValidatingElement = null;
766
829
  }
767
830
 
768
831
  this._mountClassComponent(elementType, element, this._context);
769
832
  } else {
770
833
  var shouldRender = true;
834
+
771
835
  if (reactIs.isMemo(element.type) && previousElement !== null) {
772
836
  // This is a Memo component that is being re-rendered.
773
837
  var compare = element.type.compare || shallowEqual;
838
+
774
839
  if (compare(previousElement.props, element.props)) {
775
840
  shouldRender = false;
776
841
  }
777
842
  }
843
+
778
844
  if (shouldRender) {
779
845
  var prevDispatcher = ReactCurrentDispatcher.current;
780
846
  ReactCurrentDispatcher.current = this._dispatcher;
847
+
781
848
  try {
782
849
  // elementType could still be a ForwardRef if it was
783
850
  // nested inside Memo.
@@ -785,10 +852,11 @@ var ReactShallowRenderer = function () {
785
852
  (function () {
786
853
  if (!(typeof elementType.render === 'function')) {
787
854
  {
788
- throw ReactError(Error('forwardRef requires a render function but was given ' + typeof elementType.render + '.'));
855
+ throw ReactError(Error("forwardRef requires a render function but was given " + typeof elementType.render + "."));
789
856
  }
790
857
  }
791
858
  })();
859
+
792
860
  this._rendered = elementType.render.call(undefined, element.props, element.ref);
793
861
  } else {
794
862
  this._rendered = elementType(element.props, this._context);
@@ -796,61 +864,61 @@ var ReactShallowRenderer = function () {
796
864
  } finally {
797
865
  ReactCurrentDispatcher.current = prevDispatcher;
798
866
  }
867
+
799
868
  this._finishHooks(element, context);
800
869
  }
801
870
  }
802
871
  }
803
872
 
804
873
  this._rendering = false;
874
+
805
875
  this._updater._invokeCallbacks();
806
876
 
807
877
  return this.getRenderOutput();
808
878
  };
809
879
 
810
- ReactShallowRenderer.prototype.unmount = function unmount() {
880
+ _proto2.unmount = function unmount() {
811
881
  if (this._instance) {
812
882
  if (typeof this._instance.componentWillUnmount === 'function') {
813
883
  this._instance.componentWillUnmount();
814
884
  }
815
885
  }
886
+
816
887
  this._reset();
817
888
  };
818
889
 
819
- ReactShallowRenderer.prototype._mountClassComponent = function _mountClassComponent(elementType, element, context) {
890
+ _proto2._mountClassComponent = function _mountClassComponent(elementType, element, context) {
820
891
  this._instance.context = context;
821
892
  this._instance.props = element.props;
822
893
  this._instance.state = this._instance.state || null;
823
894
  this._instance.updater = this._updater;
824
895
 
825
896
  if (typeof this._instance.UNSAFE_componentWillMount === 'function' || typeof this._instance.componentWillMount === 'function') {
826
- var beforeState = this._newState;
827
-
828
- // In order to support react-lifecycles-compat polyfilled components,
897
+ var beforeState = this._newState; // In order to support react-lifecycles-compat polyfilled components,
829
898
  // Unsafe lifecycles should not be invoked for components using the new APIs.
899
+
830
900
  if (typeof elementType.getDerivedStateFromProps !== 'function' && typeof this._instance.getSnapshotBeforeUpdate !== 'function') {
831
901
  if (typeof this._instance.componentWillMount === 'function') {
832
902
  this._instance.componentWillMount();
833
903
  }
904
+
834
905
  if (typeof this._instance.UNSAFE_componentWillMount === 'function') {
835
906
  this._instance.UNSAFE_componentWillMount();
836
907
  }
837
- }
908
+ } // setState may have been called during cWM
909
+
838
910
 
839
- // setState may have been called during cWM
840
911
  if (beforeState !== this._newState) {
841
912
  this._instance.state = this._newState || emptyObject;
842
913
  }
843
914
  }
844
915
 
845
- this._rendered = this._instance.render();
846
- // Intentionally do not call componentDidMount()
916
+ this._rendered = this._instance.render(); // Intentionally do not call componentDidMount()
847
917
  // because DOM refs are not available.
848
918
  };
849
919
 
850
- ReactShallowRenderer.prototype._updateClassComponent = function _updateClassComponent(elementType, element, context) {
920
+ _proto2._updateClassComponent = function _updateClassComponent(elementType, element, context) {
851
921
  var props = element.props;
852
-
853
-
854
922
  var oldState = this._instance.state || emptyObject;
855
923
  var oldProps = this._instance.props;
856
924
 
@@ -861,22 +929,26 @@ var ReactShallowRenderer = function () {
861
929
  if (typeof this._instance.componentWillReceiveProps === 'function') {
862
930
  this._instance.componentWillReceiveProps(props, context);
863
931
  }
932
+
864
933
  if (typeof this._instance.UNSAFE_componentWillReceiveProps === 'function') {
865
934
  this._instance.UNSAFE_componentWillReceiveProps(props, context);
866
935
  }
867
936
  }
868
- }
937
+ } // Read state after cWRP in case it calls setState
938
+
869
939
 
870
- // Read state after cWRP in case it calls setState
871
940
  var state = this._newState || oldState;
941
+
872
942
  if (typeof elementType.getDerivedStateFromProps === 'function') {
873
943
  var partialState = elementType.getDerivedStateFromProps.call(null, props, state);
944
+
874
945
  if (partialState != null) {
875
946
  state = _assign({}, state, partialState);
876
947
  }
877
948
  }
878
949
 
879
950
  var shouldUpdate = true;
951
+
880
952
  if (this._forcedUpdate) {
881
953
  shouldUpdate = true;
882
954
  this._forcedUpdate = false;
@@ -893,6 +965,7 @@ var ReactShallowRenderer = function () {
893
965
  if (typeof this._instance.componentWillUpdate === 'function') {
894
966
  this._instance.componentWillUpdate(props, state, context);
895
967
  }
968
+
896
969
  if (typeof this._instance.UNSAFE_componentWillUpdate === 'function') {
897
970
  this._instance.UNSAFE_componentWillUpdate(props, state, context);
898
971
  }
@@ -906,9 +979,9 @@ var ReactShallowRenderer = function () {
906
979
 
907
980
  if (shouldUpdate) {
908
981
  this._rendered = this._instance.render();
909
- }
910
- // Intentionally do not call componentDidUpdate()
982
+ } // Intentionally do not call componentDidUpdate()
911
983
  // because DOM refs are not available.
984
+
912
985
  };
913
986
 
914
987
  return ReactShallowRenderer;
@@ -935,11 +1008,13 @@ function getDisplayName(element) {
935
1008
 
936
1009
  function getStackAddendum() {
937
1010
  var stack = '';
1011
+
938
1012
  if (currentlyValidatingElement) {
939
1013
  var name = getDisplayName(currentlyValidatingElement);
940
1014
  var owner = currentlyValidatingElement._owner;
941
1015
  stack += describeComponentFrame(name, currentlyValidatingElement._source, owner && getComponentName(owner.type));
942
1016
  }
1017
+
943
1018
  return stack;
944
1019
  }
945
1020
 
@@ -956,10 +1031,13 @@ function getMaskedContext(contextTypes, unmaskedContext) {
956
1031
  if (!contextTypes || !unmaskedContext) {
957
1032
  return emptyObject;
958
1033
  }
1034
+
959
1035
  var context = {};
1036
+
960
1037
  for (var key in contextTypes) {
961
1038
  context[key] = unmaskedContext[key];
962
1039
  }
1040
+
963
1041
  return context;
964
1042
  }
965
1043
 
@@ -973,6 +1051,8 @@ var ReactShallowRenderer$3 = ( ReactShallowRenderer$2 && ReactShallowRenderer )
973
1051
 
974
1052
  // TODO: decide on the top-level export form.
975
1053
  // This is hacky but makes it work with both Rollup and Jest.
1054
+
1055
+
976
1056
  var shallow = ReactShallowRenderer$3.default || ReactShallowRenderer$3;
977
1057
 
978
1058
  module.exports = shallow;