diff --git a/src/rules/prefer_primordials.rs b/src/rules/prefer_primordials.rs index 61cc2268..46a93be4 100644 --- a/src/rules/prefer_primordials.rs +++ b/src/rules/prefer_primordials.rs @@ -712,20 +712,24 @@ impl Handler for PreferPrimordialsHandler { fn bin_expr(&mut self, bin_expr: &ast_view::BinExpr, ctx: &mut Context) { use ast_view::BinaryOp; - if matches!(bin_expr.op(), BinaryOp::InstanceOf) { - ctx.add_diagnostic_with_hint( - bin_expr.range(), - CODE, - PreferPrimordialsMessage::InstanceOf, - PreferPrimordialsHint::InstanceOf, - ); - } else if matches!(bin_expr.op(), BinaryOp::In) { - ctx.add_diagnostic_with_hint( - bin_expr.range(), - CODE, - PreferPrimordialsMessage::In, - PreferPrimordialsHint::In, - ); + match bin_expr.op() { + BinaryOp::InstanceOf => { + ctx.add_diagnostic_with_hint( + bin_expr.range(), + CODE, + PreferPrimordialsMessage::InstanceOf, + PreferPrimordialsHint::InstanceOf, + ); + } + BinaryOp::In if !bin_expr.left.is::() => { + ctx.add_diagnostic_with_hint( + bin_expr.range(), + CODE, + PreferPrimordialsMessage::In, + PreferPrimordialsHint::In, + ); + } + _ => {} } } } @@ -912,6 +916,15 @@ function foo(): Array {} r#" type p = Promise; "#, + r#" +class A { + #brand; + + static is(obj) { + return #brand in obj; + } +} + "#, }; } @@ -1293,6 +1306,13 @@ new DataView(new ArrayBuffer(10)).byteOffset; hint: PreferPrimordialsHint::In, }, ], + r#"a in A"#: [ + { + col: 0, + message: PreferPrimordialsMessage::In, + hint: PreferPrimordialsHint::In, + }, + ], r#"a instanceof A"#: [ { col: 0,