(type: any)
| 657 | } |
| 658 | |
| 659 | export function isLikelyComponentType(type: any): boolean { |
| 660 | if (__DEV__) { |
| 661 | switch (typeof type) { |
| 662 | case 'function': { |
| 663 | // First, deal with classes. |
| 664 | if (type.prototype != null) { |
| 665 | if (type.prototype.isReactComponent) { |
| 666 | // React class. |
| 667 | return true; |
| 668 | } |
| 669 | const ownNames = Object.getOwnPropertyNames(type.prototype); |
| 670 | if (ownNames.length > 1 || ownNames[0] !== 'constructor') { |
| 671 | // This looks like a class. |
| 672 | return false; |
| 673 | } |
| 674 | if ( |
| 675 | // $FlowFixMe[prop-missing] |
| 676 | type.prototype.__proto__ !== Object.prototype // eslint-disable-line no-proto |
| 677 | ) { |
| 678 | // It has a superclass. |
| 679 | return false; |
| 680 | } |
| 681 | // Pass through. |
| 682 | // This looks like a regular function with empty prototype. |
| 683 | } |
| 684 | // For plain functions and arrows, use name as a heuristic. |
| 685 | const name = type.name || type.displayName; |
| 686 | return typeof name === 'string' && /^[A-Z]/.test(name); |
| 687 | } |
| 688 | case 'object': { |
| 689 | if (type != null) { |
| 690 | switch (getProperty(type, '$$typeof')) { |
| 691 | case REACT_FORWARD_REF_TYPE: |
| 692 | case REACT_MEMO_TYPE: |
| 693 | // Definitely React components. |
| 694 | return true; |
| 695 | default: |
| 696 | return false; |
| 697 | } |
| 698 | } |
| 699 | return false; |
| 700 | } |
| 701 | default: { |
| 702 | return false; |
| 703 | } |
| 704 | } |
| 705 | } else { |
| 706 | throw new Error( |
| 707 | 'Unexpected call to React Refresh in a production environment.', |
| 708 | ); |
| 709 | } |
| 710 | } |
nothing calls this directly
no test coverage detected