feat(typescript): index arrow functions and type aliases - #73
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The TypeScript query set covered
class,interface,functionandmethoddeclarations. Two very common declarations matched nothing at all, so those
symbols never entered the graph and
goto/refs/callerscould not seethem:
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
Changes
Two queries in
services/parsing/typescript.py:arrow_function_defslexical_declaration→variable_declaratorholding anarrow_functionorfunction_expressionFunctiontype_alias_defstype_alias_declarationInterfacefunction_expressionis included soconst f = function () {}behaves thesame. A type alias is indexed as
Interfacebecause it names a type the sameway an interface does and there is no dedicated
NodeKind— happy to add oneif 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:
The grammar exposes them through the existing
class_declaration,function_declarationandmethod_definitionnodes — type parameters anddecorators sit alongside the name rather than wrapping it, so the current
queries already bind
@name. I left the tests in as regression guards so afuture query change cannot quietly drop them, but no production code was needed.
Flagging that explicitly rather than claiming to have fixed four things.
Checklist
pytest tests/ -v)ast-rag evaluate --all— needs the summarizer LLM, not runTesting
11 new tests in
tests/test_typescript_queries.py, covering all fourcategories from the issue plus a no-regression case. On
mainwith the sourcereverted, the six that matter fail:
The 5 that pass without the fix are the generics/decorator guards — which is
the evidence for the paragraph above.
main@ 41e48af)Note on ordering
Independent of #70, #71 and #72 — different files, merge in any order.