Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tag.type problems #17

Open
tunnckoCore opened this issue Jan 18, 2020 · 0 comments
Open

tag.type problems #17

tunnckoCore opened this issue Jan 18, 2020 · 0 comments

Comments

@tunnckoCore
Copy link

tunnckoCore commented Jan 18, 2020

First, it would be cool if in the tag object there is also the whole non-parsed string of the types.

Second, the example case

/**
 * @param {Array<string>|string} options.include - glob patterns
 * @param {string|boolean} options.exclude - ignore patterns
 * @param {Function} options.hook - a hook function passed with [Context](#context)
 * @param {boolean} options.always - a boolean that makes `options.hook` to always be called
 * @param {Function} options.glob - a globbing library like [glob][], [fast-glob][], [tiny-glob][], defaults to `fast-glob`
 * @param {object} options.globOptions
 * @param {string[]} options.cacheLocation
 */

I always felt there's something wrong. Finally dug down and found it.

{ type: 'NameExpression', name: 'string' }
{
  type: 'UnionType',
  elements: [
    { type: 'NameExpression', name: 'string' },
    { type: 'NameExpression', name: 'boolean' }
  ]
}
{ type: 'NameExpression', name: 'Function' }
{ type: 'NameExpression', name: 'boolean' }
{ type: 'NameExpression', name: 'Function' }
{ type: 'NameExpression', name: 'object' }
{
  type: 'TypeApplication',
  expression: { type: 'NameExpression', name: 'Array' },
  applications: [ { type: 'NameExpression', name: 'string' } ]
}
{ type: 'NameExpression', name: 'Promise' }

as you can see, the first one is just NameExpression, which means it only gets the last of the type definition. If you reverse it from {Array<string>|string} to {string|Array<string>} the first result will be TypeApplication.

{
  type: 'TypeApplication',
  expression: { type: 'NameExpression', name: 'Array' },
  applications: [ { type: 'NameExpression', name: 'string' } ]
}

In short, the problem only when there is a TypeApplication type in a UnionType, because this works {string|boolean} okay.

I believe that the expected result should be

{
  type: 'UnionType',
  elements: [
    { type: 'NameExpression', name: 'string' },
    {
      type: 'TypeApplication',
      expression: { type: 'NameExpression', name: 'Array' },
      applications: [ { type: 'NameExpression', name: 'string' } ]
    }
  ]
}

@jonschlinkert seems like I continue to stack up more and more issues 😆 🙉 ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant