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

Function readBlockHeader

src/extraction/languages/terraform.ts:51–70  ·  view source on GitHub ↗

Block "type" and its label values. Returns null if the block is malformed.

(block: SyntaxNode, source: string)

Source from the content-addressed store, hash-verified

49
50/** Block "type" and its label values. Returns null if the block is malformed. */
51function readBlockHeader(block: SyntaxNode, source: string): { type: string; labels: string[] } | null {
52 const named = block.namedChildren.filter((c): c is SyntaxNode => c !== null);
53 const first = named[0];
54 if (!first || first.type !== 'identifier') return null;
55 const type = getNodeText(first, source);
56 const labels: string[] = [];
57 for (let i = 1; i < named.length; i++) {
58 const child = named[i];
59 if (!child) continue;
60 if (child.type === 'string_lit') {
61 labels.push(stringLitValue(child, source));
62 } else if (child.type === 'identifier') {
63 // HCL allows unquoted identifier labels (rare in Terraform but legal).
64 labels.push(getNodeText(child, source));
65 } else {
66 break;
67 }
68 }
69 return { type, labels };
70}
71
72/** Find the `body` child of a block (it's after the labels and block_start). */
73function getBlockBody(block: SyntaxNode): SyntaxNode | null {

Callers 1

terraform.tsFile · 0.85

Calls 2

getNodeTextFunction · 0.90
stringLitValueFunction · 0.85

Tested by

no test coverage detected