Skip to content

Commit

Permalink
Improve let check in for..of (#14076)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Dec 29, 2022
1 parent 201e02e commit d798b55
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/language-js/needs-parens.js
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
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
@@ -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
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);

0 comments on commit d798b55

Please sign in to comment.