MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / loopHeader

Function loopHeader

src/graph/branch-guards.ts:1047–1058  ·  view source on GitHub ↗

A loop's header as written, keyword and braces dropped: `item of items`, `queue.length > 0`.

(loop: SyntaxNode)

Source from the content-addressed store, hash-verified

1045
1046/** A loop's header as written, keyword and braces dropped: `item of items`, `queue.length > 0`. */
1047function loopHeader(loop: SyntaxNode): string {
1048 const body = loop.childForFieldName('body') ?? namedChildren(loop).find((c) => BLOCKISH.has(c.type)) ?? null;
1049 const raw = body && body.startIndex > loop.startIndex ? loop.text.slice(0, body.startIndex - loop.startIndex) : loop.text;
1050 let text = raw.replace(/\s+/g, ' ').trim();
1051 text = text.replace(/^(?:for|foreach|while|do|repeat)\b\s*/i, '');
1052 text = text.replace(/[{:]\s*$/, '').trim();
1053 const inner = /^\((.*)\)$/s.exec(text);
1054 if (inner) text = inner[1]!.trim();
1055 // `const item of items` reads as `item of items`; the binding word is noise here.
1056 text = text.replace(/^(?:const|let|var|val|final)\s+/, '');
1057 return cut(text, 60);
1058}
1059
1060/**
1061 * The walk. `line` is 1-based, `column` 0-based (null → first non-blank).

Callers 1

loopsInTreeFunction · 0.85

Calls 4

namedChildrenFunction · 0.85
cutFunction · 0.85
hasMethod · 0.80
execMethod · 0.65

Tested by

no test coverage detected