( tree: ConfigInternal.Tree, results: ReadonlyArray<any> )
| 238 | * @internal |
| 239 | */ |
| 240 | export const reconstructTree = ( |
| 241 | tree: ConfigInternal.Tree, |
| 242 | results: ReadonlyArray<any> |
| 243 | ): Record<string, any> => { |
| 244 | const output: Record<string, any> = {} |
| 245 | |
| 246 | for (const key of Object.keys(tree)) { |
| 247 | InternalRecord.assignProperty(output, key, nodeValue(tree[key])) |
| 248 | } |
| 249 | |
| 250 | return output |
| 251 | |
| 252 | function nodeValue(node: ConfigInternal.Node): any { |
| 253 | switch (node._tag) { |
| 254 | case "Param": |
| 255 | return results[node.index] |
| 256 | case "Array": |
| 257 | return node.children.map((child) => nodeValue(child)) |
| 258 | case "Nested": |
| 259 | return reconstructTree(node.tree, results) |
| 260 | } |
| 261 | } |
| 262 | } |
no test coverage detected