Skip to content

Commit

Permalink
perf(linter): make jsx_key slightly faster (#5585)
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Sep 7, 2024
1 parent cd81d12 commit 2c3f3fe
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions crates/oxc_linter/src/rules/react/jsx_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ pub fn import_matcher<'a>(
actual_local_name: &'a str,
expected_module_name: &'a str,
) -> bool {
let expected_module_name = expected_module_name.to_lowercase();
ctx.semantic().module_record().import_entries.iter().any(|import| {
import.module_request.name().as_str() == expected_module_name.to_lowercase()
import.module_request.name().as_str() == expected_module_name
&& import.local_name.name().as_str() == actual_local_name
})
}
Expand All @@ -103,10 +104,9 @@ pub fn is_import<'a>(
expected_local_name: &'a str,
expected_module_name: &'a str,
) -> bool {
let total_imports = ctx.semantic().module_record().requested_modules.len();
let total_variables = ctx.scopes().get_bindings(ctx.scopes().root_scope_id()).len();

if total_variables == 0 && total_imports == 0 {
if ctx.semantic().module_record().requested_modules.is_empty()
&& ctx.scopes().get_bindings(ctx.scopes().root_scope_id()).is_empty()
{
return actual_local_name == expected_local_name;
}

Expand Down Expand Up @@ -486,10 +486,10 @@ fn test() {
</div>
);}))}
",
r#"import { Children } from "react";
r#"import { Children } from "react";
Children.toArray([1, 2 ,3].map(x => <App />));
"#,
r#"import React from "react";
r#"import React from "react";
React.Children.toArray([1, 2 ,3].map(x => <App />));
"#,
r"React.Children.toArray([1, 2 ,3].map(x => <App />));",
Expand Down

0 comments on commit 2c3f3fe

Please sign in to comment.