I was trying to format a block of code like this one:
let [a, b] = [64n, 2n];
do {
console.log(a);
} while (a /= b);
I found that prettier adds an extra pair of parentheses around the while condition:
let [a, b] = [64n, 2n];
do {
console.log(a);
} while ((a /= b));
I don't get why it does that. Seems like a bug, since both pieces of code give the same output. Is there any reason to prefer the second format?
The code
while(<expression>)andwhile((<expression>))will always be equivalent. However, it seems that Prettier is intentionally adding an extra wrapping parenthesis because the condition is an assignment.Documented in this GitHub issue. Here is what lydell said in December 2018