Skip to content

Commit

Permalink
perf
Browse files Browse the repository at this point in the history
  • Loading branch information
baseballyama committed Dec 27, 2024
1 parent 8f4c5c8 commit bd52e6e
Showing 1 changed file with 14 additions and 23 deletions.
37 changes: 14 additions & 23 deletions crates/oxc_linter/src/rules/eslint/no_lone_blocks.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use oxc_ast::ast::VariableDeclarationKind;
use oxc_ast::ast::{Declaration, VariableDeclarationKind};
use oxc_ast::AstKind;
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
Expand Down Expand Up @@ -76,29 +76,20 @@ impl Rule for NoLoneBlocks {
lone_blocks.push(node);
}

let span = stmt.span();
let children: Vec<_> = ctx
.nodes()
.iter()
.filter(|n| {
let n_span = n.span();
span.start < n_span.start && n_span.end < span.end
})
.collect();

for child in children {
if let Some(parent_of_child) = ctx.nodes().parent_node(child.id()) {
match child.kind() {
AstKind::VariableDeclaration(var_decl)
if var_decl.kind != VariableDeclarationKind::Var =>
{
mark_lone_block(parent_of_child, &mut lone_blocks);
}
AstKind::Function(_) | AstKind::Class(_) => {
mark_lone_block(parent_of_child, &mut lone_blocks);
}
_ => {}
for child in &stmt.body {
match child.as_declaration() {
Some(Declaration::VariableDeclaration(decl))
if decl.kind != VariableDeclarationKind::Var =>
{
mark_lone_block(node, &mut lone_blocks);
}
Some(Declaration::ClassDeclaration(_)) => {
mark_lone_block(node, &mut lone_blocks);
}
Some(Declaration::FunctionDeclaration(_)) => {
mark_lone_block(node, &mut lone_blocks);
}
_ => {}
}
}

Expand Down

0 comments on commit bd52e6e

Please sign in to comment.