Skip to content

Commit afcb9fa

Browse files
committed
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.
1 parent 49e670c commit afcb9fa

3 files changed

Lines changed: 12 additions & 5 deletions

File tree

docs/SEARCH_QUALITY_LOOP.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,8 @@ test().catch(console.error);
448448
| C++ classes/structs/enums missing from macro namespaces | Macros like `NLOHMANN_JSON_NAMESPACE_BEGIN` cause tree-sitter to misparse namespace blocks as `function_definition` | `src/extraction/languages/c-cpp.ts: isMisparsedFunction` filters bad names; `src/extraction/tree-sitter.ts: visitFunctionBody` extracts structural nodes |
449449
| C++ classes missing from `.h` headers | `.h` files default to `c` language which has `classTypes: []` | `src/extraction/grammars.ts: looksLikeCpp()` — content-based heuristic promotes `.h` files to `cpp` when C++ patterns detected |
450450
| Ruby methods inside modules missing owner in `qualified_name` | Ruby `module` AST nodes not being extracted | `src/extraction/languages/ruby.ts: visitNode` hook extracts modules; `src/extraction/tree-sitter.ts: isInsideClassLikeNode` includes `module` kind |
451+
| TypeScript abstract classes missing | `abstract_class_declaration` not in `classTypes` | `src/extraction/languages/typescript.ts: classTypes` — add `abstract_class_declaration` |
452+
| Single-expression arrow functions silently dropped | `extractName` finds identifier in expression body instead of returning `<anonymous>` | `src/extraction/tree-sitter.ts: extractName` — skip identifier search for `arrow_function`/`function_expression` nodes |
451453

452454
## After Fixing Issues
453455

@@ -531,13 +533,10 @@ if (receiverType) {
531533
- [x] **C++** — NOT needed for header-only libs. `isMisparsedFunction` hook filters macro-caused misparse artifacts (e.g. `NLOHMANN_JSON_NAMESPACE_BEGIN`). `visitFunctionBody` now extracts structural nodes (classes/structs/enums) inside macro-confused "function" bodies. Content-based `.h` detection (`looksLikeCpp` in `grammars.ts`) promotes C++ headers to `cpp` language so classes in `.h` files are extracted. Verified against nlohmann/json and gRPC. Note: out-of-class `Type::method()` definitions would need `getReceiverType` but are uncommon in header-only codebases.
532534
- [x] **C#** — NOT needed. Methods nested in class body. Added `base_list` handling in `extractInheritance` for C#'s `: Parent, IInterface` syntax. Added `propertyTypes` support for C# `property_declaration` nodes. Fixed `extractField` to handle C#'s nested `variable_declaration > variable_declarator` structure. Verified against Jellyfin
533535
- [x] **Ruby** — NOT needed for `getReceiverType`. Methods nested in class body. Added `visitNode` hook to extract Ruby `module` nodes (concerns, namespaces) with proper containment and qualified names. Methods inside modules get `Module::method` qualified names. Also wired up the `ExtractorContext` with `pushScope`/`popScope` for language hooks. Verified against Discourse
536+
- [x] **TypeScript** — NOT needed for `getReceiverType`. Methods nested in class body. Added `abstract_class_declaration` to `classTypes` so abstract classes are properly extracted. Fixed single-expression arrow function extraction (`const fn = () => expr` was silently dropped because `extractName` picked up the body identifier instead of returning `<anonymous>` for parent name resolution). Verified against Grafana
534537

535538
### Needs Verification
536539

537540
Check these — may need `getReceiverType` if methods are top-level in the AST:
538541

539542
- [ ] Kotlin — extension functions `fun Type.method()`
540-
541-
Verify these DON'T need `getReceiverType` (methods nested in class body):
542-
543-
- [ ] TypeScript

src/extraction/languages/typescript.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { LanguageExtractor } from '../tree-sitter-types';
33

44
export const typescriptExtractor: LanguageExtractor = {
55
functionTypes: ['function_declaration', 'arrow_function', 'function_expression'],
6-
classTypes: ['class_declaration'],
6+
classTypes: ['class_declaration', 'abstract_class_declaration'],
77
methodTypes: ['method_definition', 'public_field_definition'],
88
interfaceTypes: ['interface_declaration'],
99
structTypes: [],

src/extraction/tree-sitter.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ function extractName(node: SyntaxNode, source: string, extractor: LanguageExtrac
7070
}
7171
}
7272

73+
// Arrow/function expressions get their name from the parent variable_declarator,
74+
// not from identifiers in their body. Without this, single-expression arrow
75+
// functions like `const fn = () => someIdentifier` get named "someIdentifier"
76+
// instead of "fn", because the fallback below finds the body identifier.
77+
if (node.type === 'arrow_function' || node.type === 'function_expression') {
78+
return '<anonymous>';
79+
}
80+
7381
// Fall back to first identifier child
7482
for (let i = 0; i < node.namedChildCount; i++) {
7583
const child = node.namedChild(i);

0 commit comments

Comments
 (0)