UNPKG

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