(
name,
baseClassName,
staticProperties,
getInitialState,
rawProperties,
comments
)
| 935 | // 2. there's a direct method call `this.x()`, or |
| 936 | // 3. `this` is referenced alone |
| 937 | const createESClass = ( |
| 938 | name, |
| 939 | baseClassName, |
| 940 | staticProperties, |
| 941 | getInitialState, |
| 942 | rawProperties, |
| 943 | comments |
| 944 | ) => { |
| 945 | const initialStateProperty = []; |
| 946 | let maybeConstructor = []; |
| 947 | let maybeFlowStateAnnotation = []; // we only need this when we do `this.state = ...` |
| 948 | |
| 949 | if (isInitialStateLiftable(getInitialState)) { |
| 950 | if (getInitialState) { |
| 951 | initialStateProperty.push(convertInitialStateToClassProperty(getInitialState)); |
| 952 | } |
| 953 | } else { |
| 954 | maybeConstructor = createConstructor(getInitialState); |
| 955 | if (shouldTransformFlow) { |
| 956 | let stateType = j.typeAnnotation( |
| 957 | j.existsTypeAnnotation() |
| 958 | ); |
| 959 | |
| 960 | if (getInitialState.value.returnType) { |
| 961 | stateType = getInitialState.value.returnType; |
| 962 | } |
| 963 | |
| 964 | maybeFlowStateAnnotation.push(j.classProperty( |
| 965 | j.identifier('state'), |
| 966 | null, |
| 967 | stateType, |
| 968 | false |
| 969 | )); |
| 970 | } |
| 971 | } |
| 972 | |
| 973 | const propertiesAndMethods = rawProperties.map(prop => { |
| 974 | if (isPrimPropertyWithTypeAnnotation(prop)) { |
| 975 | return createClassPropertyWithType(prop); |
| 976 | } else if (isPrimProperty(prop)) { |
| 977 | return createClassProperty(prop); |
| 978 | } else if (AUTOBIND_IGNORE_KEYS.hasOwnProperty(prop.key.name)) { |
| 979 | return createMethodDefinition(prop); |
| 980 | } |
| 981 | |
| 982 | return createArrowProperty(prop); |
| 983 | }); |
| 984 | |
| 985 | const flowPropsAnnotation = shouldTransformFlow ? |
| 986 | createFlowAnnotationsFromPropTypesProperties( |
| 987 | staticProperties.find((path) => path.key.name === 'propTypes') |
| 988 | ) : |
| 989 | []; |
| 990 | |
| 991 | let finalStaticProperties = staticProperties; |
| 992 | |
| 993 | if (shouldTransformFlow && options['remove-runtime-proptypes']) { |
| 994 | finalStaticProperties = staticProperties.filter((prop) => prop.key.name !== 'propTypes'); |
no test coverage detected