1 | /**
|
---|
2 | * @license React
|
---|
3 | * react-jsx-dev-runtime.development.js
|
---|
4 | *
|
---|
5 | * Copyright (c) Facebook, Inc. and its affiliates.
|
---|
6 | *
|
---|
7 | * This source code is licensed under the MIT license found in the
|
---|
8 | * LICENSE file in the root directory of this source tree.
|
---|
9 | */
|
---|
10 |
|
---|
11 | 'use strict';
|
---|
12 |
|
---|
13 | if (process.env.NODE_ENV !== "production") {
|
---|
14 | (function() {
|
---|
15 | 'use strict';
|
---|
16 |
|
---|
17 | var React = require('react');
|
---|
18 |
|
---|
19 | // ATTENTION
|
---|
20 | // When adding new symbols to this file,
|
---|
21 | // Please consider also adding to 'react-devtools-shared/src/backend/ReactSymbols'
|
---|
22 | // The Symbol used to tag the ReactElement-like types.
|
---|
23 | var REACT_ELEMENT_TYPE = Symbol.for('react.element');
|
---|
24 | var REACT_PORTAL_TYPE = Symbol.for('react.portal');
|
---|
25 | var REACT_FRAGMENT_TYPE = Symbol.for('react.fragment');
|
---|
26 | var REACT_STRICT_MODE_TYPE = Symbol.for('react.strict_mode');
|
---|
27 | var REACT_PROFILER_TYPE = Symbol.for('react.profiler');
|
---|
28 | var REACT_PROVIDER_TYPE = Symbol.for('react.provider');
|
---|
29 | var REACT_CONTEXT_TYPE = Symbol.for('react.context');
|
---|
30 | var REACT_FORWARD_REF_TYPE = Symbol.for('react.forward_ref');
|
---|
31 | var REACT_SUSPENSE_TYPE = Symbol.for('react.suspense');
|
---|
32 | var REACT_SUSPENSE_LIST_TYPE = Symbol.for('react.suspense_list');
|
---|
33 | var REACT_MEMO_TYPE = Symbol.for('react.memo');
|
---|
34 | var REACT_LAZY_TYPE = Symbol.for('react.lazy');
|
---|
35 | var REACT_OFFSCREEN_TYPE = Symbol.for('react.offscreen');
|
---|
36 | var MAYBE_ITERATOR_SYMBOL = Symbol.iterator;
|
---|
37 | var FAUX_ITERATOR_SYMBOL = '@@iterator';
|
---|
38 | function getIteratorFn(maybeIterable) {
|
---|
39 | if (maybeIterable === null || typeof maybeIterable !== 'object') {
|
---|
40 | return null;
|
---|
41 | }
|
---|
42 |
|
---|
43 | var maybeIterator = MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL];
|
---|
44 |
|
---|
45 | if (typeof maybeIterator === 'function') {
|
---|
46 | return maybeIterator;
|
---|
47 | }
|
---|
48 |
|
---|
49 | return null;
|
---|
50 | }
|
---|
51 |
|
---|
52 | var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
---|
53 |
|
---|
54 | function error(format) {
|
---|
55 | {
|
---|
56 | {
|
---|
57 | for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
---|
58 | args[_key2 - 1] = arguments[_key2];
|
---|
59 | }
|
---|
60 |
|
---|
61 | printWarning('error', format, args);
|
---|
62 | }
|
---|
63 | }
|
---|
64 | }
|
---|
65 |
|
---|
66 | function printWarning(level, format, args) {
|
---|
67 | // When changing this logic, you might want to also
|
---|
68 | // update consoleWithStackDev.www.js as well.
|
---|
69 | {
|
---|
70 | var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
|
---|
71 | var stack = ReactDebugCurrentFrame.getStackAddendum();
|
---|
72 |
|
---|
73 | if (stack !== '') {
|
---|
74 | format += '%s';
|
---|
75 | args = args.concat([stack]);
|
---|
76 | } // eslint-disable-next-line react-internal/safe-string-coercion
|
---|
77 |
|
---|
78 |
|
---|
79 | var argsWithFormat = args.map(function (item) {
|
---|
80 | return String(item);
|
---|
81 | }); // Careful: RN currently depends on this prefix
|
---|
82 |
|
---|
83 | argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
|
---|
84 | // breaks IE9: https://github.com/facebook/react/issues/13610
|
---|
85 | // eslint-disable-next-line react-internal/no-production-logging
|
---|
86 |
|
---|
87 | Function.prototype.apply.call(console[level], console, argsWithFormat);
|
---|
88 | }
|
---|
89 | }
|
---|
90 |
|
---|
91 | // -----------------------------------------------------------------------------
|
---|
92 |
|
---|
93 | var enableScopeAPI = false; // Experimental Create Event Handle API.
|
---|
94 | var enableCacheElement = false;
|
---|
95 | var enableTransitionTracing = false; // No known bugs, but needs performance testing
|
---|
96 |
|
---|
97 | var enableLegacyHidden = false; // Enables unstable_avoidThisFallback feature in Fiber
|
---|
98 | // stuff. Intended to enable React core members to more easily debug scheduling
|
---|
99 | // issues in DEV builds.
|
---|
100 |
|
---|
101 | var enableDebugTracing = false; // Track which Fiber(s) schedule render work.
|
---|
102 |
|
---|
103 | var REACT_MODULE_REFERENCE;
|
---|
104 |
|
---|
105 | {
|
---|
106 | REACT_MODULE_REFERENCE = Symbol.for('react.module.reference');
|
---|
107 | }
|
---|
108 |
|
---|
109 | function isValidElementType(type) {
|
---|
110 | if (typeof type === 'string' || typeof type === 'function') {
|
---|
111 | return true;
|
---|
112 | } // Note: typeof might be other than 'symbol' or 'number' (e.g. if it's a polyfill).
|
---|
113 |
|
---|
114 |
|
---|
115 | if (type === REACT_FRAGMENT_TYPE || type === REACT_PROFILER_TYPE || enableDebugTracing || type === REACT_STRICT_MODE_TYPE || type === REACT_SUSPENSE_TYPE || type === REACT_SUSPENSE_LIST_TYPE || enableLegacyHidden || type === REACT_OFFSCREEN_TYPE || enableScopeAPI || enableCacheElement || enableTransitionTracing ) {
|
---|
116 | return true;
|
---|
117 | }
|
---|
118 |
|
---|
119 | if (typeof type === 'object' && type !== null) {
|
---|
120 | if (type.$$typeof === REACT_LAZY_TYPE || type.$$typeof === REACT_MEMO_TYPE || type.$$typeof === REACT_PROVIDER_TYPE || type.$$typeof === REACT_CONTEXT_TYPE || type.$$typeof === REACT_FORWARD_REF_TYPE || // This needs to include all possible module reference object
|
---|
121 | // types supported by any Flight configuration anywhere since
|
---|
122 | // we don't know which Flight build this will end up being used
|
---|
123 | // with.
|
---|
124 | type.$$typeof === REACT_MODULE_REFERENCE || type.getModuleId !== undefined) {
|
---|
125 | return true;
|
---|
126 | }
|
---|
127 | }
|
---|
128 |
|
---|
129 | return false;
|
---|
130 | }
|
---|
131 |
|
---|
132 | function getWrappedName(outerType, innerType, wrapperName) {
|
---|
133 | var displayName = outerType.displayName;
|
---|
134 |
|
---|
135 | if (displayName) {
|
---|
136 | return displayName;
|
---|
137 | }
|
---|
138 |
|
---|
139 | var functionName = innerType.displayName || innerType.name || '';
|
---|
140 | return functionName !== '' ? wrapperName + "(" + functionName + ")" : wrapperName;
|
---|
141 | } // Keep in sync with react-reconciler/getComponentNameFromFiber
|
---|
142 |
|
---|
143 |
|
---|
144 | function getContextName(type) {
|
---|
145 | return type.displayName || 'Context';
|
---|
146 | } // Note that the reconciler package should generally prefer to use getComponentNameFromFiber() instead.
|
---|
147 |
|
---|
148 |
|
---|
149 | function getComponentNameFromType(type) {
|
---|
150 | if (type == null) {
|
---|
151 | // Host root, text node or just invalid type.
|
---|
152 | return null;
|
---|
153 | }
|
---|
154 |
|
---|
155 | {
|
---|
156 | if (typeof type.tag === 'number') {
|
---|
157 | error('Received an unexpected object in getComponentNameFromType(). ' + 'This is likely a bug in React. Please file an issue.');
|
---|
158 | }
|
---|
159 | }
|
---|
160 |
|
---|
161 | if (typeof type === 'function') {
|
---|
162 | return type.displayName || type.name || null;
|
---|
163 | }
|
---|
164 |
|
---|
165 | if (typeof type === 'string') {
|
---|
166 | return type;
|
---|
167 | }
|
---|
168 |
|
---|
169 | switch (type) {
|
---|
170 | case REACT_FRAGMENT_TYPE:
|
---|
171 | return 'Fragment';
|
---|
172 |
|
---|
173 | case REACT_PORTAL_TYPE:
|
---|
174 | return 'Portal';
|
---|
175 |
|
---|
176 | case REACT_PROFILER_TYPE:
|
---|
177 | return 'Profiler';
|
---|
178 |
|
---|
179 | case REACT_STRICT_MODE_TYPE:
|
---|
180 | return 'StrictMode';
|
---|
181 |
|
---|
182 | case REACT_SUSPENSE_TYPE:
|
---|
183 | return 'Suspense';
|
---|
184 |
|
---|
185 | case REACT_SUSPENSE_LIST_TYPE:
|
---|
186 | return 'SuspenseList';
|
---|
187 |
|
---|
188 | }
|
---|
189 |
|
---|
190 | if (typeof type === 'object') {
|
---|
191 | switch (type.$$typeof) {
|
---|
192 | case REACT_CONTEXT_TYPE:
|
---|
193 | var context = type;
|
---|
194 | return getContextName(context) + '.Consumer';
|
---|
195 |
|
---|
196 | case REACT_PROVIDER_TYPE:
|
---|
197 | var provider = type;
|
---|
198 | return getContextName(provider._context) + '.Provider';
|
---|
199 |
|
---|
200 | case REACT_FORWARD_REF_TYPE:
|
---|
201 | return getWrappedName(type, type.render, 'ForwardRef');
|
---|
202 |
|
---|
203 | case REACT_MEMO_TYPE:
|
---|
204 | var outerName = type.displayName || null;
|
---|
205 |
|
---|
206 | if (outerName !== null) {
|
---|
207 | return outerName;
|
---|
208 | }
|
---|
209 |
|
---|
210 | return getComponentNameFromType(type.type) || 'Memo';
|
---|
211 |
|
---|
212 | case REACT_LAZY_TYPE:
|
---|
213 | {
|
---|
214 | var lazyComponent = type;
|
---|
215 | var payload = lazyComponent._payload;
|
---|
216 | var init = lazyComponent._init;
|
---|
217 |
|
---|
218 | try {
|
---|
219 | return getComponentNameFromType(init(payload));
|
---|
220 | } catch (x) {
|
---|
221 | return null;
|
---|
222 | }
|
---|
223 | }
|
---|
224 |
|
---|
225 | // eslint-disable-next-line no-fallthrough
|
---|
226 | }
|
---|
227 | }
|
---|
228 |
|
---|
229 | return null;
|
---|
230 | }
|
---|
231 |
|
---|
232 | var assign = Object.assign;
|
---|
233 |
|
---|
234 | // Helpers to patch console.logs to avoid logging during side-effect free
|
---|
235 | // replaying on render function. This currently only patches the object
|
---|
236 | // lazily which won't cover if the log function was extracted eagerly.
|
---|
237 | // We could also eagerly patch the method.
|
---|
238 | var disabledDepth = 0;
|
---|
239 | var prevLog;
|
---|
240 | var prevInfo;
|
---|
241 | var prevWarn;
|
---|
242 | var prevError;
|
---|
243 | var prevGroup;
|
---|
244 | var prevGroupCollapsed;
|
---|
245 | var prevGroupEnd;
|
---|
246 |
|
---|
247 | function disabledLog() {}
|
---|
248 |
|
---|
249 | disabledLog.__reactDisabledLog = true;
|
---|
250 | function disableLogs() {
|
---|
251 | {
|
---|
252 | if (disabledDepth === 0) {
|
---|
253 | /* eslint-disable react-internal/no-production-logging */
|
---|
254 | prevLog = console.log;
|
---|
255 | prevInfo = console.info;
|
---|
256 | prevWarn = console.warn;
|
---|
257 | prevError = console.error;
|
---|
258 | prevGroup = console.group;
|
---|
259 | prevGroupCollapsed = console.groupCollapsed;
|
---|
260 | prevGroupEnd = console.groupEnd; // https://github.com/facebook/react/issues/19099
|
---|
261 |
|
---|
262 | var props = {
|
---|
263 | configurable: true,
|
---|
264 | enumerable: true,
|
---|
265 | value: disabledLog,
|
---|
266 | writable: true
|
---|
267 | }; // $FlowFixMe Flow thinks console is immutable.
|
---|
268 |
|
---|
269 | Object.defineProperties(console, {
|
---|
270 | info: props,
|
---|
271 | log: props,
|
---|
272 | warn: props,
|
---|
273 | error: props,
|
---|
274 | group: props,
|
---|
275 | groupCollapsed: props,
|
---|
276 | groupEnd: props
|
---|
277 | });
|
---|
278 | /* eslint-enable react-internal/no-production-logging */
|
---|
279 | }
|
---|
280 |
|
---|
281 | disabledDepth++;
|
---|
282 | }
|
---|
283 | }
|
---|
284 | function reenableLogs() {
|
---|
285 | {
|
---|
286 | disabledDepth--;
|
---|
287 |
|
---|
288 | if (disabledDepth === 0) {
|
---|
289 | /* eslint-disable react-internal/no-production-logging */
|
---|
290 | var props = {
|
---|
291 | configurable: true,
|
---|
292 | enumerable: true,
|
---|
293 | writable: true
|
---|
294 | }; // $FlowFixMe Flow thinks console is immutable.
|
---|
295 |
|
---|
296 | Object.defineProperties(console, {
|
---|
297 | log: assign({}, props, {
|
---|
298 | value: prevLog
|
---|
299 | }),
|
---|
300 | info: assign({}, props, {
|
---|
301 | value: prevInfo
|
---|
302 | }),
|
---|
303 | warn: assign({}, props, {
|
---|
304 | value: prevWarn
|
---|
305 | }),
|
---|
306 | error: assign({}, props, {
|
---|
307 | value: prevError
|
---|
308 | }),
|
---|
309 | group: assign({}, props, {
|
---|
310 | value: prevGroup
|
---|
311 | }),
|
---|
312 | groupCollapsed: assign({}, props, {
|
---|
313 | value: prevGroupCollapsed
|
---|
314 | }),
|
---|
315 | groupEnd: assign({}, props, {
|
---|
316 | value: prevGroupEnd
|
---|
317 | })
|
---|
318 | });
|
---|
319 | /* eslint-enable react-internal/no-production-logging */
|
---|
320 | }
|
---|
321 |
|
---|
322 | if (disabledDepth < 0) {
|
---|
323 | error('disabledDepth fell below zero. ' + 'This is a bug in React. Please file an issue.');
|
---|
324 | }
|
---|
325 | }
|
---|
326 | }
|
---|
327 |
|
---|
328 | var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
|
---|
329 | var prefix;
|
---|
330 | function describeBuiltInComponentFrame(name, source, ownerFn) {
|
---|
331 | {
|
---|
332 | if (prefix === undefined) {
|
---|
333 | // Extract the VM specific prefix used by each line.
|
---|
334 | try {
|
---|
335 | throw Error();
|
---|
336 | } catch (x) {
|
---|
337 | var match = x.stack.trim().match(/\n( *(at )?)/);
|
---|
338 | prefix = match && match[1] || '';
|
---|
339 | }
|
---|
340 | } // We use the prefix to ensure our stacks line up with native stack frames.
|
---|
341 |
|
---|
342 |
|
---|
343 | return '\n' + prefix + name;
|
---|
344 | }
|
---|
345 | }
|
---|
346 | var reentry = false;
|
---|
347 | var componentFrameCache;
|
---|
348 |
|
---|
349 | {
|
---|
350 | var PossiblyWeakMap = typeof WeakMap === 'function' ? WeakMap : Map;
|
---|
351 | componentFrameCache = new PossiblyWeakMap();
|
---|
352 | }
|
---|
353 |
|
---|
354 | function describeNativeComponentFrame(fn, construct) {
|
---|
355 | // If something asked for a stack inside a fake render, it should get ignored.
|
---|
356 | if ( !fn || reentry) {
|
---|
357 | return '';
|
---|
358 | }
|
---|
359 |
|
---|
360 | {
|
---|
361 | var frame = componentFrameCache.get(fn);
|
---|
362 |
|
---|
363 | if (frame !== undefined) {
|
---|
364 | return frame;
|
---|
365 | }
|
---|
366 | }
|
---|
367 |
|
---|
368 | var control;
|
---|
369 | reentry = true;
|
---|
370 | var previousPrepareStackTrace = Error.prepareStackTrace; // $FlowFixMe It does accept undefined.
|
---|
371 |
|
---|
372 | Error.prepareStackTrace = undefined;
|
---|
373 | var previousDispatcher;
|
---|
374 |
|
---|
375 | {
|
---|
376 | previousDispatcher = ReactCurrentDispatcher.current; // Set the dispatcher in DEV because this might be call in the render function
|
---|
377 | // for warnings.
|
---|
378 |
|
---|
379 | ReactCurrentDispatcher.current = null;
|
---|
380 | disableLogs();
|
---|
381 | }
|
---|
382 |
|
---|
383 | try {
|
---|
384 | // This should throw.
|
---|
385 | if (construct) {
|
---|
386 | // Something should be setting the props in the constructor.
|
---|
387 | var Fake = function () {
|
---|
388 | throw Error();
|
---|
389 | }; // $FlowFixMe
|
---|
390 |
|
---|
391 |
|
---|
392 | Object.defineProperty(Fake.prototype, 'props', {
|
---|
393 | set: function () {
|
---|
394 | // We use a throwing setter instead of frozen or non-writable props
|
---|
395 | // because that won't throw in a non-strict mode function.
|
---|
396 | throw Error();
|
---|
397 | }
|
---|
398 | });
|
---|
399 |
|
---|
400 | if (typeof Reflect === 'object' && Reflect.construct) {
|
---|
401 | // We construct a different control for this case to include any extra
|
---|
402 | // frames added by the construct call.
|
---|
403 | try {
|
---|
404 | Reflect.construct(Fake, []);
|
---|
405 | } catch (x) {
|
---|
406 | control = x;
|
---|
407 | }
|
---|
408 |
|
---|
409 | Reflect.construct(fn, [], Fake);
|
---|
410 | } else {
|
---|
411 | try {
|
---|
412 | Fake.call();
|
---|
413 | } catch (x) {
|
---|
414 | control = x;
|
---|
415 | }
|
---|
416 |
|
---|
417 | fn.call(Fake.prototype);
|
---|
418 | }
|
---|
419 | } else {
|
---|
420 | try {
|
---|
421 | throw Error();
|
---|
422 | } catch (x) {
|
---|
423 | control = x;
|
---|
424 | }
|
---|
425 |
|
---|
426 | fn();
|
---|
427 | }
|
---|
428 | } catch (sample) {
|
---|
429 | // This is inlined manually because closure doesn't do it for us.
|
---|
430 | if (sample && control && typeof sample.stack === 'string') {
|
---|
431 | // This extracts the first frame from the sample that isn't also in the control.
|
---|
432 | // Skipping one frame that we assume is the frame that calls the two.
|
---|
433 | var sampleLines = sample.stack.split('\n');
|
---|
434 | var controlLines = control.stack.split('\n');
|
---|
435 | var s = sampleLines.length - 1;
|
---|
436 | var c = controlLines.length - 1;
|
---|
437 |
|
---|
438 | while (s >= 1 && c >= 0 && sampleLines[s] !== controlLines[c]) {
|
---|
439 | // We expect at least one stack frame to be shared.
|
---|
440 | // Typically this will be the root most one. However, stack frames may be
|
---|
441 | // cut off due to maximum stack limits. In this case, one maybe cut off
|
---|
442 | // earlier than the other. We assume that the sample is longer or the same
|
---|
443 | // and there for cut off earlier. So we should find the root most frame in
|
---|
444 | // the sample somewhere in the control.
|
---|
445 | c--;
|
---|
446 | }
|
---|
447 |
|
---|
448 | for (; s >= 1 && c >= 0; s--, c--) {
|
---|
449 | // Next we find the first one that isn't the same which should be the
|
---|
450 | // frame that called our sample function and the control.
|
---|
451 | if (sampleLines[s] !== controlLines[c]) {
|
---|
452 | // In V8, the first line is describing the message but other VMs don't.
|
---|
453 | // If we're about to return the first line, and the control is also on the same
|
---|
454 | // line, that's a pretty good indicator that our sample threw at same line as
|
---|
455 | // the control. I.e. before we entered the sample frame. So we ignore this result.
|
---|
456 | // This can happen if you passed a class to function component, or non-function.
|
---|
457 | if (s !== 1 || c !== 1) {
|
---|
458 | do {
|
---|
459 | s--;
|
---|
460 | c--; // We may still have similar intermediate frames from the construct call.
|
---|
461 | // The next one that isn't the same should be our match though.
|
---|
462 |
|
---|
463 | if (c < 0 || sampleLines[s] !== controlLines[c]) {
|
---|
464 | // V8 adds a "new" prefix for native classes. Let's remove it to make it prettier.
|
---|
465 | var _frame = '\n' + sampleLines[s].replace(' at new ', ' at '); // If our component frame is labeled "<anonymous>"
|
---|
466 | // but we have a user-provided "displayName"
|
---|
467 | // splice it in to make the stack more readable.
|
---|
468 |
|
---|
469 |
|
---|
470 | if (fn.displayName && _frame.includes('<anonymous>')) {
|
---|
471 | _frame = _frame.replace('<anonymous>', fn.displayName);
|
---|
472 | }
|
---|
473 |
|
---|
474 | {
|
---|
475 | if (typeof fn === 'function') {
|
---|
476 | componentFrameCache.set(fn, _frame);
|
---|
477 | }
|
---|
478 | } // Return the line we found.
|
---|
479 |
|
---|
480 |
|
---|
481 | return _frame;
|
---|
482 | }
|
---|
483 | } while (s >= 1 && c >= 0);
|
---|
484 | }
|
---|
485 |
|
---|
486 | break;
|
---|
487 | }
|
---|
488 | }
|
---|
489 | }
|
---|
490 | } finally {
|
---|
491 | reentry = false;
|
---|
492 |
|
---|
493 | {
|
---|
494 | ReactCurrentDispatcher.current = previousDispatcher;
|
---|
495 | reenableLogs();
|
---|
496 | }
|
---|
497 |
|
---|
498 | Error.prepareStackTrace = previousPrepareStackTrace;
|
---|
499 | } // Fallback to just using the name if we couldn't make it throw.
|
---|
500 |
|
---|
501 |
|
---|
502 | var name = fn ? fn.displayName || fn.name : '';
|
---|
503 | var syntheticFrame = name ? describeBuiltInComponentFrame(name) : '';
|
---|
504 |
|
---|
505 | {
|
---|
506 | if (typeof fn === 'function') {
|
---|
507 | componentFrameCache.set(fn, syntheticFrame);
|
---|
508 | }
|
---|
509 | }
|
---|
510 |
|
---|
511 | return syntheticFrame;
|
---|
512 | }
|
---|
513 | function describeFunctionComponentFrame(fn, source, ownerFn) {
|
---|
514 | {
|
---|
515 | return describeNativeComponentFrame(fn, false);
|
---|
516 | }
|
---|
517 | }
|
---|
518 |
|
---|
519 | function shouldConstruct(Component) {
|
---|
520 | var prototype = Component.prototype;
|
---|
521 | return !!(prototype && prototype.isReactComponent);
|
---|
522 | }
|
---|
523 |
|
---|
524 | function describeUnknownElementTypeFrameInDEV(type, source, ownerFn) {
|
---|
525 |
|
---|
526 | if (type == null) {
|
---|
527 | return '';
|
---|
528 | }
|
---|
529 |
|
---|
530 | if (typeof type === 'function') {
|
---|
531 | {
|
---|
532 | return describeNativeComponentFrame(type, shouldConstruct(type));
|
---|
533 | }
|
---|
534 | }
|
---|
535 |
|
---|
536 | if (typeof type === 'string') {
|
---|
537 | return describeBuiltInComponentFrame(type);
|
---|
538 | }
|
---|
539 |
|
---|
540 | switch (type) {
|
---|
541 | case REACT_SUSPENSE_TYPE:
|
---|
542 | return describeBuiltInComponentFrame('Suspense');
|
---|
543 |
|
---|
544 | case REACT_SUSPENSE_LIST_TYPE:
|
---|
545 | return describeBuiltInComponentFrame('SuspenseList');
|
---|
546 | }
|
---|
547 |
|
---|
548 | if (typeof type === 'object') {
|
---|
549 | switch (type.$$typeof) {
|
---|
550 | case REACT_FORWARD_REF_TYPE:
|
---|
551 | return describeFunctionComponentFrame(type.render);
|
---|
552 |
|
---|
553 | case REACT_MEMO_TYPE:
|
---|
554 | // Memo may contain any component type so we recursively resolve it.
|
---|
555 | return describeUnknownElementTypeFrameInDEV(type.type, source, ownerFn);
|
---|
556 |
|
---|
557 | case REACT_LAZY_TYPE:
|
---|
558 | {
|
---|
559 | var lazyComponent = type;
|
---|
560 | var payload = lazyComponent._payload;
|
---|
561 | var init = lazyComponent._init;
|
---|
562 |
|
---|
563 | try {
|
---|
564 | // Lazy may contain any component type so we recursively resolve it.
|
---|
565 | return describeUnknownElementTypeFrameInDEV(init(payload), source, ownerFn);
|
---|
566 | } catch (x) {}
|
---|
567 | }
|
---|
568 | }
|
---|
569 | }
|
---|
570 |
|
---|
571 | return '';
|
---|
572 | }
|
---|
573 |
|
---|
574 | var hasOwnProperty = Object.prototype.hasOwnProperty;
|
---|
575 |
|
---|
576 | var loggedTypeFailures = {};
|
---|
577 | var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
|
---|
578 |
|
---|
579 | function setCurrentlyValidatingElement(element) {
|
---|
580 | {
|
---|
581 | if (element) {
|
---|
582 | var owner = element._owner;
|
---|
583 | var stack = describeUnknownElementTypeFrameInDEV(element.type, element._source, owner ? owner.type : null);
|
---|
584 | ReactDebugCurrentFrame.setExtraStackFrame(stack);
|
---|
585 | } else {
|
---|
586 | ReactDebugCurrentFrame.setExtraStackFrame(null);
|
---|
587 | }
|
---|
588 | }
|
---|
589 | }
|
---|
590 |
|
---|
591 | function checkPropTypes(typeSpecs, values, location, componentName, element) {
|
---|
592 | {
|
---|
593 | // $FlowFixMe This is okay but Flow doesn't know it.
|
---|
594 | var has = Function.call.bind(hasOwnProperty);
|
---|
595 |
|
---|
596 | for (var typeSpecName in typeSpecs) {
|
---|
597 | if (has(typeSpecs, typeSpecName)) {
|
---|
598 | var error$1 = void 0; // Prop type validation may throw. In case they do, we don't want to
|
---|
599 | // fail the render phase where it didn't fail before. So we log it.
|
---|
600 | // After these have been cleaned up, we'll let them throw.
|
---|
601 |
|
---|
602 | try {
|
---|
603 | // This is intentionally an invariant that gets caught. It's the same
|
---|
604 | // behavior as without this statement except with a better message.
|
---|
605 | if (typeof typeSpecs[typeSpecName] !== 'function') {
|
---|
606 | // eslint-disable-next-line react-internal/prod-error-codes
|
---|
607 | var err = Error((componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' + 'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.' + 'This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.');
|
---|
608 | err.name = 'Invariant Violation';
|
---|
609 | throw err;
|
---|
610 | }
|
---|
611 |
|
---|
612 | error$1 = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED');
|
---|
613 | } catch (ex) {
|
---|
614 | error$1 = ex;
|
---|
615 | }
|
---|
616 |
|
---|
617 | if (error$1 && !(error$1 instanceof Error)) {
|
---|
618 | setCurrentlyValidatingElement(element);
|
---|
619 |
|
---|
620 | error('%s: type specification of %s' + ' `%s` is invalid; the type checker ' + 'function must return `null` or an `Error` but returned a %s. ' + 'You may have forgotten to pass an argument to the type checker ' + 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' + 'shape all require an argument).', componentName || 'React class', location, typeSpecName, typeof error$1);
|
---|
621 |
|
---|
622 | setCurrentlyValidatingElement(null);
|
---|
623 | }
|
---|
624 |
|
---|
625 | if (error$1 instanceof Error && !(error$1.message in loggedTypeFailures)) {
|
---|
626 | // Only monitor this failure once because there tends to be a lot of the
|
---|
627 | // same error.
|
---|
628 | loggedTypeFailures[error$1.message] = true;
|
---|
629 | setCurrentlyValidatingElement(element);
|
---|
630 |
|
---|
631 | error('Failed %s type: %s', location, error$1.message);
|
---|
632 |
|
---|
633 | setCurrentlyValidatingElement(null);
|
---|
634 | }
|
---|
635 | }
|
---|
636 | }
|
---|
637 | }
|
---|
638 | }
|
---|
639 |
|
---|
640 | var isArrayImpl = Array.isArray; // eslint-disable-next-line no-redeclare
|
---|
641 |
|
---|
642 | function isArray(a) {
|
---|
643 | return isArrayImpl(a);
|
---|
644 | }
|
---|
645 |
|
---|
646 | /*
|
---|
647 | * The `'' + value` pattern (used in in perf-sensitive code) throws for Symbol
|
---|
648 | * and Temporal.* types. See https://github.com/facebook/react/pull/22064.
|
---|
649 | *
|
---|
650 | * The functions in this module will throw an easier-to-understand,
|
---|
651 | * easier-to-debug exception with a clear errors message message explaining the
|
---|
652 | * problem. (Instead of a confusing exception thrown inside the implementation
|
---|
653 | * of the `value` object).
|
---|
654 | */
|
---|
655 | // $FlowFixMe only called in DEV, so void return is not possible.
|
---|
656 | function typeName(value) {
|
---|
657 | {
|
---|
658 | // toStringTag is needed for namespaced types like Temporal.Instant
|
---|
659 | var hasToStringTag = typeof Symbol === 'function' && Symbol.toStringTag;
|
---|
660 | var type = hasToStringTag && value[Symbol.toStringTag] || value.constructor.name || 'Object';
|
---|
661 | return type;
|
---|
662 | }
|
---|
663 | } // $FlowFixMe only called in DEV, so void return is not possible.
|
---|
664 |
|
---|
665 |
|
---|
666 | function willCoercionThrow(value) {
|
---|
667 | {
|
---|
668 | try {
|
---|
669 | testStringCoercion(value);
|
---|
670 | return false;
|
---|
671 | } catch (e) {
|
---|
672 | return true;
|
---|
673 | }
|
---|
674 | }
|
---|
675 | }
|
---|
676 |
|
---|
677 | function testStringCoercion(value) {
|
---|
678 | // If you ended up here by following an exception call stack, here's what's
|
---|
679 | // happened: you supplied an object or symbol value to React (as a prop, key,
|
---|
680 | // DOM attribute, CSS property, string ref, etc.) and when React tried to
|
---|
681 | // coerce it to a string using `'' + value`, an exception was thrown.
|
---|
682 | //
|
---|
683 | // The most common types that will cause this exception are `Symbol` instances
|
---|
684 | // and Temporal objects like `Temporal.Instant`. But any object that has a
|
---|
685 | // `valueOf` or `[Symbol.toPrimitive]` method that throws will also cause this
|
---|
686 | // exception. (Library authors do this to prevent users from using built-in
|
---|
687 | // numeric operators like `+` or comparison operators like `>=` because custom
|
---|
688 | // methods are needed to perform accurate arithmetic or comparison.)
|
---|
689 | //
|
---|
690 | // To fix the problem, coerce this object or symbol value to a string before
|
---|
691 | // passing it to React. The most reliable way is usually `String(value)`.
|
---|
692 | //
|
---|
693 | // To find which value is throwing, check the browser or debugger console.
|
---|
694 | // Before this exception was thrown, there should be `console.error` output
|
---|
695 | // that shows the type (Symbol, Temporal.PlainDate, etc.) that caused the
|
---|
696 | // problem and how that type was used: key, atrribute, input value prop, etc.
|
---|
697 | // In most cases, this console output also shows the component and its
|
---|
698 | // ancestor components where the exception happened.
|
---|
699 | //
|
---|
700 | // eslint-disable-next-line react-internal/safe-string-coercion
|
---|
701 | return '' + value;
|
---|
702 | }
|
---|
703 | function checkKeyStringCoercion(value) {
|
---|
704 | {
|
---|
705 | if (willCoercionThrow(value)) {
|
---|
706 | error('The provided key is an unsupported type %s.' + ' This value must be coerced to a string before before using it here.', typeName(value));
|
---|
707 |
|
---|
708 | return testStringCoercion(value); // throw (to help callers find troubleshooting comments)
|
---|
709 | }
|
---|
710 | }
|
---|
711 | }
|
---|
712 |
|
---|
713 | var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
|
---|
714 | var RESERVED_PROPS = {
|
---|
715 | key: true,
|
---|
716 | ref: true,
|
---|
717 | __self: true,
|
---|
718 | __source: true
|
---|
719 | };
|
---|
720 | var specialPropKeyWarningShown;
|
---|
721 | var specialPropRefWarningShown;
|
---|
722 | var didWarnAboutStringRefs;
|
---|
723 |
|
---|
724 | {
|
---|
725 | didWarnAboutStringRefs = {};
|
---|
726 | }
|
---|
727 |
|
---|
728 | function hasValidRef(config) {
|
---|
729 | {
|
---|
730 | if (hasOwnProperty.call(config, 'ref')) {
|
---|
731 | var getter = Object.getOwnPropertyDescriptor(config, 'ref').get;
|
---|
732 |
|
---|
733 | if (getter && getter.isReactWarning) {
|
---|
734 | return false;
|
---|
735 | }
|
---|
736 | }
|
---|
737 | }
|
---|
738 |
|
---|
739 | return config.ref !== undefined;
|
---|
740 | }
|
---|
741 |
|
---|
742 | function hasValidKey(config) {
|
---|
743 | {
|
---|
744 | if (hasOwnProperty.call(config, 'key')) {
|
---|
745 | var getter = Object.getOwnPropertyDescriptor(config, 'key').get;
|
---|
746 |
|
---|
747 | if (getter && getter.isReactWarning) {
|
---|
748 | return false;
|
---|
749 | }
|
---|
750 | }
|
---|
751 | }
|
---|
752 |
|
---|
753 | return config.key !== undefined;
|
---|
754 | }
|
---|
755 |
|
---|
756 | function warnIfStringRefCannotBeAutoConverted(config, self) {
|
---|
757 | {
|
---|
758 | if (typeof config.ref === 'string' && ReactCurrentOwner.current && self && ReactCurrentOwner.current.stateNode !== self) {
|
---|
759 | var componentName = getComponentNameFromType(ReactCurrentOwner.current.type);
|
---|
760 |
|
---|
761 | if (!didWarnAboutStringRefs[componentName]) {
|
---|
762 | error('Component "%s" contains the string ref "%s". ' + 'Support for string refs will be removed in a future major release. ' + 'This case cannot be automatically converted to an arrow function. ' + 'We ask you to manually fix this case by using useRef() or createRef() instead. ' + 'Learn more about using refs safely here: ' + 'https://reactjs.org/link/strict-mode-string-ref', getComponentNameFromType(ReactCurrentOwner.current.type), config.ref);
|
---|
763 |
|
---|
764 | didWarnAboutStringRefs[componentName] = true;
|
---|
765 | }
|
---|
766 | }
|
---|
767 | }
|
---|
768 | }
|
---|
769 |
|
---|
770 | function defineKeyPropWarningGetter(props, displayName) {
|
---|
771 | {
|
---|
772 | var warnAboutAccessingKey = function () {
|
---|
773 | if (!specialPropKeyWarningShown) {
|
---|
774 | specialPropKeyWarningShown = true;
|
---|
775 |
|
---|
776 | error('%s: `key` is not a prop. Trying to access it will result ' + 'in `undefined` being returned. If you need to access the same ' + 'value within the child component, you should pass it as a different ' + 'prop. (https://reactjs.org/link/special-props)', displayName);
|
---|
777 | }
|
---|
778 | };
|
---|
779 |
|
---|
780 | warnAboutAccessingKey.isReactWarning = true;
|
---|
781 | Object.defineProperty(props, 'key', {
|
---|
782 | get: warnAboutAccessingKey,
|
---|
783 | configurable: true
|
---|
784 | });
|
---|
785 | }
|
---|
786 | }
|
---|
787 |
|
---|
788 | function defineRefPropWarningGetter(props, displayName) {
|
---|
789 | {
|
---|
790 | var warnAboutAccessingRef = function () {
|
---|
791 | if (!specialPropRefWarningShown) {
|
---|
792 | specialPropRefWarningShown = true;
|
---|
793 |
|
---|
794 | error('%s: `ref` is not a prop. Trying to access it will result ' + 'in `undefined` being returned. If you need to access the same ' + 'value within the child component, you should pass it as a different ' + 'prop. (https://reactjs.org/link/special-props)', displayName);
|
---|
795 | }
|
---|
796 | };
|
---|
797 |
|
---|
798 | warnAboutAccessingRef.isReactWarning = true;
|
---|
799 | Object.defineProperty(props, 'ref', {
|
---|
800 | get: warnAboutAccessingRef,
|
---|
801 | configurable: true
|
---|
802 | });
|
---|
803 | }
|
---|
804 | }
|
---|
805 | /**
|
---|
806 | * Factory method to create a new React element. This no longer adheres to
|
---|
807 | * the class pattern, so do not use new to call it. Also, instanceof check
|
---|
808 | * will not work. Instead test $$typeof field against Symbol.for('react.element') to check
|
---|
809 | * if something is a React Element.
|
---|
810 | *
|
---|
811 | * @param {*} type
|
---|
812 | * @param {*} props
|
---|
813 | * @param {*} key
|
---|
814 | * @param {string|object} ref
|
---|
815 | * @param {*} owner
|
---|
816 | * @param {*} self A *temporary* helper to detect places where `this` is
|
---|
817 | * different from the `owner` when React.createElement is called, so that we
|
---|
818 | * can warn. We want to get rid of owner and replace string `ref`s with arrow
|
---|
819 | * functions, and as long as `this` and owner are the same, there will be no
|
---|
820 | * change in behavior.
|
---|
821 | * @param {*} source An annotation object (added by a transpiler or otherwise)
|
---|
822 | * indicating filename, line number, and/or other information.
|
---|
823 | * @internal
|
---|
824 | */
|
---|
825 |
|
---|
826 |
|
---|
827 | var ReactElement = function (type, key, ref, self, source, owner, props) {
|
---|
828 | var element = {
|
---|
829 | // This tag allows us to uniquely identify this as a React Element
|
---|
830 | $$typeof: REACT_ELEMENT_TYPE,
|
---|
831 | // Built-in properties that belong on the element
|
---|
832 | type: type,
|
---|
833 | key: key,
|
---|
834 | ref: ref,
|
---|
835 | props: props,
|
---|
836 | // Record the component responsible for creating this element.
|
---|
837 | _owner: owner
|
---|
838 | };
|
---|
839 |
|
---|
840 | {
|
---|
841 | // The validation flag is currently mutative. We put it on
|
---|
842 | // an external backing store so that we can freeze the whole object.
|
---|
843 | // This can be replaced with a WeakMap once they are implemented in
|
---|
844 | // commonly used development environments.
|
---|
845 | element._store = {}; // To make comparing ReactElements easier for testing purposes, we make
|
---|
846 | // the validation flag non-enumerable (where possible, which should
|
---|
847 | // include every environment we run tests in), so the test framework
|
---|
848 | // ignores it.
|
---|
849 |
|
---|
850 | Object.defineProperty(element._store, 'validated', {
|
---|
851 | configurable: false,
|
---|
852 | enumerable: false,
|
---|
853 | writable: true,
|
---|
854 | value: false
|
---|
855 | }); // self and source are DEV only properties.
|
---|
856 |
|
---|
857 | Object.defineProperty(element, '_self', {
|
---|
858 | configurable: false,
|
---|
859 | enumerable: false,
|
---|
860 | writable: false,
|
---|
861 | value: self
|
---|
862 | }); // Two elements created in two different places should be considered
|
---|
863 | // equal for testing purposes and therefore we hide it from enumeration.
|
---|
864 |
|
---|
865 | Object.defineProperty(element, '_source', {
|
---|
866 | configurable: false,
|
---|
867 | enumerable: false,
|
---|
868 | writable: false,
|
---|
869 | value: source
|
---|
870 | });
|
---|
871 |
|
---|
872 | if (Object.freeze) {
|
---|
873 | Object.freeze(element.props);
|
---|
874 | Object.freeze(element);
|
---|
875 | }
|
---|
876 | }
|
---|
877 |
|
---|
878 | return element;
|
---|
879 | };
|
---|
880 | /**
|
---|
881 | * https://github.com/reactjs/rfcs/pull/107
|
---|
882 | * @param {*} type
|
---|
883 | * @param {object} props
|
---|
884 | * @param {string} key
|
---|
885 | */
|
---|
886 |
|
---|
887 | function jsxDEV(type, config, maybeKey, source, self) {
|
---|
888 | {
|
---|
889 | var propName; // Reserved names are extracted
|
---|
890 |
|
---|
891 | var props = {};
|
---|
892 | var key = null;
|
---|
893 | var ref = null; // Currently, key can be spread in as a prop. This causes a potential
|
---|
894 | // issue if key is also explicitly declared (ie. <div {...props} key="Hi" />
|
---|
895 | // or <div key="Hi" {...props} /> ). We want to deprecate key spread,
|
---|
896 | // but as an intermediary step, we will use jsxDEV for everything except
|
---|
897 | // <div {...props} key="Hi" />, because we aren't currently able to tell if
|
---|
898 | // key is explicitly declared to be undefined or not.
|
---|
899 |
|
---|
900 | if (maybeKey !== undefined) {
|
---|
901 | {
|
---|
902 | checkKeyStringCoercion(maybeKey);
|
---|
903 | }
|
---|
904 |
|
---|
905 | key = '' + maybeKey;
|
---|
906 | }
|
---|
907 |
|
---|
908 | if (hasValidKey(config)) {
|
---|
909 | {
|
---|
910 | checkKeyStringCoercion(config.key);
|
---|
911 | }
|
---|
912 |
|
---|
913 | key = '' + config.key;
|
---|
914 | }
|
---|
915 |
|
---|
916 | if (hasValidRef(config)) {
|
---|
917 | ref = config.ref;
|
---|
918 | warnIfStringRefCannotBeAutoConverted(config, self);
|
---|
919 | } // Remaining properties are added to a new props object
|
---|
920 |
|
---|
921 |
|
---|
922 | for (propName in config) {
|
---|
923 | if (hasOwnProperty.call(config, propName) && !RESERVED_PROPS.hasOwnProperty(propName)) {
|
---|
924 | props[propName] = config[propName];
|
---|
925 | }
|
---|
926 | } // Resolve default props
|
---|
927 |
|
---|
928 |
|
---|
929 | if (type && type.defaultProps) {
|
---|
930 | var defaultProps = type.defaultProps;
|
---|
931 |
|
---|
932 | for (propName in defaultProps) {
|
---|
933 | if (props[propName] === undefined) {
|
---|
934 | props[propName] = defaultProps[propName];
|
---|
935 | }
|
---|
936 | }
|
---|
937 | }
|
---|
938 |
|
---|
939 | if (key || ref) {
|
---|
940 | var displayName = typeof type === 'function' ? type.displayName || type.name || 'Unknown' : type;
|
---|
941 |
|
---|
942 | if (key) {
|
---|
943 | defineKeyPropWarningGetter(props, displayName);
|
---|
944 | }
|
---|
945 |
|
---|
946 | if (ref) {
|
---|
947 | defineRefPropWarningGetter(props, displayName);
|
---|
948 | }
|
---|
949 | }
|
---|
950 |
|
---|
951 | return ReactElement(type, key, ref, self, source, ReactCurrentOwner.current, props);
|
---|
952 | }
|
---|
953 | }
|
---|
954 |
|
---|
955 | var ReactCurrentOwner$1 = ReactSharedInternals.ReactCurrentOwner;
|
---|
956 | var ReactDebugCurrentFrame$1 = ReactSharedInternals.ReactDebugCurrentFrame;
|
---|
957 |
|
---|
958 | function setCurrentlyValidatingElement$1(element) {
|
---|
959 | {
|
---|
960 | if (element) {
|
---|
961 | var owner = element._owner;
|
---|
962 | var stack = describeUnknownElementTypeFrameInDEV(element.type, element._source, owner ? owner.type : null);
|
---|
963 | ReactDebugCurrentFrame$1.setExtraStackFrame(stack);
|
---|
964 | } else {
|
---|
965 | ReactDebugCurrentFrame$1.setExtraStackFrame(null);
|
---|
966 | }
|
---|
967 | }
|
---|
968 | }
|
---|
969 |
|
---|
970 | var propTypesMisspellWarningShown;
|
---|
971 |
|
---|
972 | {
|
---|
973 | propTypesMisspellWarningShown = false;
|
---|
974 | }
|
---|
975 | /**
|
---|
976 | * Verifies the object is a ReactElement.
|
---|
977 | * See https://reactjs.org/docs/react-api.html#isvalidelement
|
---|
978 | * @param {?object} object
|
---|
979 | * @return {boolean} True if `object` is a ReactElement.
|
---|
980 | * @final
|
---|
981 | */
|
---|
982 |
|
---|
983 |
|
---|
984 | function isValidElement(object) {
|
---|
985 | {
|
---|
986 | return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
|
---|
987 | }
|
---|
988 | }
|
---|
989 |
|
---|
990 | function getDeclarationErrorAddendum() {
|
---|
991 | {
|
---|
992 | if (ReactCurrentOwner$1.current) {
|
---|
993 | var name = getComponentNameFromType(ReactCurrentOwner$1.current.type);
|
---|
994 |
|
---|
995 | if (name) {
|
---|
996 | return '\n\nCheck the render method of `' + name + '`.';
|
---|
997 | }
|
---|
998 | }
|
---|
999 |
|
---|
1000 | return '';
|
---|
1001 | }
|
---|
1002 | }
|
---|
1003 |
|
---|
1004 | function getSourceInfoErrorAddendum(source) {
|
---|
1005 | {
|
---|
1006 | if (source !== undefined) {
|
---|
1007 | var fileName = source.fileName.replace(/^.*[\\\/]/, '');
|
---|
1008 | var lineNumber = source.lineNumber;
|
---|
1009 | return '\n\nCheck your code at ' + fileName + ':' + lineNumber + '.';
|
---|
1010 | }
|
---|
1011 |
|
---|
1012 | return '';
|
---|
1013 | }
|
---|
1014 | }
|
---|
1015 | /**
|
---|
1016 | * Warn if there's no key explicitly set on dynamic arrays of children or
|
---|
1017 | * object keys are not valid. This allows us to keep track of children between
|
---|
1018 | * updates.
|
---|
1019 | */
|
---|
1020 |
|
---|
1021 |
|
---|
1022 | var ownerHasKeyUseWarning = {};
|
---|
1023 |
|
---|
1024 | function getCurrentComponentErrorInfo(parentType) {
|
---|
1025 | {
|
---|
1026 | var info = getDeclarationErrorAddendum();
|
---|
1027 |
|
---|
1028 | if (!info) {
|
---|
1029 | var parentName = typeof parentType === 'string' ? parentType : parentType.displayName || parentType.name;
|
---|
1030 |
|
---|
1031 | if (parentName) {
|
---|
1032 | info = "\n\nCheck the top-level render call using <" + parentName + ">.";
|
---|
1033 | }
|
---|
1034 | }
|
---|
1035 |
|
---|
1036 | return info;
|
---|
1037 | }
|
---|
1038 | }
|
---|
1039 | /**
|
---|
1040 | * Warn if the element doesn't have an explicit key assigned to it.
|
---|
1041 | * This element is in an array. The array could grow and shrink or be
|
---|
1042 | * reordered. All children that haven't already been validated are required to
|
---|
1043 | * have a "key" property assigned to it. Error statuses are cached so a warning
|
---|
1044 | * will only be shown once.
|
---|
1045 | *
|
---|
1046 | * @internal
|
---|
1047 | * @param {ReactElement} element Element that requires a key.
|
---|
1048 | * @param {*} parentType element's parent's type.
|
---|
1049 | */
|
---|
1050 |
|
---|
1051 |
|
---|
1052 | function validateExplicitKey(element, parentType) {
|
---|
1053 | {
|
---|
1054 | if (!element._store || element._store.validated || element.key != null) {
|
---|
1055 | return;
|
---|
1056 | }
|
---|
1057 |
|
---|
1058 | element._store.validated = true;
|
---|
1059 | var currentComponentErrorInfo = getCurrentComponentErrorInfo(parentType);
|
---|
1060 |
|
---|
1061 | if (ownerHasKeyUseWarning[currentComponentErrorInfo]) {
|
---|
1062 | return;
|
---|
1063 | }
|
---|
1064 |
|
---|
1065 | ownerHasKeyUseWarning[currentComponentErrorInfo] = true; // Usually the current owner is the offender, but if it accepts children as a
|
---|
1066 | // property, it may be the creator of the child that's responsible for
|
---|
1067 | // assigning it a key.
|
---|
1068 |
|
---|
1069 | var childOwner = '';
|
---|
1070 |
|
---|
1071 | if (element && element._owner && element._owner !== ReactCurrentOwner$1.current) {
|
---|
1072 | // Give the component that originally created this child.
|
---|
1073 | childOwner = " It was passed a child from " + getComponentNameFromType(element._owner.type) + ".";
|
---|
1074 | }
|
---|
1075 |
|
---|
1076 | setCurrentlyValidatingElement$1(element);
|
---|
1077 |
|
---|
1078 | error('Each child in a list should have a unique "key" prop.' + '%s%s See https://reactjs.org/link/warning-keys for more information.', currentComponentErrorInfo, childOwner);
|
---|
1079 |
|
---|
1080 | setCurrentlyValidatingElement$1(null);
|
---|
1081 | }
|
---|
1082 | }
|
---|
1083 | /**
|
---|
1084 | * Ensure that every element either is passed in a static location, in an
|
---|
1085 | * array with an explicit keys property defined, or in an object literal
|
---|
1086 | * with valid key property.
|
---|
1087 | *
|
---|
1088 | * @internal
|
---|
1089 | * @param {ReactNode} node Statically passed child of any type.
|
---|
1090 | * @param {*} parentType node's parent's type.
|
---|
1091 | */
|
---|
1092 |
|
---|
1093 |
|
---|
1094 | function validateChildKeys(node, parentType) {
|
---|
1095 | {
|
---|
1096 | if (typeof node !== 'object') {
|
---|
1097 | return;
|
---|
1098 | }
|
---|
1099 |
|
---|
1100 | if (isArray(node)) {
|
---|
1101 | for (var i = 0; i < node.length; i++) {
|
---|
1102 | var child = node[i];
|
---|
1103 |
|
---|
1104 | if (isValidElement(child)) {
|
---|
1105 | validateExplicitKey(child, parentType);
|
---|
1106 | }
|
---|
1107 | }
|
---|
1108 | } else if (isValidElement(node)) {
|
---|
1109 | // This element was passed in a valid location.
|
---|
1110 | if (node._store) {
|
---|
1111 | node._store.validated = true;
|
---|
1112 | }
|
---|
1113 | } else if (node) {
|
---|
1114 | var iteratorFn = getIteratorFn(node);
|
---|
1115 |
|
---|
1116 | if (typeof iteratorFn === 'function') {
|
---|
1117 | // Entry iterators used to provide implicit keys,
|
---|
1118 | // but now we print a separate warning for them later.
|
---|
1119 | if (iteratorFn !== node.entries) {
|
---|
1120 | var iterator = iteratorFn.call(node);
|
---|
1121 | var step;
|
---|
1122 |
|
---|
1123 | while (!(step = iterator.next()).done) {
|
---|
1124 | if (isValidElement(step.value)) {
|
---|
1125 | validateExplicitKey(step.value, parentType);
|
---|
1126 | }
|
---|
1127 | }
|
---|
1128 | }
|
---|
1129 | }
|
---|
1130 | }
|
---|
1131 | }
|
---|
1132 | }
|
---|
1133 | /**
|
---|
1134 | * Given an element, validate that its props follow the propTypes definition,
|
---|
1135 | * provided by the type.
|
---|
1136 | *
|
---|
1137 | * @param {ReactElement} element
|
---|
1138 | */
|
---|
1139 |
|
---|
1140 |
|
---|
1141 | function validatePropTypes(element) {
|
---|
1142 | {
|
---|
1143 | var type = element.type;
|
---|
1144 |
|
---|
1145 | if (type === null || type === undefined || typeof type === 'string') {
|
---|
1146 | return;
|
---|
1147 | }
|
---|
1148 |
|
---|
1149 | var propTypes;
|
---|
1150 |
|
---|
1151 | if (typeof type === 'function') {
|
---|
1152 | propTypes = type.propTypes;
|
---|
1153 | } else if (typeof type === 'object' && (type.$$typeof === REACT_FORWARD_REF_TYPE || // Note: Memo only checks outer props here.
|
---|
1154 | // Inner props are checked in the reconciler.
|
---|
1155 | type.$$typeof === REACT_MEMO_TYPE)) {
|
---|
1156 | propTypes = type.propTypes;
|
---|
1157 | } else {
|
---|
1158 | return;
|
---|
1159 | }
|
---|
1160 |
|
---|
1161 | if (propTypes) {
|
---|
1162 | // Intentionally inside to avoid triggering lazy initializers:
|
---|
1163 | var name = getComponentNameFromType(type);
|
---|
1164 | checkPropTypes(propTypes, element.props, 'prop', name, element);
|
---|
1165 | } else if (type.PropTypes !== undefined && !propTypesMisspellWarningShown) {
|
---|
1166 | propTypesMisspellWarningShown = true; // Intentionally inside to avoid triggering lazy initializers:
|
---|
1167 |
|
---|
1168 | var _name = getComponentNameFromType(type);
|
---|
1169 |
|
---|
1170 | error('Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?', _name || 'Unknown');
|
---|
1171 | }
|
---|
1172 |
|
---|
1173 | if (typeof type.getDefaultProps === 'function' && !type.getDefaultProps.isReactClassApproved) {
|
---|
1174 | error('getDefaultProps is only used on classic React.createClass ' + 'definitions. Use a static property named `defaultProps` instead.');
|
---|
1175 | }
|
---|
1176 | }
|
---|
1177 | }
|
---|
1178 | /**
|
---|
1179 | * Given a fragment, validate that it can only be provided with fragment props
|
---|
1180 | * @param {ReactElement} fragment
|
---|
1181 | */
|
---|
1182 |
|
---|
1183 |
|
---|
1184 | function validateFragmentProps(fragment) {
|
---|
1185 | {
|
---|
1186 | var keys = Object.keys(fragment.props);
|
---|
1187 |
|
---|
1188 | for (var i = 0; i < keys.length; i++) {
|
---|
1189 | var key = keys[i];
|
---|
1190 |
|
---|
1191 | if (key !== 'children' && key !== 'key') {
|
---|
1192 | setCurrentlyValidatingElement$1(fragment);
|
---|
1193 |
|
---|
1194 | error('Invalid prop `%s` supplied to `React.Fragment`. ' + 'React.Fragment can only have `key` and `children` props.', key);
|
---|
1195 |
|
---|
1196 | setCurrentlyValidatingElement$1(null);
|
---|
1197 | break;
|
---|
1198 | }
|
---|
1199 | }
|
---|
1200 |
|
---|
1201 | if (fragment.ref !== null) {
|
---|
1202 | setCurrentlyValidatingElement$1(fragment);
|
---|
1203 |
|
---|
1204 | error('Invalid attribute `ref` supplied to `React.Fragment`.');
|
---|
1205 |
|
---|
1206 | setCurrentlyValidatingElement$1(null);
|
---|
1207 | }
|
---|
1208 | }
|
---|
1209 | }
|
---|
1210 |
|
---|
1211 | var didWarnAboutKeySpread = {};
|
---|
1212 | function jsxWithValidation(type, props, key, isStaticChildren, source, self) {
|
---|
1213 | {
|
---|
1214 | var validType = isValidElementType(type); // We warn in this case but don't throw. We expect the element creation to
|
---|
1215 | // succeed and there will likely be errors in render.
|
---|
1216 |
|
---|
1217 | if (!validType) {
|
---|
1218 | var info = '';
|
---|
1219 |
|
---|
1220 | if (type === undefined || typeof type === 'object' && type !== null && Object.keys(type).length === 0) {
|
---|
1221 | info += ' You likely forgot to export your component from the file ' + "it's defined in, or you might have mixed up default and named imports.";
|
---|
1222 | }
|
---|
1223 |
|
---|
1224 | var sourceInfo = getSourceInfoErrorAddendum(source);
|
---|
1225 |
|
---|
1226 | if (sourceInfo) {
|
---|
1227 | info += sourceInfo;
|
---|
1228 | } else {
|
---|
1229 | info += getDeclarationErrorAddendum();
|
---|
1230 | }
|
---|
1231 |
|
---|
1232 | var typeString;
|
---|
1233 |
|
---|
1234 | if (type === null) {
|
---|
1235 | typeString = 'null';
|
---|
1236 | } else if (isArray(type)) {
|
---|
1237 | typeString = 'array';
|
---|
1238 | } else if (type !== undefined && type.$$typeof === REACT_ELEMENT_TYPE) {
|
---|
1239 | typeString = "<" + (getComponentNameFromType(type.type) || 'Unknown') + " />";
|
---|
1240 | info = ' Did you accidentally export a JSX literal instead of a component?';
|
---|
1241 | } else {
|
---|
1242 | typeString = typeof type;
|
---|
1243 | }
|
---|
1244 |
|
---|
1245 | error('React.jsx: type is invalid -- expected a string (for ' + 'built-in components) or a class/function (for composite ' + 'components) but got: %s.%s', typeString, info);
|
---|
1246 | }
|
---|
1247 |
|
---|
1248 | var element = jsxDEV(type, props, key, source, self); // The result can be nullish if a mock or a custom function is used.
|
---|
1249 | // TODO: Drop this when these are no longer allowed as the type argument.
|
---|
1250 |
|
---|
1251 | if (element == null) {
|
---|
1252 | return element;
|
---|
1253 | } // Skip key warning if the type isn't valid since our key validation logic
|
---|
1254 | // doesn't expect a non-string/function type and can throw confusing errors.
|
---|
1255 | // We don't want exception behavior to differ between dev and prod.
|
---|
1256 | // (Rendering will throw with a helpful message and as soon as the type is
|
---|
1257 | // fixed, the key warnings will appear.)
|
---|
1258 |
|
---|
1259 |
|
---|
1260 | if (validType) {
|
---|
1261 | var children = props.children;
|
---|
1262 |
|
---|
1263 | if (children !== undefined) {
|
---|
1264 | if (isStaticChildren) {
|
---|
1265 | if (isArray(children)) {
|
---|
1266 | for (var i = 0; i < children.length; i++) {
|
---|
1267 | validateChildKeys(children[i], type);
|
---|
1268 | }
|
---|
1269 |
|
---|
1270 | if (Object.freeze) {
|
---|
1271 | Object.freeze(children);
|
---|
1272 | }
|
---|
1273 | } else {
|
---|
1274 | error('React.jsx: Static children should always be an array. ' + 'You are likely explicitly calling React.jsxs or React.jsxDEV. ' + 'Use the Babel transform instead.');
|
---|
1275 | }
|
---|
1276 | } else {
|
---|
1277 | validateChildKeys(children, type);
|
---|
1278 | }
|
---|
1279 | }
|
---|
1280 | }
|
---|
1281 |
|
---|
1282 | {
|
---|
1283 | if (hasOwnProperty.call(props, 'key')) {
|
---|
1284 | var componentName = getComponentNameFromType(type);
|
---|
1285 | var keys = Object.keys(props).filter(function (k) {
|
---|
1286 | return k !== 'key';
|
---|
1287 | });
|
---|
1288 | var beforeExample = keys.length > 0 ? '{key: someKey, ' + keys.join(': ..., ') + ': ...}' : '{key: someKey}';
|
---|
1289 |
|
---|
1290 | if (!didWarnAboutKeySpread[componentName + beforeExample]) {
|
---|
1291 | var afterExample = keys.length > 0 ? '{' + keys.join(': ..., ') + ': ...}' : '{}';
|
---|
1292 |
|
---|
1293 | error('A props object containing a "key" prop is being spread into JSX:\n' + ' let props = %s;\n' + ' <%s {...props} />\n' + 'React keys must be passed directly to JSX without using spread:\n' + ' let props = %s;\n' + ' <%s key={someKey} {...props} />', beforeExample, componentName, afterExample, componentName);
|
---|
1294 |
|
---|
1295 | didWarnAboutKeySpread[componentName + beforeExample] = true;
|
---|
1296 | }
|
---|
1297 | }
|
---|
1298 | }
|
---|
1299 |
|
---|
1300 | if (type === REACT_FRAGMENT_TYPE) {
|
---|
1301 | validateFragmentProps(element);
|
---|
1302 | } else {
|
---|
1303 | validatePropTypes(element);
|
---|
1304 | }
|
---|
1305 |
|
---|
1306 | return element;
|
---|
1307 | }
|
---|
1308 | } // These two functions exist to still get child warnings in dev
|
---|
1309 |
|
---|
1310 | var jsxDEV$1 = jsxWithValidation ;
|
---|
1311 |
|
---|
1312 | exports.Fragment = REACT_FRAGMENT_TYPE;
|
---|
1313 | exports.jsxDEV = jsxDEV$1;
|
---|
1314 | })();
|
---|
1315 | }
|
---|