Files
tsgo/testdata/tests/cases/compiler/circularControlFlowNarrowingWithCurrentElement01.ts
7919c9a7eb Add CFA regression test for while loop with continue statements (#1325)
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: DanielRosenwasser <[email protected]>
Co-authored-by: Daniel Rosenwasser <[email protected]>
2025-07-07 21:05:41 +00:00

40 lines
684 B
TypeScript

// @strict: true
// @noEmit: true
class A {
next: A | null = null;
constructor(readonly children: (A | null)[]) {}
}
function getNodes(): A[] {
const out: A[] = [];
let current: A | null = new A([]);
while (current !== null) {
let firstChild = null;
if (out.length) {
current = current.next;
continue;
}
for (let i = 0; i < current.children.length; i++) {
const child = current.children[i];
if (child) {
if (!firstChild) {
firstChild = child;
firstChild.next = current.next;
}
child.next = current.next;
}
}
current = firstChild || current.next;
}
return out;
}