Files
test-repo/changelog_unreleased/javascript/16391.md
T
Christopher Dignamandfisker Cheung 988b43b72d Add parens for nullish coalescing in tenary (#16391)
* 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>
2024-06-18 01:47:28 +01:00

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);
```