From f052a6d6664b4bfa3fae14445ce7558f8186e0c1 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Fri, 30 Aug 2024 14:56:55 +0000 Subject: [PATCH] perf(linter): `react/jsx_no_undef` faster check for unbound references (#5349) Follow-on after #5223. Now that we are getting an `IdentifierReference` with a `reference_id`, we can use that ID for a faster lookup of whether the reference is bound or not. --- crates/oxc_linter/src/rules/react/jsx_no_undef.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/oxc_linter/src/rules/react/jsx_no_undef.rs b/crates/oxc_linter/src/rules/react/jsx_no_undef.rs index 6dd66bf56ac45..55a738acb2635 100644 --- a/crates/oxc_linter/src/rules/react/jsx_no_undef.rs +++ b/crates/oxc_linter/src/rules/react/jsx_no_undef.rs @@ -53,19 +53,19 @@ impl Rule for JsxNoUndef { fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) { if let AstKind::JSXOpeningElement(elem) = &node.kind() { if let Some(ident) = get_resolvable_ident(&elem.name) { + let reference = ctx.symbols().get_reference(ident.reference_id().unwrap()); + if reference.symbol_id().is_some() { + return; + } let name = ident.name.as_str(); + // TODO: Remove this check once we have `JSXMemberExpressionObject::ThisExpression` if name == "this" { return; } - for scope_id in ctx.scopes().ancestors(node.scope_id()) { - if ctx.scopes().has_binding(scope_id, name) { - return; - } - } if ctx.globals().is_enabled(name) { return; } - ctx.diagnostic(jsx_no_undef_diagnostic(ident.name.as_str(), ident.span)); + ctx.diagnostic(jsx_no_undef_diagnostic(name, ident.span)); } } }