(id: string)
| 947 | const stack: string[] = [] |
| 948 | |
| 949 | const dfs = (id: string): string[] | null => { |
| 950 | if (state.get(id) === VISITED) return null |
| 951 | if (state.get(id) === VISITING) { |
| 952 | const cycleStart = stack.indexOf(id) |
| 953 | return cycleStart >= 0 ? [...stack.slice(cycleStart), id] : [id] |
| 954 | } |
| 955 | state.set(id, VISITING) |
| 956 | stack.push(id) |
| 957 | for (const next of adjacency.get(id) ?? []) { |
| 958 | const found = dfs(next) |
| 959 | if (found) return found |
| 960 | } |
| 961 | stack.pop() |
| 962 | state.set(id, VISITED) |
| 963 | return null |
| 964 | } |
| 965 | |
| 966 | for (const g of groups) { |
| 967 | const cycle = dfs(g.id) |
no test coverage detected