(loop: Loop | null | undefined)
| 112 | * @returns Normalized loop with only relevant fields |
| 113 | */ |
| 114 | export function normalizeLoop(loop: Loop | null | undefined): NormalizedLoop | null | undefined { |
| 115 | if (!loop) return undefined // Normalize null to undefined |
| 116 | const { id, nodes, loopType, iterations, forEachItems, whileCondition, doWhileCondition } = loop |
| 117 | |
| 118 | // Sort nodes for consistent comparison (execution order is determined by edges, not array order) |
| 119 | const sortedNodes = [...nodes].sort() |
| 120 | const base: NormalizedLoop = { id, nodes: sortedNodes, loopType } |
| 121 | |
| 122 | // Only add optional fields if they have non-null/undefined values |
| 123 | switch (loopType) { |
| 124 | case 'for': |
| 125 | if (iterations != null) base.iterations = iterations |
| 126 | break |
| 127 | case 'forEach': |
| 128 | if (forEachItems != null) base.forEachItems = forEachItems |
| 129 | break |
| 130 | case 'while': |
| 131 | if (whileCondition != null) base.whileCondition = whileCondition |
| 132 | break |
| 133 | case 'doWhile': |
| 134 | if (doWhileCondition != null) base.doWhileCondition = doWhileCondition |
| 135 | break |
| 136 | } |
| 137 | |
| 138 | return base |
| 139 | } |
| 140 | |
| 141 | /** Normalized parallel result type with only essential fields */ |
| 142 | interface NormalizedParallel { |
no outgoing calls
no test coverage detected