diff --git a/src/rules/prefer_primordials.rs b/src/rules/prefer_primordials.rs index 99905a60..fcfadc4d 100644 --- a/src/rules/prefer_primordials.rs +++ b/src/rules/prefer_primordials.rs @@ -323,7 +323,7 @@ struct PreferPrimordialsHandler; impl Handler for PreferPrimordialsHandler { fn ident(&mut self, ident: &ast_view::Ident, ctx: &mut Context) { - fn inside_var_decl_lhs_or_member_expr_or_prop( + fn inside_var_decl_lhs_or_member_expr_or_prop_or_type_ref( orig: ast_view::Node, node: ast_view::Node, ) -> bool { @@ -336,11 +336,14 @@ impl Handler for PreferPrimordialsHandler { if let Some(kv) = node.to::() { return kv.key.range().contains(&orig.range()); } + if let Some(type_ref) = node.to::() { + return type_ref.type_name.range().contains(&orig.range()); + } match node.parent() { None => false, Some(parent) => { - inside_var_decl_lhs_or_member_expr_or_prop(orig, parent) + inside_var_decl_lhs_or_member_expr_or_prop_or_type_ref(orig, parent) } } } @@ -349,7 +352,7 @@ impl Handler for PreferPrimordialsHandler { scope.var(&ident.inner.to_id()).is_some() } - if inside_var_decl_lhs_or_member_expr_or_prop( + if inside_var_decl_lhs_or_member_expr_or_prop_or_type_ref( ident.as_node(), ident.as_node(), ) { @@ -767,6 +770,15 @@ let a, b, c; const { indirectEval } = primordials; indirectEval("console.log('This test should pass.');"); "#, + r#" +function foo(a: Array) {} + "#, + r#" +function foo(): Array {} + "#, + r#" +type p = Promise; + "#, }; }