| 725 | }; |
| 726 | |
| 727 | const propTypeToFlowAnnotation = val => { |
| 728 | let cursor = val; |
| 729 | let isOptional = true; |
| 730 | let typeResult = flowFixMeType; |
| 731 | |
| 732 | if ( // check `.isRequired` first |
| 733 | cursor.type === 'MemberExpression' && |
| 734 | cursor.property.type === 'Identifier' && |
| 735 | cursor.property.name === 'isRequired' |
| 736 | ) { |
| 737 | isOptional = false; |
| 738 | cursor = cursor.object; |
| 739 | } |
| 740 | |
| 741 | switch (cursor.type) { |
| 742 | case 'CallExpression': { // type class |
| 743 | const calleeName = cursor.callee.type === 'MemberExpression' ? |
| 744 | cursor.callee.property.name : |
| 745 | cursor.callee.name; |
| 746 | |
| 747 | const constructor = propTypeToFlowMapping[calleeName]; |
| 748 | if (!constructor) { // unknown type class |
| 749 | // it's not necessary since `typeResult` defaults to `flowFixMeType`, |
| 750 | // but it's more explicit this way |
| 751 | typeResult = flowFixMeType; |
| 752 | break; |
| 753 | } |
| 754 | |
| 755 | switch (cursor.callee.property.name) { |
| 756 | case 'arrayOf': { |
| 757 | const arg = cursor.arguments[0]; |
| 758 | typeResult = constructor( |
| 759 | propTypeToFlowAnnotation(arg)[0] |
| 760 | ); |
| 761 | break; |
| 762 | } |
| 763 | case 'instanceOf': { |
| 764 | const arg = cursor.arguments[0]; |
| 765 | if (arg.type !== 'Identifier') { |
| 766 | typeResult = flowFixMeType; |
| 767 | break; |
| 768 | } |
| 769 | |
| 770 | typeResult = constructor(arg); |
| 771 | break; |
| 772 | } |
| 773 | case 'objectOf': { |
| 774 | const arg = cursor.arguments[0]; |
| 775 | typeResult = constructor( |
| 776 | propTypeToFlowAnnotation(arg)[0] |
| 777 | ); |
| 778 | break; |
| 779 | } |
| 780 | case 'oneOf': { |
| 781 | const argList = cursor.arguments[0].elements; |
| 782 | if ( |
| 783 | !argList || |
| 784 | !argList.every(node => |
no outgoing calls
no test coverage detected