Skip to content

feat(parser): track JSX elements as function calls for intra-file resolution#57

Open
rafalemosmarta wants to merge 1 commit intoharshkedia177:mainfrom
almanova-tech:feat/jsx-intra-file-tracking
Open

feat(parser): track JSX elements as function calls for intra-file resolution#57
rafalemosmarta wants to merge 1 commit intoharshkedia177:mainfrom
almanova-tech:feat/jsx-intra-file-tracking

Conversation

@rafalemosmarta
Copy link
Copy Markdown

Problem

JSX elements (<Foo />, <Bar>...</Bar>) are not tracked by the TypeScript
parser as function calls. This causes false positive dead code reports for
React components defined and used within the same file — a very common pattern
in TSX codebases.

The root cause is that tree-sitter models JSX tags as jsx_element /
jsx_self_closing_element nodes, not call_expression, so they were invisible
to the call tracing pipeline.

Solution

Added _extract_jsx_usage() to the TypeScript parser:

  • Dispatches on jsx_element and jsx_self_closing_element in _walk()
  • Converts uppercase tag names to CallInfo records (same as function calls)
  • Skips native HTML tags (lowercase: <div>, <span>, etc.)
  • Supports dotted components (<Form.Input />) via receiver field

Tests

Added 6 test cases covering:

  • Self-closing elements (<Foo />)
  • Opening/closing elements (<Foo>...</Foo>)
  • HTML tag filtering (lowercase skipped)
  • Dotted components (<Ns.Component />)
  • Nested components
  • Mixed JSX + regular function calls

All 25 tests pass (19 existing + 6 new).

…olution

JSX elements (<Foo />, <Bar>...</Bar>) were not being tracked by the
TypeScript parser, causing false positive dead code reports for React
components used within the same file. This is because tree-sitter
models JSX tags as jsx_element / jsx_self_closing_element nodes rather
than call_expression nodes.

Changes:
- Add _extract_jsx_usage() to TypeScriptParser that converts JSX
  element nodes into CallInfo records
- Dispatch jsx_element and jsx_self_closing_element in _walk()
- Skip native HTML tags (lowercase like <div>, <span>)
- Support dotted components (<Ns.Component />) via receiver field
- Add 6 comprehensive test cases covering all JSX patterns

This fixes dead code false positives for any React/TSX codebase where
components are defined and used within the same file.
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.

1 participant