diff --git a/src/sourcemap/CodeCoverage.zig b/src/sourcemap/CodeCoverage.zig index 03c2e0363d..bf12e05ff2 100644 --- a/src/sourcemap/CodeCoverage.zig +++ b/src/sourcemap/CodeCoverage.zig @@ -394,6 +394,8 @@ pub const ByteRangeMapping = struct { executable_lines = try Bitset.initEmpty(allocator, line_count); lines_which_have_executed = try Bitset.initEmpty(allocator, line_count); for (blocks, 0..) |block, i| { + if (block.endOffset < 0) continue; // does not map to anything + const min: usize = @intCast(@min(block.startOffset, block.endOffset)); const max: usize = @intCast(@max(block.startOffset, block.endOffset)); var min_line: u32 = std.math.maxInt(u32); @@ -473,6 +475,8 @@ pub const ByteRangeMapping = struct { lines_which_have_executed = try Bitset.initEmpty(allocator, line_count); for (blocks, 0..) |block, i| { + if (block.endOffset < 0) continue; // does not map to anything + const min: usize = @intCast(@min(block.startOffset, block.endOffset)); const max: usize = @intCast(@max(block.startOffset, block.endOffset)); var min_line: u32 = std.math.maxInt(u32); diff --git a/test/cli/test/coverage.test.ts b/test/cli/test/coverage.test.ts new file mode 100644 index 0000000000..af72217d02 --- /dev/null +++ b/test/cli/test/coverage.test.ts @@ -0,0 +1,20 @@ +import { test, expect } from "bun:test"; +import { tempDirWithFiles, bunExe, bunEnv } from "harness"; +import path from "path"; + +test("coverage crash", () => { + const dir = tempDirWithFiles("cov", { + "demo.test.ts": `class Y { + #hello +}`, + }); + const result = Bun.spawnSync([bunExe(), "test", "--coverage"], { + cwd: dir, + env: { + ...bunEnv, + }, + stdio: ["inherit", "inherit", "inherit"], + }); + expect(result.exitCode).toBe(0); + expect(result.signalCode).toBeUndefined(); +});