fix(javascript): acquire nested iterators from stored receivers (#12542)

* fix(javascript): acquire nested iterators from stored receivers

* fix(javascript): preserve stored iterator branches and pattern timing
This commit is contained in:
morluto authored and GitHub committed 2026-11-19 22:22:46 +00:00
1 parent 4892615ecb
commit f5573a0064
8 files changed
+490 -65

No files matched your search

@@ -19,8 +19,35 @@ const iteratorCloseSource = `
const restSource = [undefined, { mode: "before" }];
try { const [head = null.value, ...rest] = restSource; } catch {}
const { 1: { mode: abruptAfterClose } } = restSource;
const replaced = { items: [0], next: { mode: "borrowed" } };
const { replace = (replaced.items = [0, replaced.next]), next: { mode: replacedBeforeClose }, items: [use], next: { mode: replacedAfterClose } } = replaced;
const holder = { parent: { items: [0], next: { mode: "before" } } };
const custom = { child: holder.parent.next, [Symbol.iterator]() { delete this.child.mode; return [0].values(); } };
const { useCustom = (holder.parent.items = custom), items: [read], next: { mode: projectedAfterAcquisition } } = holder.parent;
`;
const expectedDependencies = [
["declared", ["a"]],
["a", ["a"]],
["plain", ["a", "0"]],
["fallback", ["a", "0"]],
["scalar", ["b"]],
["ordinary", ["0"]],
["arrayAssigned", ["0"]],
["elided", ["1"]],
["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"],
["replacedBeforeClose", ["next", "mode"]],
["replacedAfterClose", ["next", "mode"], "candidate"],
["projectedAfterAcquisition", ["parent", "next", "mode"], "candidate"],
] as const;
cliTest(
"traces proved destructuring dependencies and leaves custom iteration uncertain",
async ({ cli }) => {
@@ -82,24 +109,7 @@ cliTest(
.object({ normalized_result: javascriptApplicationAnalysisResultSchema })
.parse(output.json);
const graph = result.semantic_graph;
for (const [name, path, resolution = "resolved"] of [
["declared", ["a"]],
["a", ["a"]],
["plain", ["a", "0"]],
["fallback", ["a", "0"]],
["scalar", ["b"]],
["ordinary", ["0"]],
["arrayAssigned", ["0"]],
["elided", ["1"]],
["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) {
for (const [name, path, resolution = "resolved"] of expectedDependencies) {
const binding = graph.nodes.find(
(node) => node.kind === "binding" && node.label === name,
);