feat: Add TypeScript abstract class extraction and fix arrow function naming
Addresses TypeScript abstract classes missing by adding abstract_class_declaration to classTypes. Fixes single-expression arrow functions being silently dropped by preventing extractName from searching identifiers in arrow_function/function_expression bodies, ensuring they return for proper parent name resolution instead of incorrectly using body identifiers.
This commit is contained in:
@@ -3,7 +3,7 @@ import type { LanguageExtractor } from '../tree-sitter-types';
|
||||
|
||||
export const typescriptExtractor: LanguageExtractor = {
|
||||
functionTypes: ['function_declaration', 'arrow_function', 'function_expression'],
|
||||
classTypes: ['class_declaration'],
|
||||
classTypes: ['class_declaration', 'abstract_class_declaration'],
|
||||
methodTypes: ['method_definition', 'public_field_definition'],
|
||||
interfaceTypes: ['interface_declaration'],
|
||||
structTypes: [],
|
||||
|
||||
@@ -70,6 +70,14 @@ function extractName(node: SyntaxNode, source: string, extractor: LanguageExtrac
|
||||
}
|
||||
}
|
||||
|
||||
// Arrow/function expressions get their name from the parent variable_declarator,
|
||||
// not from identifiers in their body. Without this, single-expression arrow
|
||||
// functions like `const fn = () => someIdentifier` get named "someIdentifier"
|
||||
// instead of "fn", because the fallback below finds the body identifier.
|
||||
if (node.type === 'arrow_function' || node.type === 'function_expression') {
|
||||
return '<anonymous>';
|
||||
}
|
||||
|
||||
// Fall back to first identifier child
|
||||
for (let i = 0; i < node.namedChildCount; i++) {
|
||||
const child = node.namedChild(i);
|
||||
|
||||
Reference in New Issue
Block a user