fix(javascript): keep Vite dependency slots after a spread unknown (#4023)

The __vite__mapDeps table indexer mapped a spread element to one unknown slot, so every later entry kept a definite index even though the spread can add any number of elements. A call such as __vite__mapDeps([0, 2]) over ["./first.js", ...["./middle-a.js", "./middle-b.js"], "./last.js"] then resolved index 2 to last.js instead of middle-b.js. Keep only the entries before the first spread; indexes from the spread onward stay unknown.
This commit is contained in:
Wade authored and GitHub committed 2026-10-22 03:50:42 +08:00
1 parent f6e4e0296f
commit d8199ab6af
2 files changed
+23 -1

No files matched your search

@@ -83,4 +83,19 @@ describe("Vite preload dependency recovery", () => {
.map(({ specifier }) => specifier),
).toEqual(["./original.js"]);
});
it("keeps table slots from a spread onward unknown", () => {
const analysis = analyzeJavaScriptStaticSource(`
const __vite__mapDeps = (indexes, map = __vite__mapDeps, dependencies =
(map.f || (map.f = ["./first.js", ...["./middle-a.js", "./middle-b.js"], "./last.js"]))) =>
indexes.map((index) => dependencies[index]);
__vite__mapDeps([0, 2]);
`);
expect(
analysis.references
.filter(({ kind }) => kind === "dynamic-import")
.map(({ specifier }) => specifier),
).toEqual(["./first.js", null]);
});
});