mirror of
https://github.com/morluto/rea.git
synced 2026-10-30 19:35:56 +00:00
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:
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]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user