spacehub

surshar / claude-code

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

Built by Anthropic · github.com/anthropics

claude-code / mods / diff / tests / fixtures / tree / codes-in.ts
20 lines · 538 BRaw
1import type { CodeProps, RenderNode } from 'claude-code'
2
3/**
4 * The props of every `Code` under a rendered tree node, depth-first in
5 * drawing order.
6 *
7 * @param node an element or a string
8 * @returns the Code props
9 */
10export function codesIn(node: RenderNode): CodeProps[] {
11 const isText = typeof node === 'string'
12 const isCode = !isText && node.type === 'Code'
13 const hasChildren = !isText && 'children' in node
14
15 return isCode
16 ? [node.props]
17 : hasChildren
18 ? (node.children ?? []).flatMap(codesIn)
19 : []
20}