Skip to content

Brackets around property accessor on let are removed; changes program syntax #13999

@Josh-Cena

Description

@Josh-Cena

Prettier 2.8.1
Playground link

--parser babel

Input:

var let = [1];
(let[0] = 2);

Output:

var let = [1];
let[0] = 2;

Second Output:

SyntaxError: Unexpected token (2:5)
  1 | var let = [1];
> 2 | let[0] = 2;
    |     ^
  3 |

Expected behavior:
Do not remove the brackets, as they are necessary to make the assignment not destructuring. This is a very niche bug, but it seems like a fairly trivial oversight.

For context, I'm documenting expression statements at mdn/content#22994, and this tripped me up when I was trying to document a workaround.

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