fix(linter): edge case with infinite loops. (#3672)

closes #3663 this time for real😅

browser search doesn't work in the GitHub actions (because of the partial rendering I guess) I had to use GitHub's own log search to see all instances related to this rule.

[oxlint-ecosystem-ci](https://github.com/rzvxa/oxlint-ecosystem-ci/actions/runs/9512820948)
This commit is contained in:
rzvxa 2024-06-14 08:37:16 +00:00
parent abd6ac8811
commit cf71c23d93

View file

@ -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![