* add parens for nullish coalescing fix #4873 * add function * Update tests/format/js/nullish-coalescing/nullish_coalesing_operator.js Co-authored-by: fisker Cheung <lionkay@gmail.com> * update snapshot * add changelog entry * fix typo --------- Co-authored-by: fisker Cheung <lionkay@gmail.com>
22 lines
415 B
Markdown
22 lines
415 B
Markdown
#### Add parentheses for nullish coalescing in ternary (#16391 by @cdignam-segment)
|
|
|
|
This change adds clarity to operator precedence.
|
|
|
|
<!-- prettier-ignore -->
|
|
```js
|
|
// Input
|
|
foo ? bar ?? foo : baz;
|
|
foo ?? bar ? a : b;
|
|
a ? b : foo ?? bar;
|
|
|
|
// Prettier stable
|
|
foo ? bar ?? foo : baz;
|
|
foo ?? bar ? a : b;
|
|
a ? b : foo ?? bar;
|
|
|
|
// Prettier main
|
|
foo ? (bar ?? foo) : baz;
|
|
(foo ?? bar) ? a : b;
|
|
a ? b : (foo ?? bar);
|
|
```
|