MCPcopy Index your code
hub / github.com/claude-code-best/claude-code / findCommandNode

Function findCommandNode

src/utils/bash/parser.ts:138–173  ·  view source on GitHub ↗
(node: Node, parent: Node | null)

Source from the content-addressed store, hash-verified

136}
137
138function findCommandNode(node: Node, parent: Node | null): Node | null {
139 const { type, children } = node
140
141 if (COMMAND_TYPES.has(type)) return node
142
143 // Variable assignment followed by command
144 if (type === 'variable_assignment' && parent) {
145 return (
146 parent.children.find(
147 c => COMMAND_TYPES.has(c.type) && c.startIndex > node.startIndex,
148 ) ?? null
149 )
150 }
151
152 // Pipeline: recurse into first child (which may be a redirected_statement)
153 if (type === 'pipeline') {
154 for (const child of children) {
155 const result = findCommandNode(child, node)
156 if (result) return result
157 }
158 return null
159 }
160
161 // Redirected statement: find the command inside
162 if (type === 'redirected_statement') {
163 return children.find(c => COMMAND_TYPES.has(c.type)) ?? null
164 }
165
166 // Recursive search
167 for (const child of children) {
168 const result = findCommandNode(child, node)
169 if (result) return result
170 }
171
172 return null
173}
174
175function extractEnvVars(commandNode: Node | null): string[] {
176 if (!commandNode || commandNode.type !== 'command') return []

Callers 1

parseCommandFunction · 0.85

Calls 1

hasMethod · 0.45

Tested by

no test coverage detected