test(sourcemap): consolidate point lookup and CLI parity (#13067)

test(sourcemap): consolidate point lookup and original location cases
This commit is contained in:
morluto authored and GitHub committed 2026-11-21 10:37:04 +00:00
1 parent 47d86582c8
commit 07225b8b3e
2 files changed
+134 -139

No files matched your search

@@ -55,12 +55,12 @@ it("keeps ignore-list precedence and section-local indexes for duplicate sources
});
describe("upstream source-map point evidence", () => {
it("preserves duplicate-column candidates, their URL spelling and their own content", () => {
it("preserves duplicate-column candidates, URL spelling and out-of-content positions", () => {
const report = trace({
...leaf,
sources: ["dir/same.ts", "dir/same.ts", "dir//same.ts"],
sourcesContent: ["first", "second", "repeated separator"],
mappings: "AAAA,ACAA,ACAA",
mappings: "AAAA,ACAA,ACUA",
});
expect(report.matches).toMatchObject([
{
@@ -80,6 +80,12 @@ describe("upstream source-map point evidence", () => {
source_index: 2,
resolved_url: "https://app.test/maps/dir//same.ts",
content: { text: "repeated separator" },
original_position: {
line: 11,
column: 0,
offset: null,
content_position: "outside-embedded-text",
},
},
]);
});
@@ -106,15 +112,19 @@ describe("upstream source-map point evidence", () => {
content: { utf8_bytes: 8 },
});
});
it("distinguishes no match from a generated-only match carried across empty lines", () => {
const map = { ...leaf, mappings: "CAAA,I;;" };
expect(trace(map)).toMatchObject({
it("distinguishes no match, an exact generated-only match, and carry across empty lines", () => {
const map = { ...leaf, mappings: ";;C,CAAA;CAAA,I;;" };
expect(trace(map, { line: 3, column: 0 })).toMatchObject({
matches: [],
lookup: { matched_generated_position: null },
});
expect(trace(map, { line: 3, column: 2 })).toMatchObject({
expect(trace(map, { line: 3, column: 1 })).toMatchObject({
matches: [{ state: "generated-only" }],
lookup: { matched_generated_position: { line: 1, column: 5 } },
lookup: { matched_generated_position: { line: 3, column: 1 } },
});
expect(trace(map, { line: 6, column: 2 })).toMatchObject({
matches: [{ state: "generated-only" }],
lookup: { matched_generated_position: { line: 4, column: 5 } },
});
});
it("preserves unknown source identity while retaining embedded content", () => {
@@ -174,16 +184,6 @@ describe("upstream source-map point evidence", () => {
original_position: { line: 1, column: 0 },
});
});
it("reports original positions outside embedded contents without fabricating an offset", () => {
expect(trace({ ...leaf, mappings: "AAUA" }).matches[0]).toMatchObject({
original_position: {
line: 11,
column: 0,
offset: null,
content_position: "outside-embedded-text",
},
});
});
});
describe("source-map section-boundary candidates", () => {
@@ -252,41 +252,41 @@ describe("source-map section-boundary candidates", () => {
name: "secondName",
},
]);
expect(report.matches).toHaveLength(2);
},
);
it.each([false, true])(
"keeps a generated-only section-boundary candidate (first=%s)",
(generatedOnlyFirst) => {
const generated = { version: 3, sources: [], names: [], mappings: "A" };
const first = generatedOnlyFirst ? generated : leaf;
const second = generatedOnlyFirst ? leaf : generated;
const report = trace(
it("keeps generated-only and mapped candidates in declaration order at section boundaries", () => {
const generated = { version: 3, sources: [], names: [], mappings: "A" };
const map = {
version: 3,
sections: [
{ offset: { line: 0, column: 0 }, map: { ...leaf, mappings: "KAAA" } },
{ offset: { line: 0, column: 5 }, map: generated },
{
version: 3,
sections: [
{
offset: { line: 0, column: 0 },
map: { ...first, mappings: `K${first.mappings.slice(1)}` },
},
{ offset: { line: 0, column: 5 }, map: second },
],
offset: { line: 1, column: 0 },
map: { ...generated, mappings: "K" },
},
{ line: 1, column: 5 },
);
const mapped = {
{ offset: { line: 1, column: 5 }, map: leaf },
],
};
expect(trace(map, { line: 1, column: 5 }).matches).toMatchObject([
{
state: "mapped",
flattened_source_index: 0,
section_path: [generatedOnlyFirst ? 1 : 0],
section_path: [0],
source_index: 0,
};
const generatedOnly = { state: "generated-only" };
expect(report.matches).toMatchObject(
generatedOnlyFirst ? [generatedOnly, mapped] : [mapped, generatedOnly],
);
expect(report.matches).toHaveLength(2);
},
);
},
{ state: "generated-only" },
]);
expect(trace(map, { line: 2, column: 5 }).matches).toMatchObject([
{ state: "generated-only" },
{
state: "mapped",
flattened_source_index: 1,
section_path: [3],
source_index: 0,
},
]);
});
});
describe("source-map layout admission", () => {
@@ -304,18 +304,6 @@ describe("source-map layout admission", () => {
);
},
);
it("retains empty generated lines and generated-only mappings", () => {
const report = traceSourceMap(
JSON.stringify({ ...leaf, mappings: ";;A,CAAA;" }),
url,
{ line: 3, column: 0 },
);
expect(report.lookup.matched_generated_position).toEqual({
line: 3,
column: 0,
});
expect(report.matches).toEqual([{ state: "generated-only" }]);
});
it("validates regular-map source indexes after reusing its decoded rows", () => {
expect(() => trace({ ...leaf, mappings: "ACAA" })).toThrow(/index/u);
});