fix(javascript): retain array-pattern iterator close effects (#12534)

* fix(javascript): retain array-pattern iterator close effects

* fix(javascript): bound array-pattern close exposure

* fix(javascript): follow stored array elements at iterator close

* fix(javascript): retain iterator closes before array rest
This commit is contained in:
morluto authored and GitHub committed 2026-11-19 21:57:50 +00:00
1 parent 756f772430
commit 8ef5a34ff5
9 files changed
+601 -49

No files matched your search

@@ -7,6 +7,20 @@ import { javascriptApplicationAnalysisResultSchema } from "../../../src/domain/j
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
import { cliTest } from "../../support/cli/cliFixture.js";
const iteratorCloseSource = `
const box = { label: "ready", items: [{ mode: "kept" }, { mode: "old" }] };
Object.getPrototypeOf([].values()).return = function () {
delete this.next().value.mode;
return {};
};
const { label: beforeClose, items: [first], items: { 0: { mode: consumed }, 1: { mode: afterClose } } } = box;
const stored = { items: [0], next: { mode: "borrowed" } };
const { insert = (stored.items[1] = stored.next), items: [assigned], next: { mode: storedAfterClose } } = stored;
const restSource = [undefined, { mode: "before" }];
try { const [head = null.value, ...rest] = restSource; } catch {}
const { 1: { mode: abruptAfterClose } } = restSource;
`;
cliTest(
"traces proved destructuring dependencies and leaves custom iteration uncertain",
async ({ cli }) => {
@@ -59,6 +73,7 @@ cliTest(
[selected] = after;
`,
);
await writeFile(join(root, "iterator-close.js"), iteratorCloseSource);
const output = await cli.run({
arguments: ["analyze-javascript-application", root, "--json"],
});
@@ -79,6 +94,11 @@ cliTest(
["projected", ["items", "0"]],
["arrayObject", ["0", "mode"]],
["selected", ["0"], "candidate"],
["beforeClose", ["label"]],
["consumed", ["items", "0", "mode"]],
["afterClose", ["items", "1", "mode"], "candidate"],
["storedAfterClose", ["next", "mode"], "candidate"],
["abruptAfterClose", ["1", "mode"], "candidate"],
] as const) {
const binding = graph.nodes.find(
(node) => node.kind === "binding" && node.label === name,
@@ -116,6 +136,9 @@ cliTest(
"projected",
"arrayObject",
"selected",
"beforeClose",
"consumed",
"afterClose",
]) {
const binding = graph.nodes.find(
({ kind, label }) => kind === "binding" && label === name,
@@ -144,7 +167,8 @@ cliTest(
]),
},
};
if (name === "selected") expect(trace.json).not.toMatchObject(relation);
if (name === "selected" || name === "afterClose")
expect(trace.json).not.toMatchObject(relation);
else expect(trace.json).toMatchObject(relation);
}
},