The shape of a block, one line per item, indented — what a reader would see.
(block: WireBlock, indent = '')
| 51 | |
| 52 | /** The shape of a block, one line per item, indented — what a reader would see. */ |
| 53 | function shape(block: WireBlock, indent = ''): string[] { |
| 54 | const out: string[] = []; |
| 55 | for (const item of block) { |
| 56 | if (item.kind === 'step') { |
| 57 | out.push(`${indent}${item.step}${item.again ? ' (again)' : ''}${item.within ? ` inside ${item.within}` : ''}`); |
| 58 | if (item.body) out.push(...shape(item.body, `${indent} `)); |
| 59 | } else if (item.kind === 'fork') { |
| 60 | out.push(`${indent}${item.form} ${item.on}`); |
| 61 | for (const arm of item.arms) { |
| 62 | out.push(`${indent} arm ${arm.when}${arm.ends ? ` ends:${arm.ends}` : ''}`); |
| 63 | out.push(...shape(arm.body, `${indent} `)); |
| 64 | } |
| 65 | } else if (item.kind === 'block') { |
| 66 | out.push(`${indent}${item.block}${item.via ? ` via ${item.via.name}` : item.by ? ` ${item.by}` : ''}${item.again ? ' (again)' : ''}`); |
| 67 | out.push(...shape(item.body, `${indent} `)); |
| 68 | } else out.push(`${indent}cut ${item.why}`); |
| 69 | } |
| 70 | return out; |
| 71 | } |
| 72 | |
| 73 | /* --------------------------------------------------------------- tests -- */ |
| 74 |
no test coverage detected