Skip to content

[Bug]: Inconsistently parsing between TypeScript and Babel for decorator auto accessors #15238

@sosukesuzuki

Description

@sosukesuzuki

💻

  • Would you like to work on a fix?

How are you using Babel?

Other (Next.js, Gatsby, vue-cli, ...)

Input code

class C {
  accessor
  property
}

Configuration file name

No response

Configuration

Use @babel/parser as a Node.js API.

Current and expected behavior

current:

@babel/parser with typescript plugin parses the input code to:

// pseudo AST
{
  type: class
  children: [
    property ( name = "accessor" ),
    property ( name = "foo" )
  ]
}

But TypeScript Compiler parses the input code to:

// pseudo AST
{
  type: class
  children: [
    accessor property ( name = "foo" )
  ]
}

expected:

Must match the decorator spec. I don't know which is correct.
If TypeScript Compiler behavior is wrong, we should report to microsoft/typescript repository.

Environment

Environment does not matter.

Possible solution

Fix parsing logic

Additional context

I noticed this while working on printing accessor property syntax for Prettier ( prettier/prettier#13919 )

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions