| 69 | const result: WFNode[] = [] |
| 70 | |
| 71 | const visit = (id: string): void => { |
| 72 | if (visited.has(id)) return |
| 73 | for (const e of edges) { |
| 74 | if (e.target === id && !visited.has(e.source) && nodeMap.has(e.source)) return |
| 75 | } |
| 76 | const node = nodeMap.get(id) |
| 77 | if (!node) return |
| 78 | visited.add(id) |
| 79 | result.push(node) |
| 80 | for (const childId of adj.get(id) ?? []) visit(childId) |
| 81 | } |
| 82 | |
| 83 | for (const node of nodes) if ((inDeg.get(node.id) ?? 0) === 0) visit(node.id) |
| 84 | for (const node of nodes) if (!visited.has(node.id)) visit(node.id) |