mirror of
https://github.com/documentationjs/documentation.git
synced 2026-01-18 14:17:30 +00:00
Given the `type` tag introduced with Flow, this can infer a typedef statement, as well as infer its potentially nested properties and their types. This also includes * Refactor of Markdown AST generation that fixes #228 * Refactor of nest.js to handle multi-level nesting
62 lines
1.1 KiB
JavaScript
62 lines
1.1 KiB
JavaScript
var namedTypes = {
|
|
'NumberTypeAnnotation': 'number',
|
|
'BooleanTypeAnnotation': 'boolean',
|
|
'ObjectTypeAnnotation': 'Object',
|
|
'StringTypeAnnotation': 'string'
|
|
};
|
|
|
|
var oneToOne = {
|
|
'AnyTypeAnnotation': {
|
|
type: 'AllLiteral'
|
|
}
|
|
};
|
|
|
|
function flowDoctrine(type) {
|
|
|
|
if (type.type in namedTypes) {
|
|
return {
|
|
type: 'NameExpression',
|
|
name: namedTypes[type.type]
|
|
};
|
|
}
|
|
|
|
if (type.type in oneToOne) {
|
|
return oneToOne[type.type];
|
|
}
|
|
|
|
if (type.type === 'NullableTypeAnnotation') {
|
|
return {
|
|
type: 'OptionalType',
|
|
expression: flowDoctrine(type.typeAnnotation)
|
|
};
|
|
}
|
|
|
|
if (type.type === 'UnionTypeAnnotation') {
|
|
return {
|
|
type: 'UnionType',
|
|
elements: type.types.map(flowDoctrine)
|
|
};
|
|
}
|
|
|
|
if (type.type === 'GenericTypeAnnotation') {
|
|
|
|
if (type.typeParameters) {
|
|
return {
|
|
type: 'TypeApplication',
|
|
expression: {
|
|
type: 'NameExpression',
|
|
name: type.id.name
|
|
},
|
|
applications: type.typeParameters.params.map(flowDoctrine)
|
|
};
|
|
}
|
|
|
|
return {
|
|
type: 'NameExpression',
|
|
name: type.id.name
|
|
};
|
|
}
|
|
}
|
|
|
|
module.exports = flowDoctrine;
|