in src/handlers/flowTypeHandler.ts [16:97]
function setPropDescriptor(
documentation: Documentation,
path: NodePath,
typeParams: TypeParameters | null,
importer: Importer,
): void {
if (t.ObjectTypeSpreadProperty.check(path.node)) {
const argument = unwrapUtilityType(path.get('argument'));
if (t.ObjectTypeAnnotation.check(argument.node)) {
applyToFlowTypeProperties(
documentation,
argument,
(propertyPath, innerTypeParams) => {
setPropDescriptor(
documentation,
propertyPath,
innerTypeParams,
importer,
);
},
typeParams,
importer,
);
return;
}
const name = argument.get('id').get('name');
const resolvedPath = resolveToValue(
name,
// TODO: Make this configurable with a pragma comment?
importer,
);
if (resolvedPath && t.TypeAlias.check(resolvedPath.node)) {
const right = resolvedPath.get('right');
applyToFlowTypeProperties(
documentation,
right,
(propertyPath, innerTypeParams) => {
setPropDescriptor(
documentation,
propertyPath,
innerTypeParams,
importer,
);
},
typeParams,
importer,
);
} else if (!argument.node.typeParameters) {
documentation.addComposes(name.node.name);
}
} else if (t.ObjectTypeProperty.check(path.node)) {
const type = getFlowType(path.get('value'), typeParams, importer);
const propName = getPropertyName(path, importer);
if (!propName) return;
const propDescriptor = documentation.getPropDescriptor(propName);
propDescriptor.required = !path.node.optional;
propDescriptor.flowType = type;
// We are doing this here instead of in a different handler
// to not need to duplicate the logic for checking for
// imported types that are spread in to props.
setPropDescription(documentation, path, importer);
} else if (t.TSPropertySignature.check(path.node)) {
const type = getTSType(path.get('typeAnnotation'), typeParams, importer);
const propName = getPropertyName(path, importer);
if (!propName) return;
const propDescriptor = documentation.getPropDescriptor(propName);
propDescriptor.required = !path.node.optional;
propDescriptor.tsType = type;
// We are doing this here instead of in a different handler
// to not need to duplicate the logic for checking for
// imported types that are spread in to props.
setPropDescription(documentation, path, importer);
}
}