Skip to content

Commit 66dbf9d

Browse files
committed
perf(linter/no-console): get static property name only once (#11880)
Instead of iterating over `allow` and recalculating the static property name on each turn of the loop, check if the property name is allowed once it's already calculated with `MemberExpression::static_property_info`. This PR also ensures that the fix made in #11879 works. If not stacked on top of that PR, one of the tests added in #11878 fails.
1 parent fe78dcf commit 66dbf9d

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

crates/oxc_linter/src/rules/eslint/no_console.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,13 @@ impl Rule for NoConsole {
112112
};
113113

114114
if ident.name == "console"
115-
&& ctx.scoping().root_unresolved_references().contains_key(ident.name.as_str())
116-
&& !self
117-
.allow
118-
.iter()
119-
.any(|s| member_expr.static_property_name().is_some_and(|f| f == s))
115+
&& ctx.scoping().root_unresolved_references().contains_key("console")
120116
{
121-
if let Some((mem_span, _)) = member_expr.static_property_info() {
117+
if let Some((mem_span, prop_name)) = member_expr.static_property_info() {
118+
if self.allow.iter().any(|allowed_name| allowed_name == prop_name) {
119+
return;
120+
}
121+
122122
let diagnostic_span = ident.span().merge(mem_span);
123123

124124
ctx.diagnostic_with_suggestion(

0 commit comments

Comments
 (0)