| 137 | } |
| 138 | |
| 139 | function extractName(node: TSNode, _kind: string): string { |
| 140 | const nameNode = node.childForFieldName("name") |
| 141 | ?? node.childForFieldName("declarator") |
| 142 | ?? node.namedChildren?.find((c: TSNode) => |
| 143 | c.type === "identifier" || c.type === "type_identifier" |
| 144 | || c.type === "property_identifier" || c.type === "simple_identifier" |
| 145 | ); |
| 146 | |
| 147 | if (nameNode) { |
| 148 | if (nameNode.type === "function_declarator" || nameNode.type === "pointer_declarator") { |
| 149 | const inner = nameNode.childForFieldName("declarator") ?? nameNode.namedChildren?.[0]; |
| 150 | if (inner) return inner.text; |
| 151 | } |
| 152 | return nameNode.text; |
| 153 | } |
| 154 | |
| 155 | for (const child of node.namedChildren ?? []) { |
| 156 | if (child.type === "variable_declarator" || child.type === "const_declaration") { |
| 157 | const inner = child.childForFieldName("name"); |
| 158 | if (inner) return inner.text; |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | return node.text.split(/[\s({]/)[0]?.trim() ?? "anonymous"; |
| 163 | } |
| 164 | |
| 165 | function extractSignature(node: TSNode): string { |
| 166 | const lines = node.text.split("\n"); |