Skip to content

feat(typescript): index arrow functions and type aliases - #73

Merged
lexasub merged 1 commit into
mainfrom
feat/typescript-queries
Aug 9, 2026
Merged

feat(typescript): index arrow functions and type aliases#73
lexasub merged 1 commit into
mainfrom
feat/typescript-queries

Conversation

@r0h1tb

@r0h1tb r0h1tb commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

Description

The TypeScript query set covered class, interface, function and method
declarations. Two very common declarations matched nothing at all, so those
symbols never entered the graph and goto / refs / callers could not see
them:

export const add = (a: number, b: number): number => a + b;   // not indexed
type UserId = string;                                          // not indexed

Arrow functions matter most here — in a lot of TypeScript codebases that is how
every function is declared, so those files were effectively contributing
classes and nothing else.

Related Issue

Fixes #16

Type of Change

  • Bug fix
  • New feature (non-breaking change that adds functionality)
  • Breaking change
  • Documentation update

Changes

Two queries in services/parsing/typescript.py:

query matches indexed as
arrow_function_defs lexical_declarationvariable_declarator holding an arrow_function or function_expression Function
type_alias_defs type_alias_declaration Interface

function_expression is included so const f = function () {} behaves the
same. A type alias is indexed as Interface because it names a type the same
way an interface does and there is no dedicated NodeKind — happy to add one
if you would rather they were distinguishable.

Only two of the four listed gaps were real

The issue lists arrow functions, type aliases, generic types and decorators.
Generics and decorators already work. I checked before writing anything:

class Box<T> { ... }          // extracted
function identity<T>(v: T) {} // extracted
@Component({...})
export class AppComponent {}  // extracted
@HostListener("click")
onClick(): void {}            // extracted

The grammar exposes them through the existing class_declaration,
function_declaration and method_definition nodes — type parameters and
decorators sit alongside the name rather than wrapping it, so the current
queries already bind @name. I left the tests in as regression guards so a
future query change cannot quietly drop them, but no production code was needed.

Flagging that explicitly rather than claiming to have fixed four things.

Checklist

  • My code follows the code style of this project
  • I have added tests that prove my feature works
  • All new and existing tests passed (pytest tests/ -v)
  • I have updated the documentation accordingly (comments)
  • I have run ast-rag evaluate --all — needs the summarizer LLM, not run
  • My changes generate no new warnings

Testing

11 new tests in tests/test_typescript_queries.py, covering all four
categories from the issue plus a no-regression case. On main with the source
reverted, the six that matter fail:

$ git stash -- ast_rag/
$ pytest tests/test_typescript_queries.py -q
FAILED TestArrowFunctions::test_const_arrow_function_is_extracted
FAILED TestArrowFunctions::test_async_arrow_function_is_extracted
FAILED TestArrowFunctions::test_arrow_function_is_a_function_kind
FAILED TestTypeAliases::test_simple_type_alias_is_extracted
FAILED TestTypeAliases::test_type_alias_is_indexed_as_a_named_type
FAILED TestTypeAliases::test_generic_type_alias_is_extracted
6 failed, 5 passed

The 5 that pass without the fix are the generics/decorator guards — which is
the evidence for the paragraph above.

passed failed skipped xfailed
baseline (main @ 41e48af) 232 0 1 1
this branch 243 0 1 1
$ ruff check ast_rag/            # All checks passed!
$ ruff format --check ast_rag/ tests/   # 88 files already formatted

Note on ordering

Independent of #70, #71 and #72 — different files, merge in any order.

The TypeScript query set covered class, interface, function and method
declarations. `const add = (a, b) => a + b` -- how most TypeScript code
declares a function -- and `type UserId = string` matched nothing, so those
symbols were absent from the graph entirely and goto, refs and callers could
not see them.

Adds two queries:

- arrow_function_defs: a lexical_declaration whose variable_declarator holds
  an arrow_function or function_expression, indexed as Function so it behaves
  like any other callable
- type_alias_defs: type_alias_declaration, indexed as Interface -- it names a
  type in the same way, and there is no dedicated NodeKind

Only two of the four gaps listed on the issue turned out to be real. Generic
classes/functions and decorated classes/methods already extract correctly,
because the grammar exposes them through the existing class_declaration,
function_declaration and method_definition nodes -- the type parameters and
decorators sit alongside the name rather than wrapping it. Tests cover them
anyway so a future query change cannot quietly drop them.
@r0h1tb
r0h1tb requested a review from lexasub as a code owner August 8, 2026 20:13
@github-project-automation github-project-automation Bot moved this to Backlog in raged kanban Aug 8, 2026
@lexasub
lexasub merged commit 14327eb into main Aug 9, 2026
1 check passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in raged kanban Aug 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Improve TypeScript Support

2 participants