mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
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.
This commit is contained in:
parent
d236554512
commit
f052a6d666
1 changed files with 7 additions and 7 deletions
|
|
@ -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 name = ident.name.as_str();
|
||||
if name == "this" {
|
||||
let reference = ctx.symbols().get_reference(ident.reference_id().unwrap());
|
||||
if reference.symbol_id().is_some() {
|
||||
return;
|
||||
}
|
||||
for scope_id in ctx.scopes().ancestors(node.scope_id()) {
|
||||
if ctx.scopes().has_binding(scope_id, name) {
|
||||
return;
|
||||
}
|
||||
let name = ident.name.as_str();
|
||||
// TODO: Remove this check once we have `JSXMemberExpressionObject::ThisExpression`
|
||||
if name == "this" {
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue