fix(source-maps): keep sources when sourcesContent length differs (#2873)
ECMA-426 DecodeSourceMapSources reads a content slot only while its index is within sourcesContent, so a shorter array leaves trailing sources without content and a longer array adds no sources. Local application analysis and browser collection rejected any length mismatch and dropped every original from the map. The content helper now checks only entry types. Browser collection drops its separate check because the leaf schema already validates every supplied entry, and the raw records are still budgeted before parsing. Fixes #2821
This commit is contained in:
@@ -810,7 +810,6 @@ describe("web source-map sourcesContent validation", () => {
|
||||
it.each([
|
||||
["a scalar sourcesContent value", { sourcesContent: "source" }],
|
||||
["a non-string, non-null source entry", { sourcesContent: [42] }],
|
||||
["a sourcesContent array with the wrong length", { sourcesContent: [] }],
|
||||
])("reports %s as invalid", async (_description, content) => {
|
||||
const result = await fetchWebSourceMaps([request], input(), undefined, {
|
||||
fetch: () =>
|
||||
@@ -841,6 +840,50 @@ describe("web source-map sourcesContent validation", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it.each([
|
||||
["shorter", ["import './a.ts';"]],
|
||||
["longer", ["import './a.ts';", null, "unused trailing content"]],
|
||||
])(
|
||||
"keeps every source declaration when sourcesContent is %s than sources",
|
||||
async (_length, sourcesContent) => {
|
||||
const result = await fetchWebSourceMaps([request], input(), undefined, {
|
||||
fetch: () =>
|
||||
Promise.resolve(
|
||||
new Response(
|
||||
JSON.stringify({
|
||||
version: 3,
|
||||
sources: ["a.ts", "b.ts"],
|
||||
sourcesContent,
|
||||
names: [],
|
||||
mappings: "",
|
||||
}),
|
||||
{ status: 200 },
|
||||
),
|
||||
),
|
||||
});
|
||||
|
||||
expect(result.items[0]).toMatchObject({
|
||||
status: "included",
|
||||
limitation: null,
|
||||
original_sources: [
|
||||
{
|
||||
source_index: 0,
|
||||
declaration_index: 0,
|
||||
source: `${origin}/assets/a.ts`,
|
||||
artifact: { text: "import './a.ts';" },
|
||||
},
|
||||
{
|
||||
source_index: 1,
|
||||
declaration_index: 1,
|
||||
source: `${origin}/assets/b.ts`,
|
||||
artifact: null,
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(result.items[0]?.original_sources).toHaveLength(2);
|
||||
},
|
||||
);
|
||||
|
||||
it("accepts null source-map source contents", async () => {
|
||||
const result = await fetchWebSourceMaps([request], input(), undefined, {
|
||||
fetch: () =>
|
||||
|
||||
Reference in New Issue
Block a user