Skip to content

Commit fd6f455

Browse files
committed
fix(prefer-primordials): allow private identifier in in expression
1 parent b722829 commit fd6f455

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

src/rules/prefer_primordials.rs

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -713,20 +713,24 @@ impl Handler for PreferPrimordialsHandler {
713713
fn bin_expr(&mut self, bin_expr: &ast_view::BinExpr, ctx: &mut Context) {
714714
use ast_view::BinaryOp;
715715

716-
if matches!(bin_expr.op(), BinaryOp::InstanceOf) {
717-
ctx.add_diagnostic_with_hint(
718-
bin_expr.range(),
719-
CODE,
720-
PreferPrimordialsMessage::InstanceOf,
721-
PreferPrimordialsHint::InstanceOf,
722-
);
723-
} else if matches!(bin_expr.op(), BinaryOp::In) {
724-
ctx.add_diagnostic_with_hint(
725-
bin_expr.range(),
726-
CODE,
727-
PreferPrimordialsMessage::In,
728-
PreferPrimordialsHint::In,
729-
);
716+
match bin_expr.op() {
717+
BinaryOp::InstanceOf => {
718+
ctx.add_diagnostic_with_hint(
719+
bin_expr.range(),
720+
CODE,
721+
PreferPrimordialsMessage::InstanceOf,
722+
PreferPrimordialsHint::InstanceOf,
723+
);
724+
}
725+
BinaryOp::In if !bin_expr.left.is::<ast_view::PrivateName>() => {
726+
ctx.add_diagnostic_with_hint(
727+
bin_expr.range(),
728+
CODE,
729+
PreferPrimordialsMessage::In,
730+
PreferPrimordialsHint::In,
731+
);
732+
}
733+
_ => {}
730734
}
731735
}
732736
}
@@ -913,6 +917,15 @@ function foo(): Array<any> {}
913917
r#"
914918
type p = Promise<void>;
915919
"#,
920+
r#"
921+
class A {
922+
#brand;
923+
924+
static is(obj) {
925+
return #brand in obj;
926+
}
927+
}
928+
"#,
916929
};
917930
}
918931

@@ -1294,6 +1307,13 @@ new DataView(new ArrayBuffer(10)).byteOffset;
12941307
hint: PreferPrimordialsHint::In,
12951308
},
12961309
],
1310+
r#"a in A"#: [
1311+
{
1312+
col: 0,
1313+
message: PreferPrimordialsMessage::In,
1314+
hint: PreferPrimordialsHint::In,
1315+
},
1316+
],
12971317
r#"a instanceof A"#: [
12981318
{
12991319
col: 0,

0 commit comments

Comments
 (0)