Skip to content

Bug: key of constructor in class C { "constructor"() {} } should not be an Identifier #11084

@overlookmotel

Description

@overlookmotel

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=5.8.2&showAST=es&fileType=.tsx&code=MYGwhgzhAEDC0G8BQ1oCJgHsB2EAuATgK7B6YFoAUAlItAL5KNA&eslintrc=N4KABGBEBOCuA2BTAzpAXGYBfEWg&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

class C {
  "constructor"() { }
}

ESLint Config

n/a

tsconfig

n/a

Expected Result

I expected key property of MethodDefinition to be a Literal, not an Identifier.

This would match Espree (AST explorer).

Actual Result

key property of MethodDefinition is an Identifier:

{
  "type": "MethodDefinition",
  "key": {
    "type": "Identifier",
    "range": [12, 25],
    "name": "constructor",
    "decorators": [],
    "optional": false,
    "typeAnnotation": null
  },
  "kind": "constructor",
  "...": "..."
}

Main reason I think this is a bug is that it's different from Espree, where key is a Literal.

But additionally, I feel this is error-prone, because you can normally assume that the section of source text corresponding to an Identifier's range starts with either a UnicodeIDStart character, or \. This breaks that rule - the first character is ".

Additional Info

No response

Versions

package version
@typescript-eslint/parser 8.30.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    ASTPRs and Issues about the AST structureaccepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workinglocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: typescript-estreeIssues related to @typescript-eslint/typescript-estree

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy