JavaScript: the ?? precedence test tells the two groupings apart

`(null ?? 1 | 2)` and `(null ?? 0 ? 'a' : 'b')` give the same result under
either grouping. `(1 ?? 2 | 4)` gives 5 and `(1 ?? 0 ? 'a' : 'b')` gives 1
when `??` binds the wrong way, so the test now fails on a wrong precedence.
This commit is contained in:
dotCooCoo
2026-11-22 07:59:50 -08:00
parent 74d481ef68
commit 001e9ec83e
+2 -2
View File
@@ -137,8 +137,8 @@ fn coalesce_takes_the_right_side_only_for_undefined_or_null() {
#[test]
fn coalesce_binds_looser_than_bitwise_and_tighter_than_the_conditional() {
truth("(null ?? 1 | 2) === 3");
truth("(null ?? 0 ? 'a' : 'b') === 'b'");
truth("(1 ?? 2 | 4) === 1");
truth("(1 ?? 0 ? 'a' : 'b') === 'a'");
truth("var x = null ?? 7, y = 1 ?? 8; x === 7 && y === 1");
truth("((null || 1) ?? 2) === 1 && (null ?? (0 && 1)) === 0 && ((0 ?? 1) || 2) === 2 && ((null && 1) ?? 2) === 2");
}