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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing parentheses for ((let) of []); #10828

Closed
fisker opened this issue May 6, 2021 · 1 comment · Fixed by #14044
Closed

Missing parentheses for ((let) of []); #10828

fisker opened this issue May 6, 2021 · 1 comment · Fixed by #14044
Labels
lang:javascript Issues affecting JS locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. type:bug Issues identifying ugly output, or a defect in the program

Comments

@fisker
Copy link
Member

fisker commented May 6, 2021

Prettier 2.2.1
Playground link

--parser babel

Input:

for ((let) of []);

Output:

for (let of []);

Second Output:

SyntaxError: Unexpected token, expected ";" (1:13)
> 1 | for (let of []);
    |             ^
  2 | 

The parens are also needed in for ((let) of []); and for ((let.foo.bar) of []);.

See https://tc39.es/ecma262/#sec-for-in-and-for-of-statements

Originally posted by @thorn0 in #10777 (comment)

@sosukesuzuki
Copy link
Member

sosukesuzuki commented May 6, 2021

summary

according to spec

for in:

for (expression1 in expression2) {}

If expressin1 starts with let[, it should be wrapped by parens.

for of:

for (expression1 of expression2) {}

If expression1 starts with let or async of, it should be wrapped by parens.

for await of:

for await (expression1 of expression2) {}

If expression1 starts with let, it should be wrapped by parens.

@sosukesuzuki sosukesuzuki added lang:javascript Issues affecting JS type:bug Issues identifying ugly output, or a defect in the program labels May 6, 2021
@github-actions github-actions bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Nov 28, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lang:javascript Issues affecting JS locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. type:bug Issues identifying ugly output, or a defect in the program
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants