What one recorded site draws as.
(input: ProgramInput, site: ProgramSite, path: readonly string[], state: Reading)
| 263 | |
| 264 | /** What one recorded site draws as. */ |
| 265 | function itemFor(input: ProgramInput, site: ProgramSite, path: readonly string[], state: Reading): WireItem | null { |
| 266 | if (site.into) { |
| 267 | // A helper the walk folded: drawn where it is called, its own body inside. |
| 268 | const via = input.node(site.into); |
| 269 | const block: Extract<WireItem, { kind: 'block' }> = { |
| 270 | kind: 'block', |
| 271 | block: 'inline', |
| 272 | ...(via ? { via } : {}), |
| 273 | ...(site.within ? { within: site.within } : {}), |
| 274 | body: [], |
| 275 | }; |
| 276 | if (!open(site.into, path, state)) { |
| 277 | block.again = true; |
| 278 | return block; |
| 279 | } |
| 280 | block.body = blockFor(input, site.into, [...path, site.into], state); |
| 281 | return block.body.length === 0 ? null : block; |
| 282 | } |
| 283 | if (!site.step) return null; |
| 284 | const step = input.step(site.step); |
| 285 | const item: Extract<WireItem, { kind: 'step' }> = { |
| 286 | kind: 'step', |
| 287 | step: site.step, |
| 288 | ...(site.link ? { link: site.link } : {}), |
| 289 | ...(site.within ? { within: site.within } : {}), |
| 290 | }; |
| 291 | // A step the walk entered reads on into what it does — the same steps the |
| 292 | // tree draws a row below, here under the box that reaches them. |
| 293 | if (step?.into) { |
| 294 | if (open(step.into, path, state)) { |
| 295 | const body = blockFor(input, step.into, [...path, step.into], state); |
| 296 | if (body.length > 0) item.body = body; |
| 297 | } else if (input.sites.has(step.into)) item.again = true; |
| 298 | } |
| 299 | return item; |
| 300 | } |
| 301 | |
| 302 | /** |
| 303 | * Whether this reading may open a function's body here: not if it is already |