fix(javascript): avoid argument limits when expanding escaped receivers

This commit is contained in:
Ysopwnable 2026-10-10 19:11:00 +08:00 committed by GitHub
parent 3cd80cbb88
commit bace2c5a4f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 38 additions and 3 deletions

View File

@ -597,11 +597,9 @@ describe("property mutation collection on minified bundles", () => {
{ length: 2000 },
(_, index) => `source.p${index} = ${index};`,
).join(" ");
const start = performance.now();
const value = resultValue(
`const source = { token: "TOKEN" }; ${writes} return [source.token, source.p1999];`,
);
expect(performance.now() - start).toBeLessThan(2000);
expect(value).toMatchObject({
status: "array",
items: [

View File

@ -343,7 +343,8 @@ export const collectSemanticMemberMutations = (
if (paths.has(pathKey)) continue;
paths.add(pathKey);
expanded.set(node, paths);
pending.push(...expandedValues(node, value.path, "escape"));
for (const reference of expandedValues(node, value.path, "escape"))
pending.push(reference);
}
}
const byPath = escapedLeaves.get(root) ?? new Map();

View File

@ -115,3 +115,39 @@ cliTest(
({ cli }) => verifyJavaScriptReturnShapes(cli, source, assertReturns),
120_000,
);
cliTest(
"analyzes wide receiver returns without losing escaped reference facts",
({ cli }) => {
const width = 160_000;
const object = Array.from(
{ length: width },
(_, index) => `p${index}:0`,
).join(",");
const array = "0,".repeat(width);
const wideSource = [
["wideObject", `{${object},last:shared}`],
["wideArray", `[${array}shared]`],
]
.map(
([name, value]) =>
`export function ${name}(){const shared={x:1};const box={wide(){return ${value}},noop(){}};box.noop();return {x:shared.x,keep:7};}`,
)
.join("\n");
return verifyJavaScriptReturnShapes(cli, wideSource, (fields) => {
for (const name of ["wideObject", "wideArray"]) {
expect(fields(name)).toContainEqual(
expect.objectContaining({ path: "/x", state: "unknown" }),
);
expect(fields(name)).toContainEqual(
expect.objectContaining({
path: "/keep",
state: "literal",
value: 7,
}),
);
}
});
},
120_000,
);