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

Function walkTopLevel

source code/utils/bash/treeSitterAnalysis.ts:310–396  ·  view source on GitHub ↗
(node: TreeSitterNode)

Source from the content-addressed store, hash-verified

308
309 // Walk top-level children of the program node
310 function walkTopLevel(node: TreeSitterNode): void {
311 for (const child of node.children) {
312 if (!child) continue
313
314 if (child.type === 'list') {
315 // list nodes contain && and || operators
316 for (const listChild of child.children) {
317 if (!listChild) continue
318 if (listChild.type === '&&' || listChild.type === '||') {
319 operators.push(listChild.type)
320 } else if (
321 listChild.type === 'list' ||
322 listChild.type === 'redirected_statement'
323 ) {
324 // Nested list, or redirected_statement wrapping a list/pipeline —
325 // recurse so inner operators/pipelines are detected. For
326 // `cmd1 && cmd2 2>/dev/null && cmd3`, the redirected_statement
327 // wraps `list(cmd1 && cmd2)` — the inner `&&` would be missed
328 // without recursion.
329 walkTopLevel({ ...node, children: [listChild] } as TreeSitterNode)
330 } else if (listChild.type === 'pipeline') {
331 hasPipeline = true
332 segments.push(listChild.text)
333 } else if (listChild.type === 'subshell') {
334 hasSubshell = true
335 segments.push(listChild.text)
336 } else if (listChild.type === 'compound_statement') {
337 hasCommandGroup = true
338 segments.push(listChild.text)
339 } else {
340 segments.push(listChild.text)
341 }
342 }
343 } else if (child.type === ';') {
344 operators.push(';')
345 } else if (child.type === 'pipeline') {
346 hasPipeline = true
347 segments.push(child.text)
348 } else if (child.type === 'subshell') {
349 hasSubshell = true
350 segments.push(child.text)
351 } else if (child.type === 'compound_statement') {
352 hasCommandGroup = true
353 segments.push(child.text)
354 } else if (
355 child.type === 'command' ||
356 child.type === 'declaration_command' ||
357 child.type === 'variable_assignment'
358 ) {
359 segments.push(child.text)
360 } else if (child.type === 'redirected_statement') {
361 // `cd ~/src && find path 2>/dev/null` — tree-sitter wraps the ENTIRE
362 // compound in a redirected_statement: program → redirected_statement →
363 // (list → cmd1, &&, cmd2) + file_redirect. Same for `cmd1 | cmd2 > out`
364 // (wraps pipeline) and `(cmd) > out` (wraps subshell). Recurse to
365 // detect the inner structure; skip file_redirect children (redirects
366 // don't affect compound/pipeline classification).
367 let foundInner = false

Callers 1

extractCompoundStructureFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected