fix(coverage): don't mark lines uncovered when zero-count range only partially overlaps#32601
Merged
bartlomieju merged 4 commits intomainfrom Mar 15, 2026
Merged
fix(coverage): don't mark lines uncovered when zero-count range only partially overlaps#32601bartlomieju merged 4 commits intomainfrom
bartlomieju merged 4 commits intomainfrom
Conversation
…partially overlaps
The coverage line count algorithm had two phases: Phase 1 found the
innermost range fully enclosing each line, and Phase 2 reset the count
to zero if any zero-count range merely *overlapped* (even partially)
the line. This caused lines like `if (cond) {` and `finally {` to be
falsely marked uncovered when a tiny zero-count range (e.g. the
unreachable gap between catch's return and finally) partially overlapped
them.
Fix Phase 2 to require the same full-enclosure criterion as Phase 1,
and only override when the zero-count range is more specific (smaller)
than the best range found in Phase 1.
Fixes #13781
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Update the Phase 2 zero-count override to require the range reaches at least one edge of the line. A zero-count range floating in the middle (not touching start or end) is a V8 artifact (e.g. catch/finally gap) and should not zero out the line. Update test expectations for console.log with uncalled arrow fn — the line IS executed so marking it covered is more correct. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #13781 —
finallyblocks (andifcondition lines) were incorrectly marked as uncovered when all branches intry/catchhadreturnstatements.Root cause
The coverage line count algorithm has two phases:
For
try/catch/finallywith returns, V8 emits a tiny zero-count range (often just 1 character) representing the unreachable sequential path betweencatch'sreturnand thefinallykeyword. Phase 2's partial-overlap check let this tiny range incorrectly zero out thefinally {line — even though Phase 1 correctly found a larger enclosing range with count > 0.The same bug affected
if (cond) {lines where the false-branch zero-count range partially overlapped the condition line.Fix
Phase 2 now uses the same full-enclosure criterion as Phase 1, and only overrides when the zero-count range is more specific (smaller) than the best range found in Phase 1.
Test plan
finallyiftry/catchhavereturnstatements #13781 now reports 100% line coverage🤖 Generated with Claude Code