MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / findCommandNode

Function findCommandNode

source code/utils/bash/parser.ts:140–175  ·  view source on GitHub ↗
(node: Node, parent: Node | null)

Source from the content-addressed store, hash-verified

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

Callers 1

parseCommandFunction · 0.85

Calls 1

hasMethod · 0.45

Tested by

no test coverage detected