UNPKG

@typedefs/parser

Version:
41 lines (38 loc) 2.5 kB
import { lex, parser } from './lib' /** * The Parser For JSDoc Types. * @param {string} type The type to parse, e.g., `!Promise<!Array<function(string)>>` */ export default function parse(type) { const tokens = lex(type) return parser(tokens) } /* documentary types/index.xml */ /** * @suppress {nonStandardJsDocs} * @typedef {_typedefsParser.FunctionType} FunctionType `@record` The meta information about the function. */ /** * @suppress {nonStandardJsDocs} * @typedef {Object} _typedefsParser.FunctionType `@record` The meta information about the function. * @prop {!Array<!_typedefsParser.Type>} args The arguments of the function. * @prop {?_typedefsParser.Type} return The return type of the function. When the value is set to `null`, it means the function does not have a return. If the return was actually `null`, it would be specified as `return: { name: 'null' }`. * @prop {!_typedefsParser.Type} [this] The type of the `this` argument specified as `function(this: Type)`. * @prop {!_typedefsParser.Type} [new] The type of the `new` argument specified as `function(new: Type)`. * @prop {!_typedefsParser.Type} [variableArgs] The type of the variable arguments, e.g., `function(...Type)`. */ /** * @suppress {nonStandardJsDocs} * @typedef {_typedefsParser.Type} Type `@record` The representation of a type. */ /** * @suppress {nonStandardJsDocs} * @typedef {Object} _typedefsParser.Type `@record` The representation of a type. * @prop {boolean} [nullable] Whether the type is nullable. This is defined by writing `?` before the type name to state nullability and `!` otherwise. The parser does not infer nullability from types being primitive and `Function/function`. * @prop {string} [name] The name of the type. * @prop {!Array<!_typedefsParser.Type>} [union] If the type is defined as a union, e.g., `(string|number)`, contains the united types. Must include parenthesis. * @prop {!Object<string, _typedefsParser.Type>} [record] If the type is a record, contains its representation. If a property of the record does not have a type, it will be set to null. * @prop {!Array<!_typedefsParser.Type>} [application] The application of the type, e.g., the inner type of `Object<Application>`. * @prop {!_typedefsParser.FunctionType} [function] The function info with args and return if the type is a function. * @prop {boolean} [optional] If the type is returned as an optional argument of a function (`function(string=)`), this will be set to true. */