Skip to content

Using member access expressions (@(array[0])) in decorators produces incorrect output #14309

@zsakowitz

Description

@zsakowitz

Prettier 2.8.3
Playground link

--parser typescript

Input:

class Person {
  @(myDecoratorArray[0])
  greet() {}
}

Output:

class Person {
  @myDecoratorArray[0]
  greet() {}
}

Why is this wrong?

In the original script, the Person class has a single member: a greet method decorated with myDecoratorArray[0].

The output has very different code. The Person class now has two members:

  • a greet method with zero decorators, and
  • a computed property (0) decorated with myDecoratorArray.

Expected behavior:

The output should be the same as the input, with the decorator properly enclosed in parentheses.

Metadata

Metadata

Assignees

Labels

lang:javascriptIssues affecting JSlocked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions