Skip to content

Commit 0b2f22d

Browse files
committedApr 6, 2025·
perf(linter): replace phf_set with array in globals (#10274)
Related to #10076
1 parent 3dfa876 commit 0b2f22d

File tree

6 files changed

+17
-36
lines changed

6 files changed

+17
-36
lines changed
 

‎crates/oxc_linter/src/globals.rs

+11-30
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
use phf::phf_set;
22

3-
pub const GLOBAL_OBJECT_NAMES: phf::Set<&'static str> = phf_set! {
4-
"global",
5-
"globalThis",
6-
"self",
7-
"window",
8-
};
3+
pub const GLOBAL_OBJECT_NAMES: [&str; 4] = ["global", "globalThis", "self", "window"];
4+
5+
/// set of reserved HTML tag names definition
6+
/// if it's not reserved, then it can have aria-* roles, states, and properties
7+
/// Reference: <https://github.com/GoogleChrome/accessibility-developer-tools/wiki/Audit-Rules#ax_aria_12>
8+
/// Reference: <https://www.w3.org/TR/html-aria/#rules-wd>
9+
/// Reference: <https://github.com/A11yance/aria-query/blob/v5.3.2/src/domMap.js>
10+
pub const RESERVED_HTML_TAG: [&str; 16] = [
11+
"base", "col", "colgroup", "head", "html", "link", "meta", "noembed", "noscript", "param",
12+
"picture", "script", "source", "style", "title", "track",
13+
];
914

1015
/// set of valid ARIA properties from the WAI-ARIA 1.1 specifications.
1116
/// Reference: <https://www.w3.org/TR/wai-aria/#state_prop_def>
@@ -342,27 +347,3 @@ pub const HTML_TAG: phf::Set<&'static str> = phf_set! {
342347
"wbr",
343348
"xmp",
344349
};
345-
346-
/// set of reserved HTML tag names definition
347-
/// if it's not reserved, then it can have aria-* roles, states, and properties
348-
/// Reference: <https://github.com/GoogleChrome/accessibility-developer-tools/wiki/Audit-Rules#ax_aria_12>
349-
/// Reference: <https://www.w3.org/TR/html-aria/#rules-wd>
350-
/// Reference: <https://github.com/A11yance/aria-query/blob/v5.3.2/src/domMap.js>
351-
pub const RESERVED_HTML_TAG: phf::Set<&'static str> = phf_set! {
352-
"base",
353-
"col",
354-
"colgroup",
355-
"head",
356-
"html",
357-
"link",
358-
"meta",
359-
"noembed",
360-
"noscript",
361-
"param",
362-
"picture",
363-
"script",
364-
"source",
365-
"style",
366-
"title",
367-
"track",
368-
};

‎crates/oxc_linter/src/rules/eslint/prefer_exponentiation_operator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl Rule for PreferExponentiationOperator {
6767
}
6868

6969
if let Expression::Identifier(ident) = member_expr.object().without_parentheses() {
70-
if GLOBAL_OBJECT_NAMES.contains(ident.name.as_str())
70+
if GLOBAL_OBJECT_NAMES.contains(&ident.name.as_str())
7171
&& ctx.is_reference_to_global_variable(ident)
7272
{
7373
ctx.diagnostic(prefer_exponentian_operator_diagnostic(call_expr.span));

‎crates/oxc_linter/src/rules/jsx_a11y/aria_unsupported_elements.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl Rule for AriaUnsupportedElements {
5151
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
5252
if let AstKind::JSXOpeningElement(jsx_el) = node.kind() {
5353
let el_type = get_element_type(ctx, jsx_el);
54-
if RESERVED_HTML_TAG.contains(&el_type) {
54+
if RESERVED_HTML_TAG.contains(&el_type.as_ref()) {
5555
for attr in &jsx_el.attributes {
5656
let attr = match attr {
5757
JSXAttributeItem::Attribute(attr) => attr,

‎crates/oxc_linter/src/rules/unicorn/new_for_builtins.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ fn is_expr_global_builtin<'a, 'b>(
108108
return None;
109109
};
110110

111-
if !GLOBAL_OBJECT_NAMES.contains(&ident.name) {
111+
if !GLOBAL_OBJECT_NAMES.contains(&ident.name.as_str()) {
112112
return None;
113113
}
114114

‎crates/oxc_linter/src/rules/unicorn/no_document_cookie.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ fn is_document_cookie_reference<'a, 'b>(
122122
}
123123

124124
if let Expression::Identifier(ident) = member_expr.object().without_parentheses() {
125-
if !GLOBAL_OBJECT_NAMES.contains(ident.name.as_str()) {
125+
if !GLOBAL_OBJECT_NAMES.contains(&ident.name.as_str()) {
126126
return false;
127127
}
128128
}

‎crates/oxc_linter/src/rules/unicorn/prefer_number_properties.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl Rule for PreferNumberProperties {
6161
return;
6262
};
6363

64-
if GLOBAL_OBJECT_NAMES.contains(ident_name.name.as_str()) {
64+
if GLOBAL_OBJECT_NAMES.contains(&ident_name.name.as_str()) {
6565
match member_expr.static_property_name() {
6666
Some("NaN") => {
6767
ctx.diagnostic(prefer_number_properties_diagnostic(
@@ -114,7 +114,7 @@ fn extract_ident_from_expression<'b>(expr: &'b Expression<'_>) -> Option<&'b str
114114
return None;
115115
};
116116

117-
if GLOBAL_OBJECT_NAMES.contains(ident_name.name.as_str()) {
117+
if GLOBAL_OBJECT_NAMES.contains(&ident_name.name.as_str()) {
118118
member_expr.static_property_name()
119119
} else {
120120
None

0 commit comments

Comments
 (0)