fix(dead-code): count JSX prop function references as usage (closes #294)#295
Merged
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
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.



Root cause
.tsxfiles are parsed byparsers/tsx_parser.py(TSXParser, routed fromcommands/scan.py:711) — NOTts_backend_parser.py. Its tree walk emitted CALLS edges only forcall_expression/new_expression/ JSX component elements. A function passed as a JSX prop value (onClick={handleClick}) is a bare identifier inside ajsx_expressioncontainer — a reference, not a call — so it produced zero edges.ref_countis computed from incoming edges, so every React event handler gotrc=0/status=dead(mass false-positive on the primary React use case).Fix
scripts/parsers/tsx_parser.py— new_process_jsx_expression, dispatched from the tree walk onjsx_expressionnodes. It emits a usage edge (via_jsx_ref) from the enclosing function to a referenced name, but ONLY when that name resolves to a function declared in the same file (declaredguard) — arbitrary identifiers / DOM props / non-function names are never counted. Two shapes handled:onClick={handleClick}(direct identifier).{items.map(renderItem)}(identifier in a call'sarguments).Double-counting avoided: the
functionposition of acall_expressionis skipped (already emitted by_parse_call), nestedjsx_expressionnodes are left to the outer walk, andmember_expression(items.map,this.x) is skipped.Before / after (repro from the issue)
onClick={handleClick})onSubmit={handleSubmit}){items.map(renderItem)})directlyCalled())Tests
Added 4 golden assertions + a
App.tsxfixture totests/test_graph_accuracy_golden.py: JSX-prop handler rc>=1, callback-arg rc>=1, direct-call not regressed, genuinely-unused handler still dead.Wide-net run (all pass):
Also green:
test_ts_backend_parser.py,test_js_backend_parser.py.🤖 Generated with Claude Code