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

Bug: decorators get duplicated in AST for parameter properties #5581

Closed
4 tasks done
fisker opened this issue Aug 31, 2022 · 1 comment · Fixed by #5582
Closed
4 tasks done

Bug: decorators get duplicated in AST for parameter properties #5581

fisker opened this issue Aug 31, 2022 · 1 comment · Fixed by #5582
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: typescript-estree Issues related to @typescript-eslint/typescript-estree

Comments

@fisker
Copy link
Contributor

fisker commented Aug 31, 2022

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Relevant Package

parser

Playground Link

https://typescript-eslint.io/play/#ts=4.8.2&sourceType=module&showAST=es&code=MYGwhgzhAECC0G9pgBQAEAm0AOAnAlgG5gAuAptAB4Bc0AdgK4C2ARmbgJSLQC+vQA&eslintrc=N4KABGBEBOCuA2BTAzpAXGYBfEWg&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA

Repro Code

> parse = require("@typescript-eslint/typescript-estree").parse
[Function: parse]
> ast = parse('class A {a (@d private x: number) {}}')
{
  type: 'Program',
  body: [
    {
      type: 'ClassDeclaration',
      id: [Object],
      body: [Object],
      superClass: null
    }
  ],
  sourceType: 'script'
}
> ast.body[0].body.body[0].value.params[0].decorators[0]
{ type: 'Decorator', expression: { type: 'Identifier', name: 'd' } }
> ast.body[0].body.body[0].value.params[0].parameter.decorators[0]
{ type: 'Decorator', expression: { type: 'Identifier', name: 'd' } }

ESLint Config

N/A

tsconfig

N/A

Expected Result

Not duplicate the decorator

Actual Result

the decorator get duplicate

Additional Info

No response

Versions

package version
@typescript-eslint/parser 5.36.1
node 18.8.0
@fisker fisker added bug Something isn't working triage Waiting for maintainers to take a look labels Aug 31, 2022
@bradzacher bradzacher added package: typescript-estree Issues related to @typescript-eslint/typescript-estree accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for maintainers to take a look labels Aug 31, 2022
@bradzacher bradzacher changed the title Bug: decorators get duplicated in AST Bug: decorators get duplicated in AST for parameter properties Aug 31, 2022
@bradzacher
Copy link
Member

bradzacher commented Aug 31, 2022

I believe that this specific code isn't required.

const decorators = getDecorators(node);
if (decorators) {
parameter.decorators = decorators.map(d => this.convertChild(d));
}

This block was added in #5551 (https://github.com/typescript-eslint/typescript-eslint/pull/5551/files#diff-341d9ffb40c62139c7da69b49d5081cbce7eabce79b58fe569de987a91e63c14R1676-R1679).

We should also add a fixture for this to prevent future regressions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: typescript-estree Issues related to @typescript-eslint/typescript-estree
Projects
None yet
2 participants