Skip to content

fix: recover chained TS decorators and report the lossy parse region (#4711) - #4715

Closed
Deepjyoti-Sarmah wants to merge 2 commits into
Graphify-Labs:v8from
Deepjyoti-Sarmah:fix/4711-ts-decorator-chain
Closed

Deepjyoti-Sarmah wants to merge 2 commits into
Graphify-Labs:v8from
Deepjyoti-Sarmah:fix/4711-ts-decorator-chain

Conversation

@Deepjyoti-Sarmah

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes #4711. A TypeScript decorator whose expression is a call chain (@(Link().toMany())) contributed no references edge to the graph, and the partial-parse warning pointed at a line that was not the one costing extraction.

tree-sitter-typescript 0.23.2 cannot parse a member access on a call in decorator position. @Link().toMany() fails on one line, without parentheses, and with the dot moved to the next line, so no formatting change avoids it. The parser recovers by wrapping Link(). in an ERROR and parsing toMany() as a sibling inside the parentheses. _ts_decorator_name returned None for every parenthesized_expression, so the whole decorator was skipped.

The warning also reported the first ERROR in document order. In continent.entity.ts that is line 14, a single-line recovery that keeps every symbol; the multiline region at line 33 is the one that lost edges.

 graphify/extractors/engine.py
+  _ts_decorator_target_name()
+    unwrap a parenthesized decorator
+    name the outermost call the parser recovered
+    name nothing for a recovered non-call expression (`@(A, B)`)
+
+  _first_multiline_error_line()
+    line of the earliest ERROR that spans more than one line

 graphify/extract.py
-  first_error_line
+  lossy_error_line, falling back to first_error_line
+  "error region at line N" instead of "first error at line N"

Before (v8, continent.entity.ts from the issue):

warning:  ... continent.entity.ts (first error at line 14, 6 symbol(s) extracted)
decorator edges: column, entity, primarykey

After:

warning:  ... continent.entity.ts (error region at line 33, 8 symbol(s) extracted)
decorator edges: column, tomany, toone, entity, primarykey

The two new edges add their stub targets, which is where the two extra nodes come from.

The 7-line x.ts from the issue goes from no decorator edge to:

x_c -> tomany [references, context=decorator]

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Tests or CI
  • Refactor
  • Security fix

Verification & Invariants

A decorator's references edge targets the outermost call of its expression, whether or not the expression is parenthesized. A recovered expression that is not a call (an invalid @(A, B)) gets no name rather than a guessed one. The warning line names the region the warning gate selects on: the earliest multiline ERROR, or the first error when the file yielded nothing but its file node.

  • Read the CONTRIBUTING.md guide.
  • Reproduced the issue and identified the invariant.
  • Made the smallest fix necessary.
  • Added a regression test (if bug fix) or isolated boundary test.
  • Kept the PR description synchronized with the final implementation.
  • Documented any limitations / unsupported cases explicitly.

Merge Danger

Door: two-way. No cache schema change. Cached per-file results without lossy_error_line keep the old first-error line until they are re-extracted; the graph itself is unchanged by that key.

Blast Radius: TS/JS decorator edges and the partial-parse warning text.

Parenthesized decorators in every language now resolve a name where they previously resolved none. Plain decorators (@Component, @ng.Component(), @Injectable) take the same path as before, and the 320 TS/JS tests pass. The warning wording changed from first error at line N to error region at line N, which is user-visible; four existing expectations were updated with it. The full-suite failure set is identical to v8.

Limitations

  • Grammar: the parse error remains. tree-sitter-typescript 0.23.2 is the newest release on PyPI, and TSX and JS grammars fail on the same construct. No source rewrite tried (paren stripping, double parens, computed access, sequence, optional chain, line continuation) parses.
  • Unparenthesized chains: @Link().toMany() still attributes only Link, because the parser ends the decorator at @Link() and parses the rest as a separate expression.
  • One target per decorator: only the outermost call is named, so Link gets no edge from @(Link().toMany()).
  • Repeated targets: two decorators with the same target collapse into one edge, since edges are deduplicated by endpoints and relation.
  • Warning: it still says "may be partially extracted" even when every symbol survived; the parser cannot tell whether the lost part was a decorator edge or a symbol.

How was this tested?

New tests in tests/test_ts_decorator_chains.py run extract() on small TS files: the two recovered shapes, the clean identifier-receiver shape, the invalid-sequence guard, and the warning line for a file with an earlier single-line error.

pytest tests/test_ts_decorator_chains.py (v8)      -> 4 failed, 1 passed
pytest tests/test_ts_decorator_chains.py (this PR) -> 5 passed
pytest test_ts_*.py test_js_*.py test_python_decorators.py \
       test_partial_extraction_warning.py          -> 320 passed
pytest -q -p no:randomly (full suite, serial)      -> v8:      39 failed, 7988 passed, 361 skipped
                                                      this PR:  39 failed, 7993 passed, 361 skipped
                                                      (failure sets identical)

Verified on the issue's files with graphify update --force:

file v8 this PR
x.ts no decorator edge x_c -> tomany
continent.entity.ts 3 decorator edges, warning at line 14 5 decorator edges, warning at line 33

Graphify-specific checklist

  • I updated generated skill artifacts (uv run python -m tools.skillgen --bless) when changing their source fragments. (N/A: no skill fragments touched.)
  • I confirmed that AST/structural extraction remains deterministic (no ambient state dependencies like ENV variables).
  • I reviewed changes for security implications (no unsafe interpolation into shell/Python).
  • I confirmed no API keys or local-only graph data are included.
  • (If applicable) I disclosed AI authorship in my commit messages.

…raphify-Labs#4711)

tree-sitter-typescript 0.23.2 cannot parse a member access on a call in
decorator position. For `@(Link().toMany())` it wraps `Link().` in an ERROR
and parses `toMany()` as a sibling, and `_ts_decorator_name` returned None for
any parenthesized expression, so the decorator contributed no edge at all.

Read the outermost call of a parenthesized decorator, including one recovered
past an ERROR, and leave a genuinely unparseable expression (an invalid
`@(A, B)`) without a name.

The partial-parse warning also reported the first ERROR line, which is often an
earlier single-line recovery that kept its symbols. Report the multiline
region the warning gate selects on instead.
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @Deepjyoti-Sarmah. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic.

@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Oct 23, 2026

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graphify reviewed this change.

No issues found by static checks — no coupling regressions or blocking issues in the code graph. That is not the same as safe to merge: see what was not checked.

Not checked: tests were not run; formal verification proved 0 of 3 changed function(s) (1 sampled, not proven, 2 not verified).

Formal verification. PR-changed functions: 1/3 verified (0 proven, 1 may-equivalent, 0 distinguished) · 2 not verified (1 vacuous, 1 unsupported).

Not verified on this run: \_extract\_generic (unsupported), \_ts\_decorator\_name (vacuous: never exercised).


Graphify review — findings

Fixes TypeScript decorators written as call chains, like @(Link().toMany()), which lost their references edge entirely. The new _ts_decorator_target_name unwraps the parenthesized expression and takes the outermost call (toMany) even when tree-sitter-typescript 0.23.2 wraps part of the chain in an ERROR. The parse error itself is still upstream, so the extractor recovers from it rather than fixing the parse. The partial-extraction warning now points at the multiline ERROR region that triggered it, via a new lossy_error_line, instead of an earlier single-line recovery that kept every symbol. It also reads "error region at line N" rather than "first error at line N", and the existing tests are updated to match. If no multiline error exists, it falls back to the first error line as before.

No blocking issues surfaced. 1 lower-confidence candidate did not survive cross-model review.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 3647 functions depend on the 773 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: extract() — 1006 callers, 60 callees
  • worse: _extract_generic() — 20 callers, 47 callees

Verification — 3647 functions in the blast radius were not formally verified this run (proofs are advisory here).

Gate & verification

graphify gate

PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 3401 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

209 of 444 test file(s) selected (47%) via static blast radius.

  • tests/test_affected_overrides.py — impact
  • tests/test_astro_extraction.py — impact
  • tests/test_astro_import_ids.py — impact
  • tests/test_blade_extractor.py — impact
  • tests/test_build.py — impact
  • tests/test_builtin_global_type_refs.py — impact
  • tests/test_c_include_resolution.py — impact
  • tests/test_cache.py — impact
  • tests/test_case_sensitive_resolution.py — impact
  • tests/test_cjs_module_extension.py — impact
  • tests/test_cobol_extractor.py — impact
  • tests/test_cpp_method_declarations.py — impact
  • tests/test_cpp_nested_and_cli.py — impact
  • tests/test_cpp_objc_cross_file_calls.py — impact
  • tests/test_cpp_template_type_params.py — impact
  • tests/test_cross_extension_reexport_self_cycle.py — impact
  • tests/test_cross_language_call_resolution.py — impact
  • tests/test_cross_repo_external_call_guards.py — impact
  • tests/test_cross_repo_member_calls.py — impact
  • tests/test_csharp_call_site_generic_args.py — impact
  • tests/test_csharp_delegate_declarations.py — impact
  • tests/test_csharp_enum_members.py — impact
  • tests/test_csharp_field_generic_args.py — impact
  • tests/test_csharp_foreach_loop_variable.py — impact
  • tests/test_csharp_generic_callsites.py — impact
  • tests/test_csharp_interface_dispatch.py — impact
  • tests/test_csharp_member_calls.py — impact
  • tests/test_csharp_member_chain_calls.py — impact
  • tests/test_csharp_member_nodes.py — impact
  • tests/test_csharp_object_creation.py — impact
  • tests/test_csharp_partial_classes.py — impact
  • tests/test_csharp_tuple_type_refs.py — impact
  • tests/test_csharp_type_resolution.py — impact
  • tests/test_csharp_underscore_collisions.py — impact
  • tests/test_csharp_var_call_return_type.py — impact
  • tests/test_csharp_verbatim_interpolation.py — impact
  • tests/test_definition_file_portability.py — impact
  • tests/test_detect.py — impact
  • tests/test_dotnet.py — impact
  • tests/test_duplicate_annotation_edges.py — impact
  • tests/test_ejs_extractor.py — impact
  • tests/test_elixir_defdelegate.py — impact
  • tests/test_elixir_import_resolution.py — impact
  • tests/test_elixir_keyword_def_calls.py — impact
  • tests/test_elixir_qualified_calls.py — impact
  • tests/test_elixir_unqualified_call_scope.py — impact
  • tests/test_erlang_extractor.py — impact
  • tests/test_ext_tagged_id_clash.py — impact
  • tests/test_extract.py — impact
  • tests/test_extract_cache_location.py — impact
  • … and 159 more

Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.

Formal verification

No difference found (not proven): No behavior difference found in extract (not a proof).

The verifier ran both versions of extract on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

Could not verify: Could not verify \_extract\_generic.

The verifier did not have enough to check \_extract\_generic, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: no capturable inputs from the test suite; property tier: parameter `config` is annotated `LanguageConfig` — outside the synthesizable primitive/collection set

Could not verify: Could not verify \_ts\_decorator\_name.

The verifier did not have enough to check \_ts\_decorator\_name, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: no capturable inputs from the test suite; property tier: not verifiable: all 228 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly AttributeError — names the real obstacle, not a sampling gap)

· 2 more finding(s) on lines outside this diff (see the check run).

@safishamsi

Copy link
Copy Markdown
Member

Landed in v0.9.96, now on PyPI (pip install graphifyy==0.9.96). Chained TS decorators are recovered and the lossy parse region is reported. Thanks for the fix, @Deepjyoti-Sarmah.

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

Labels

contributor Pull request from a returning community contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TS: parenthesized decorator @(fn().method()) with a line break before .method is flagged a syntax error, dropping later symbols

2 participants