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

Improve let check in for..of #14076

Merged
merged 3 commits into from
Dec 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/language-js/needs-parens.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@ function needsParens(path, options) {
// `for ((async) of []);` and `for ((let) of []);`
if (
name === "left" &&
(node.name === "async" || node.name === "let") &&
parent.type === "ForOfStatement" &&
!parent.await
((node.name === "async" && !parent.await) || node.name === "let") &&
parent.type === "ForOfStatement"
) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ printWidth: 80
| printWidth
=====================================input======================================
async function a() {
for await((let) of foo);
for await((let).a of foo);
for await((let)[a] of foo);
for await((let)()[a] of foo);
}
=====================================output=====================================
async function a() {
for await ((let) of foo);
for await ((let).a of foo);
for await ((let)[a] of foo);
for await ((let)()[a] of foo);
Expand All @@ -40,6 +42,8 @@ for (letFoo of foo);
for ((let.a) in foo);
for ((let[a]) in foo);
for (let of of let);
=====================================output=====================================
for ((let) of foo);
for (foo of let);
Expand All @@ -53,5 +57,7 @@ for (letFoo of foo);
for (let.a in foo);
for ((let)[a] in foo);
for (let of of let);
================================================================================
`;
1 change: 1 addition & 0 deletions tests/format/js/identifier/for-of/await.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
async function a() {
for await((let) of foo);
for await((let).a of foo);
for await((let)[a] of foo);
for await((let)()[a] of foo);
Expand Down
2 changes: 2 additions & 0 deletions tests/format/js/identifier/for-of/let.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ for (letFoo of foo);

for ((let.a) in foo);
for ((let[a]) in foo);

for (let of of let);