Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
Open
@overlookmotel

Description

@overlookmotel
Issue body actions

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 structurePRs and Issues about the AST structureaccepting prsGo ahead, send a pull request that resolves this issueGo ahead, send a pull request that resolves this issuebugSomething isn't workingSomething isn't workingpackage: typescript-estreeIssues related to @typescript-eslint/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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.