MCPcopy Create free account
hub / github.com/claude-code-best/claude-code / walkProgram

Function walkProgram

src/utils/bash/ast.ts:463–477  ·  view source on GitHub ↗
(root: Node)

Source from the content-addressed store, hash-verified

461}
462
463function walkProgram(root: Node): ParseForSecurityResult {
464 // ERROR-node check folded into collectCommands — any unhandled node type
465 // (including ERROR) falls through to tooComplex() in the default branch.
466 // Avoids a separate full-tree walk for error detection.
467 const commands: SimpleCommand[] = []
468 // Track variables assigned earlier in the same command. When a
469 // simple_expansion ($VAR) references a tracked var, we can substitute
470 // a placeholder instead of returning too-complex. Enables patterns like
471 // `NOW=$(date) && jq --arg now "$NOW" ...` — $NOW is known to be the
472 // $(date) output (already extracted as inner command).
473 const varScope = new Map<string, string>()
474 const err = collectCommands(root, commands, varScope)
475 if (err) return err
476 return { kind: 'simple', commands }
477}
478
479/**
480 * Recursively collect leaf `command` nodes from a structural wrapper node.

Callers 1

parseForSecurityFromAstFunction · 0.85

Calls 1

collectCommandsFunction · 0.85

Tested by

no test coverage detected