diff --git a/crates/oxc_linter/src/rules/eslint/no_unreachable.rs b/crates/oxc_linter/src/rules/eslint/no_unreachable.rs index da24a6215..a988c41cb 100644 --- a/crates/oxc_linter/src/rules/eslint/no_unreachable.rs +++ b/crates/oxc_linter/src/rules/eslint/no_unreachable.rs @@ -6,7 +6,7 @@ use oxc_semantic::{ visit::{depth_first_search, Control, DfsEvent, EdgeRef}, Direction, }, - EdgeType, InstructionKind, + EdgeType, ErrorEdgeKind, InstructionKind, }; use oxc_span::{GetSpan, Span}; @@ -84,7 +84,9 @@ impl Rule for NoUnreachable { // `NewFunction` is always reachable | EdgeType::NewFunction // `Finalize` can be reachable if we encounter an error in the loop. - | EdgeType::Finalize => true, + | EdgeType::Finalize + // Explicit `Error` can also be reachable if we encounter an error in the loop. + | EdgeType::Error(ErrorEdgeKind::Explicit) => true, // If we have an incoming `Jump` and it is from a `Break` instruction, // We know with high confidence that we are visiting a reachable block. @@ -256,6 +258,15 @@ fn test() { } c(); ", + " + try { + while (true) { + a(); + } + } catch { + b(); + } + ", ]; let fail = vec![