feat(parser): track JSX elements as function calls for intra-file resolution#57
Open
rafalemosmarta wants to merge 1 commit intoharshkedia177:mainfrom
Open
Conversation
…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.
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.
Problem
JSX elements (
<Foo />,<Bar>...</Bar>) are not tracked by the TypeScriptparser 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_elementnodes, notcall_expression, so they were invisibleto the call tracing pipeline.
Solution
Added
_extract_jsx_usage()to the TypeScript parser:jsx_elementandjsx_self_closing_elementin_walk()CallInforecords (same as function calls)<div>,<span>, etc.)<Form.Input />) viareceiverfieldTests
Added 6 test cases covering:
<Foo />)<Foo>...</Foo>)<Ns.Component />)All 25 tests pass (19 existing + 6 new).