mirror of
https://github.com/morluto/rea.git
synced 2026-10-22 22:02:27 -05:00
Accept absent map-level sourcesContent and preserve null source-name slots alongside known originals and aligned content. Represent unnamed local declarations explicitly, retain leaf-local and flattened indices, and preserve declared indexed-section order across consumers. Account for added indices before browser output allocation. Accept legacy retained rows without indices. Consolidate public CLI/MCP source-map fixtures and update the stale named-source-only assertion. BREAKING CHANGE: Browser source-map original and mapping rows expose null for unavailable source names instead of inventing an unknown-source string. New index fields are optional when reading older retained evidence. Refs #2023, #2024
68 lines
1.9 KiB
TypeScript
68 lines
1.9 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { flattenSourceMapLeaves } from "./sourceMapEnvelope.js";
|
|
|
|
const leaf = {
|
|
version: 3,
|
|
mappings: "AAAA",
|
|
sources: ["app.ts"],
|
|
names: [],
|
|
};
|
|
|
|
describe("source-map envelope walk", () => {
|
|
it("collects indexed section leaves without interpreting generated offsets", () => {
|
|
const root = {
|
|
version: 3,
|
|
sections: [
|
|
{
|
|
offset: { line: 0, column: 0 },
|
|
map: {
|
|
version: 3,
|
|
sections: [
|
|
{
|
|
offset: { line: 0, column: 0 },
|
|
map: { ...leaf, sources: ["b.ts"] },
|
|
},
|
|
{
|
|
offset: { line: 1, column: 0 },
|
|
map: { ...leaf, sources: ["c.ts"] },
|
|
},
|
|
],
|
|
},
|
|
},
|
|
{
|
|
offset: { line: 10, column: 0 },
|
|
map: { ...leaf, sources: ["d.ts"] },
|
|
},
|
|
],
|
|
};
|
|
expect(flattenSourceMapLeaves(root)?.map(({ sources }) => sources)).toEqual(
|
|
[["b.ts"], ["c.ts"], ["d.ts"]],
|
|
);
|
|
});
|
|
|
|
it("rejects sections without embedded maps", () => {
|
|
const missing = {
|
|
version: 3,
|
|
sections: [{ offset: { line: 0, column: 0 } }],
|
|
};
|
|
expect(flattenSourceMapLeaves(missing)).toBeUndefined();
|
|
});
|
|
|
|
it("rejects non-version-3 roots and nested maps", () => {
|
|
expect(flattenSourceMapLeaves({ version: 3 })).toHaveLength(1);
|
|
expect(flattenSourceMapLeaves(null)).toBeUndefined();
|
|
expect(flattenSourceMapLeaves([{ version: 3 }])).toBeUndefined();
|
|
expect(
|
|
flattenSourceMapLeaves({ version: 2, mappings: "AAAA" }),
|
|
).toBeUndefined();
|
|
expect(flattenSourceMapLeaves({ mappings: "AAAA" })).toBeUndefined();
|
|
expect(
|
|
flattenSourceMapLeaves({
|
|
version: 3,
|
|
sections: [{ offset: { line: 0, column: 0 }, map: { version: 2 } }],
|
|
}),
|
|
).toBeUndefined();
|
|
});
|
|
});
|