Skip to content

Implement TypeTuple#70

Open
kungfooman wants to merge 1 commit intohegemonic:mainfrom
kungfooman:TypeTuple
Open

Implement TypeTuple#70
kungfooman wants to merge 1 commit intohegemonic:mainfrom
kungfooman:TypeTuple

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.

1 participant