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

Wrong CST d.ts type generation with same label for different alternatives #1745

Closed
medihack opened this issue Jan 22, 2022 · 2 comments · Fixed by #1746
Closed

Wrong CST d.ts type generation with same label for different alternatives #1745

medihack opened this issue Jan 22, 2022 · 2 comments · Fixed by #1746

Comments

@medihack
Copy link
Contributor

medihack commented Jan 22, 2022

I am generating my types for the CST visitor with generateCstDts. This works fine, but not for this rule:

  public content = this.RULE("content", () => {
    this.MANY(() => {
      this.OR([
        {
          ALT: () => {
            this.SUBRULE(this.element, { LABEL: "items" })
          },
        },
        {
          ALT: () => {
            this.SUBRULE(this.chardata, { LABEL: "items" })
          },
        },
        {
          ALT: () => {
            this.SUBRULE(this.expression, { LABEL: "items" })
          },
        },
      ])
    })
  })

I end up with a generated type like this:

export type ContentCstChildren = {
  items?: ElementCstNode[];
};

but expected something like this:

export type ContentCstChildren = {
  items?: Array<ElementCstNode | ChardataCstNode | ExpressionCstNode>
@medihack medihack changed the title generateCstDts fails with Alternation inside Repetition Wrong type generation of generateCstDts with Alternation inside Repetition Jan 22, 2022
@medihack medihack changed the title Wrong type generation of generateCstDts with Alternation inside Repetition Wrong type generation of generateCstDts with Alternation inside Repetition with LABEL Jan 22, 2022
@medihack
Copy link
Contributor Author

Ok, just took a look at the generator code and it seems to be quite tricky to make it work with LABEL correctly.

By the way, there is a little bug in the update-snapshots on line 14. It must be const result = api.generateCstDts(parser.getGAstProductions()).

@bd82
Copy link
Member

bd82 commented Jan 31, 2022

I merged your fixed, it seems quite clean 👍

@bd82 bd82 changed the title Wrong type generation of generateCstDts with Alternation inside Repetition with LABEL Wrong CST d.ts type generation with same label for different alternatives Feb 14, 2022
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 a pull request may close this issue.

2 participants