Files
test-repo/tests/format/js/nullish-coalescing/nullish_coalesing_operator.js
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

27 lines
444 B
JavaScript

obj.foo ?? "default";
const x = (foo, bar = foo ?? bar) => {};
foo ? bar ?? foo : baz;
foo ?? (bar ?? baz);
(foo ?? bar) ?? baz;
// Mixing ?? and (&& or ||) requires parens
// It's a syntax error without it.
(foo ?? baz) || baz;
foo ?? (baz || baz);
(foo ?? baz) && baz;
foo ?? (baz && baz);
(foo || baz) ?? baz;
foo || (baz ?? baz);
(foo && baz) ?? baz;
foo && (baz ?? baz);
foo ?? bar ? a : b;
a ? foo ?? bar : b;
a ? b : foo ?? bar;