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

Implement TypeTuple #70

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

kungfooman
Copy link

@kungfooman kungfooman commented Aug 5, 2022

Hi @hegemonic,

I would like to see tuple support, which is requested since 2015 and 2017 you mentioned you are open for a PR: jsdoc/jsdoc#1073 (comment)

So this is the first step. As soon as catharsis returns a proper AST, JSDoc can correctly implement the documentation for it.

The AST naming is inspired by TypeScript:

Input 1:

const catharsis = require("./catharsis");
const ret = catharsis.parse("[a: string, b: number]", {jsdoc: true});
console.log(JSON.stringify(ret, null, 2));

Output 1:

{
  "type": "TypeTuple",
  "elements": [
    {
      "type": "NamedTupleMember",
      "key": "a",
      "value": {
        "type": "NameExpression",
        "name": "string"
      }
    },
    {
      "type": "NamedTupleMember",
      "key": "b",
      "value": {
        "type": "NameExpression",
        "name": "number"
      }
    }
  ]
}

Input 2:

const catharsis = require("./catharsis");
const ret = catharsis.parse("[action: string, id: 1|2|3]", {jsdoc: true});
console.log(JSON.stringify(ret, null, 2));

Output 2:

{
  "type": "TypeTuple",
  "elements": [
    {
      "type": "NamedTupleMember",
      "key": "action",
      "value": {
        "type": "NameExpression",
        "name": "string"
      }
    },
    {
      "type": "NamedTupleMember",
      "key": "id",
      "value": {
        "type": "TypeUnion",
        "elements": [
          {
            "type": "NameExpression",
            "name": "1"
          },
          {
            "type": "NameExpression",
            "name": "2"
          },
          {
            "type": "NameExpression",
            "name": "3"
          }
        ]
      }
    }
  ]
}

Input 3:

const catharsis = require("./catharsis");
const ret = catharsis.parse("[number, string, Date]", {jsdoc: true});
console.log(JSON.stringify(ret, null, 2));

Output 3:

{
  "type": "TypeTuple",
  "elements": [
    {
      "type": "NameExpression",
      "name": "number"
    },
    {
      "type": "NameExpression",
      "name": "string"
    },
    {
      "type": "NameExpression",
      "name": "Date"
    }
  ]
}

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

Successfully merging this pull request may close these issues.

None yet

1 participant