Skip to content

Commit

Permalink
perf(linter): react/jsx_no_undef faster check for unbound references (
Browse files Browse the repository at this point in the history
#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.
  • Loading branch information
overlookmotel committed Aug 30, 2024
1 parent d236554 commit f052a6d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions crates/oxc_linter/src/rules/react/jsx_no_undef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
Expand Down

0 comments on commit f052a6d

Please sign in to comment.