in src/utils/getFlowType.ts [367:409]
function getFlowTypeWithResolvedTypes(
path: NodePath,
typeParams: TypeParameters | null,
importer: Importer,
): TypeDescriptor {
const node = path.node;
let type: TypeDescriptor | null = null;
const isTypeAlias = t.TypeAlias.check(path.parentPath.node);
// When we see a typealias mark it as visited so that the next
// call of this function does not run into an endless loop
if (isTypeAlias) {
if (visitedTypes[path.parentPath.node.id.name] === true) {
// if we are currently visiting this node then just return the name
// as we are starting to endless loop
return { name: path.parentPath.node.id.name };
} else if (typeof visitedTypes[path.parentPath.node.id.name] === 'object') {
// if we already resolved the type simple return it
return visitedTypes[path.parentPath.node.id.name];
}
// mark the type as visited
visitedTypes[path.parentPath.node.id.name] = true;
}
if (node.type in flowTypes) {
type = { name: flowTypes[node.type] };
} else if (node.type in flowLiteralTypes) {
type = { name: 'literal', value: node.raw || `${node.value}` };
} else if (node.type in namedTypes) {
type = namedTypes[node.type](path, typeParams, importer);
}
if (!type) {
type = { name: 'unknown' };
}
if (isTypeAlias) {
// mark the type as unvisited so that further calls can resolve the type again
visitedTypes[path.parentPath.node.id.name] = type;
}
return type;
}