function amendPropTypes()

in src/handlers/propTypeHandler.ts [23:71]


function amendPropTypes(
  getDescriptor: (propName: string) => PropDescriptor,
  path: NodePath,
  importer: Importer,
): void {
  if (!t.ObjectExpression.check(path.node)) {
    return;
  }

  path.get('properties').each((propertyPath: NodePath): void => {
    switch (propertyPath.node.type) {
      // @ts-ignore
      case t.Property.name: {
        const propName = getPropertyName(propertyPath, importer);
        if (!propName) return;

        const propDescriptor = getDescriptor(propName);
        const valuePath = resolveToValue(propertyPath.get('value'), importer);
        const type: PropTypeDescriptor = isPropTypesExpression(
          valuePath,
          importer,
        )
          ? getPropType(valuePath, importer)
          : { name: 'custom', raw: printValue(valuePath) };

        if (type) {
          propDescriptor.type = type;
          propDescriptor.required =
            type.name !== 'custom' && isRequiredPropType(valuePath);
        }
        break;
      }
      // @ts-ignore
      case t.SpreadElement.name: {
        const resolvedValuePath = resolveToValue(
          propertyPath.get('argument'),
          importer,
        );
        switch (resolvedValuePath.node.type) {
          // @ts-ignore
          case t.ObjectExpression.name: // normal object literal
            amendPropTypes(getDescriptor, resolvedValuePath, importer);
            break;
        }
        break;
      }
    }
  });
}