MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / shape

Function shape

__tests__/ui-steps-program.test.ts:53–71  ·  view source on GitHub ↗

The shape of a block, one line per item, indented — what a reader would see.

(block: WireBlock, indent = '')

Source from the content-addressed store, hash-verified

51
52/** The shape of a block, one line per item, indented — what a reader would see. */
53function 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

Callers 1

Calls 1

pushMethod · 0.80

Tested by

no test coverage detected