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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 task
sosukesuzuki opened this issue Nov 30, 2022 · 4 comments
Labels
area: third party area: typescript outdated A closed issue/PR that is archived due to age. Recommended to make a new issue Spec: Decorators

Comments

@sosukesuzuki
Copy link
Member

馃捇

  • 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 )

@liuxingbaoyu
Copy link
Member

This code is also legal in js and is parsed into two properties.
In addition, even if I set the language to JavaScript in the ts repl, it still produces output like ts.
So I'm guessing it's a ts bug.

@JLHwung
Copy link
Contributor

JLHwung commented Nov 30, 2022

This is a TS bug. The spec draft:

FieldDefinition[Yield, Await] :
  accessor [no LineTerminator here] ClassElementName[?Yield, ?Await] Initializer[+In, ?Yield, ?Await]opt

disables line terminator after accessor in the accessor property.

@sosukesuzuki
Copy link
Member Author

Thanks, I reported to TS repo microsoft/TypeScript#51707

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Mar 3, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: third party area: typescript outdated A closed issue/PR that is archived due to age. Recommended to make a new issue Spec: Decorators
Projects
None yet
Development

No branches or pull requests

3 participants