mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
refactor(linter): simplify getting ImportDefaultSpecifier (#2453)
This commit is contained in:
parent
d0d0d9d7bb
commit
cd48e1e9d9
1 changed files with 6 additions and 22 deletions
|
|
@ -1,8 +1,5 @@
|
|||
use oxc_ast::{
|
||||
ast::{
|
||||
Expression, ImportDeclarationSpecifier, JSXAttributeItem, JSXAttributeName,
|
||||
ModuleDeclaration, ObjectPropertyKind, PropertyKey,
|
||||
},
|
||||
ast::{Expression, JSXAttributeItem, JSXAttributeName, ObjectPropertyKind, PropertyKey},
|
||||
AstKind,
|
||||
};
|
||||
use oxc_diagnostics::{
|
||||
|
|
@ -39,8 +36,10 @@ declare_oxc_lint!(
|
|||
|
||||
impl Rule for InlineScriptId {
|
||||
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
|
||||
let AstKind::ModuleDeclaration(ModuleDeclaration::ImportDeclaration(import_decl)) =
|
||||
node.kind()
|
||||
let AstKind::ImportDefaultSpecifier(specifier) = node.kind() else {
|
||||
return;
|
||||
};
|
||||
let Some(AstKind::ImportDeclaration(import_decl)) = ctx.nodes().parent_kind(node.id())
|
||||
else {
|
||||
return;
|
||||
};
|
||||
|
|
@ -49,23 +48,8 @@ impl Rule for InlineScriptId {
|
|||
return;
|
||||
}
|
||||
|
||||
let Some(import_specifiers) = &import_decl.specifiers else { return };
|
||||
|
||||
// find default import
|
||||
let Some(default_import) = import_specifiers.iter().find_map(|import_specifier| {
|
||||
let ImportDeclarationSpecifier::ImportDefaultSpecifier(import_default_specifier) =
|
||||
import_specifier
|
||||
else {
|
||||
return None;
|
||||
};
|
||||
|
||||
Some(import_default_specifier)
|
||||
}) else {
|
||||
return;
|
||||
};
|
||||
|
||||
'references_loop: for reference in
|
||||
ctx.semantic().symbol_references(default_import.local.symbol_id.get().unwrap())
|
||||
ctx.semantic().symbol_references(specifier.local.symbol_id.get().unwrap())
|
||||
{
|
||||
let node = ctx.nodes().get_node(reference.node_id());
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue