MCPcopy Index your code
hub / github.com/reactjs/react-codemod / createFlowAnnotationsFromPropTypesProperties

Function createFlowAnnotationsFromPropTypesProperties

transforms/class.js:859–888  ·  view source on GitHub ↗
(prop)

Source from the content-addressed store, hash-verified

857 };
858
859 const createFlowAnnotationsFromPropTypesProperties = (prop) => {
860 const typePropertyList = [];
861
862 if (!prop || prop.value.type !== 'ObjectExpression') {
863 return typePropertyList;
864 }
865
866 prop.value.properties.forEach(typeProp => {
867 if (!typeProp.key) { // stuff like SpreadProperty
868 return;
869 }
870
871 const keyIsLiteral = typeProp.key.type === 'Literal';
872 const name = keyIsLiteral ? typeProp.key.value : typeProp.key.name;
873
874 const [valueType, isOptional] = propTypeToFlowAnnotation(typeProp.value);
875 typePropertyList.push(j.objectTypeProperty(
876 keyIsLiteral ? j.literal(name) : j.identifier(name),
877 valueType,
878 isOptional
879 ));
880 });
881
882 return j.classProperty(
883 j.identifier('props'),
884 null,
885 j.typeAnnotation(j.objectTypeAnnotation(typePropertyList)),
886 false
887 );
888 };
889
890 // to ensure that our property initializers' evaluation order is safe
891 const repositionStateProperty = (initialStateProperty, propertiesAndMethods) => {

Callers 1

createESClassFunction · 0.85

Calls 1

propTypeToFlowAnnotationFunction · 0.85

Tested by

no test coverage detected