From ab2ef4f89ba3ca50c68abb2ca43e36b7793f3673 Mon Sep 17 00:00:00 2001 From: Ash Date: Sat, 1 Apr 2023 16:40:25 +0100 Subject: [PATCH] fix: nullish coalescing operator precedence (#240) --- crates/oxc_linter/src/rules/no_mixed_operators.rs | 3 ++- crates/oxc_linter/src/snapshots/no_mixed_operators.snap | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/oxc_linter/src/rules/no_mixed_operators.rs b/crates/oxc_linter/src/rules/no_mixed_operators.rs index 3b8c55a87..b181fc91f 100644 --- a/crates/oxc_linter/src/rules/no_mixed_operators.rs +++ b/crates/oxc_linter/src/rules/no_mixed_operators.rs @@ -217,7 +217,7 @@ const PRECEDENCES: [u8; 27] = [ 4, 3, 9, 9, 2, - 9, + 3 ]; const ARITHMETIC: &[&str] = &OPERATORS[..6]; @@ -296,6 +296,7 @@ fn test() { ("x ? a && b : 0", Some(json!([{ "groups": [["&&", "||", "?:"]] }]))), ("x ? 0 : a && b", Some(json!([{ "groups": [["&&", "||", "?:"]] }]))), ("a + b ?? c", Some(json!([{ "groups": [["+", "??"]] }]))), + ("a in b ?? c", Some(json!([{ "groups": [["in", "??"]] }]))), ]; Tester::new(NoMixedOperators::NAME, pass, fail).test_and_snapshot(); diff --git a/crates/oxc_linter/src/snapshots/no_mixed_operators.snap b/crates/oxc_linter/src/snapshots/no_mixed_operators.snap index 8f84ca851..1813ffbde 100644 --- a/crates/oxc_linter/src/snapshots/no_mixed_operators.snap +++ b/crates/oxc_linter/src/snapshots/no_mixed_operators.snap @@ -108,3 +108,10 @@ expression: no_mixed_operators ╰──── help: Use parentheses to clarify the intended order of operations. + ⚠ eslint(no-mixed-operators): Unexpected mix of in with ?? + ╭─[no_mixed_operators.tsx:1:1] + 1 │ a in b ?? c + · ── ── + ╰──── + help: Use parentheses to clarify the intended order of operations. +