Skip to content

fix: map .tsx files to tsx grammar instead of typescript#22

Open
rishal-raj wants to merge 1 commit into
Aider-AI:mainfrom
rishal-raj:fix/tsx-grammar
Open

fix: map .tsx files to tsx grammar instead of typescript#22
rishal-raj wants to merge 1 commit into
Aider-AI:mainfrom
rishal-raj:fix/tsx-grammar

Conversation

@rishal-raj

@rishal-raj rishal-raj commented Jun 28, 2026

Copy link
Copy Markdown

.tsx files contain JSX syntax which the typescript tree-sitter grammar cannot parse, resulting in 25+ parse errors per file and dropped symbols in the repo map. The tsx grammar is a strict superset of typescript and handles both correctly (0 errors vs 25 on real-world TSX files).

.ts files are unchanged and continue to use the typescript grammar.

Fixes #21

.tsx files contain JSX syntax which the typescript tree-sitter grammar
cannot parse, resulting in 25+ parse errors per file and dropped symbols
in the repo map. The tsx grammar is a strict superset of typescript and
handles both correctly (0 errors vs 25 on real-world TSX files).

.ts files are unchanged and continue to use the typescript grammar.
@rishal-raj

rishal-raj commented Jun 28, 2026

Copy link
Copy Markdown
Author

aider is still not able to parse and build the repomap correctly, and needs another fix for this to work because

There's a typescript-tags.scm but no tsx-tags.scm. When the grammar is now tsx, aider looks for tsx-tags.scm, finds nothing, and extracts 0 tags
And also,
The query captures function_declaration and class_declaration but not variable_declarator — which is how all React components are written (export const HealthBadge = ...). Arrow function components are completely invisible to this query, and that's a separate issue from the .tsx grammar mapping.

The grammar fix (tsx vs typescript) correctly parses JSX with 0 errors, but the SCM query doesn't know to look for arrow-function-style component definitions. That's a query gap that exists for .ts files too, not just .tsx.

To fix it properly, the tsx-tags.scm (or typescript-tags.scm) needs an additional pattern like:

(variable_declarator
name: (identifier) @name.definition.function
value: [(arrow_function) (function)]) @definition.function

That would capture export const HealthBadge = ({ score }) => ..., export const KPICard = ..., etc. This is a genuine query enhancement — it would need to go into aider as a new or updated SCM file, and also be tested against .ts files to make sure it doesn't produce false positives (e.g. capturing every const x = () => not just exported ones).

The exported-only version would need:

(export_statement
(lexical_declaration
(variable_declarator
name: (identifier) @name.definition.function
value: [(arrow_function) (function)]))) @definition.function

This would have to be a change in the aider repository

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: .tsx files are hardcoded to "typescript" parser in parsers.py, causing Tree-sitter parsing failures

1 participant