Skip to content

fix(health): count TS object-literal shorthand properties as reads#759

Merged
swati510 merged 2 commits into
mainfrom
fix/dataflow-ts-shorthand-reads
Jul 10, 2026
Merged

fix(health): count TS object-literal shorthand properties as reads#759
swati510 merged 2 commits into
mainfrom
fix/dataflow-ts-shorthand-reads

Conversation

@RaghavChamadiya

Copy link
Copy Markdown
Member

Problem

The ts_js def/use dialect classifies only plain identifier nodes as variable reads. It knows shorthand_property_identifier_pattern (the destructuring binder, a def) but never counts shorthand_property_identifier, the object-literal read in { days, limit }. Those reads were invisible to the dataflow layer.

Impact on shipped consumers:

  • Extract Method IN/OUT inference on TS/JS can omit a variable a candidate span consumes via shorthand, producing a wrong parameter list.
  • This violates the documented precision-first contract in defuse.py (unresolvable identifiers are reads).

Concrete repros: packages/api-client/src/graph.ts::getHotFilesGraph reported days and limit as unused parameters even though both are consumed at line 97 via shorthand; same for providers.ts::setActiveProvider (provider) and packages/vscode/src/features/trees/shared.ts::section (key, label).

Fix

Extend the dialect's identifier_kinds with shorthand_property_identifier. Grammar introspection across the typescript, tsx, and javascript packs confirms the non-pattern kind only ever appears in read position (object literals); destructuring binders, including assignment-LHS destructuring, always parse as the _pattern variant. So this adds reads and can never introduce a false def.

Tests

New fixtures in tests/unit/health/test_dataflow_langs.py:

  • shorthand reads in a return object (return { days, limit, payload })
  • LHS destructuring def mixed with RHS shorthand read on the same statement (const { a } = { ...source, b })
  • spread plus shorthand on the plain JS grammar

Full health suite (921 tests) passes with no extract-method golden shifts. Full unit suite passes except the pre-existing test_bundled_changelog_in_sync failure, which is unrelated (bundled changelog drifted on main).

Rerunning the tree-wide dataflow sweep confirms the three shorthand false-positive repros above are gone.

Perf-neutral: the change adds one string to a frozenset consulted in an existing membership check.

The ts_js def/use dialect only knew shorthand_property_identifier_pattern
(the destructuring binder) and never counted shorthand_property_identifier
(an object-literal read like { days, limit }) as a use. Extract Method
IN/OUT inference on TS/JS could therefore omit a variable a candidate span
consumes via shorthand, producing a wrong parameter list, and params_unused
reported false positives for such parameters.

Grammar introspection across the typescript, tsx, and javascript packs
confirms the non-pattern kind never appears in a write-target position, so
extending identifier_kinds adds reads without risking false defs.
@repowise-bot

repowise-bot Bot commented Jul 10, 2026

Copy link
Copy Markdown

✅ Health: 7.7 (unchanged)

📋 At a glance
2 hotspots touched.

Files & modules (2)
  • packages (1 file)
    • .../dialects/ts_js.py
  • tests (1 file)
    • .../health/test_dataflow_langs.py
🔎 More signals (1)

🔥 Hotspots touched (2)

  • .../dialects/ts_js.py — 1 commits/90d, 1 dependents · primary owner: Raghav Chamadiya (100%)
  • .../health/test_dataflow_langs.py — 2 commits/90d, 0 dependents · primary owner: Raghav Chamadiya (100%)

📊 Full report · ⭐ Star Repowise · 📥 Install bot · Last updated 2026-07-10 15:25 UTC
Silence on a single PR with [skip repowise] in the title · Per-repo toggle on repowise.dev/settings?tab=bot

@swati510 swati510 merged commit c6cf775 into main Jul 10, 2026
7 checks passed
@swati510 swati510 deleted the fix/dataflow-ts-shorthand-reads branch July 10, 2026 15:27
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.

2 participants