Skip to content

Commit

Permalink
fix: allow for braces within type declarations (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe authored Nov 10, 2021
1 parent 176a494 commit a750cae
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/loader/babel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ export default <PluginItem> function babelPluginUntyped (api: ConfigAPI) {
// Extract and apply any manual types
schema.tags = schema.tags?.filter((tag) => {
if (tag.startsWith('@returns')) {
const { type } = tag.match(/^@returns\s+\{(?<type>[^}]+)\}/)?.groups || {}
const { type } = tag.match(/^@returns\s+\{(?<type>.+)\}/)?.groups || {}
if (type) {
schema.returns = schema.returns || {}
Object.assign(schema.returns, getTypeDescriptor(type))
return false
}
}
if (tag.startsWith('@param')) {
const { type, param } = tag.match(/^@param\s+\{(?<type>[^}]+)\}\s+(?<param>\w+)/)?.groups || {}
const { type, param } = tag.match(/^@param\s+\{(?<type>.+)\}\s+(?<param>\w+)/)?.groups || {}
if (type && param) {
const arg = schema.args?.find(arg => arg.name === param)
if (arg) {
Expand Down Expand Up @@ -188,12 +188,12 @@ function parseJSDocs (input: string | string[]): Schema {
const tags = clumpLines(lines.slice(firstTag), ['@'], '\n')
for (const tag of tags) {
if (tag.startsWith('@type')) {
const type = tag.match(/@type\s+\{([^}]+)\}/)?.[1]
const type = tag.match(/@type\s+\{(.+)\}/)?.[1]
Object.assign(schema, getTypeDescriptor(type))
const typedef = tags.find(t => t.match(/@typedef\s+\{([^}]+)\} (.*)/)?.[2] === type)
const typedef = tags.find(t => t.match(/@typedef\s+\{(.+)\} (.*)/)?.[2] === type)
if (typedef) {
schema.markdownType = type
schema.tsType = typedef.match(/@typedef\s+\{([^}]+)\}/)?.[1]
schema.tsType = typedef.match(/@typedef\s+\{(.+)\}/)?.[1]
}
continue
}
Expand Down

0 comments on commit a750cae

Please sign in to comment.