Skip to content

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

Closed

Description

@erayhanoglu

Summary

A parenthesized decorator @( ... ) whose expression is a call expression followed by a line break before .member is rejected by the TypeScript AST extractor. The file is reported as having a syntax error and every symbol after the decorator is dropped from the graph.

tsc accepts the same file without a single diagnostic.

This formatting is what Prettier produces for chained decorator factories, so it is common in decorator-heavy codebases (NestJS, TypeORM, and in my case @sqb/connect).

Minimal reproduction

x.ts — 7 lines, clean under tsc --noEmit:

declare function Link(): any;

export class C {
  @(Link()
    .toMany())
  a: unknown;
}
$ graphify update .
  warning: 1 file(s) had syntax errors and may be partially extracted: x.ts (first error at line 4, 1 symbol(s) extracted)

Only C is extracted; the property a is lost.

What exactly triggers it

I bisected the construct. The line break before . only matters when the receiver is a call expression:

# Decorator Result
1 @(Link().toMany()) — one line ✅ clean
2 @(Link\n .toMany()) — line break, identifier receiver ✅ clean
3 @(\n Link().toMany()\n) — line break after @(, expression on one line ✅ clean
4 @(Link()\n .toMany()) — line break, call receiver ❌ syntax error
5 @(Link({ a: 1 })\n .toMany(() => X, {})\n .toOne(() => Y, {})) ❌ syntax error
6 const v = Link()\n .toMany(); — same chain, plain statement ✅ clean

Rows 2 and 3 show parenthesized decorators are supported in general, and row 6 shows multi-line call chains are fine outside decorator position — so this is specific to a call-expression receiver continuing onto the next line inside a decorator.

Line breaks inside the argument list are fine; it is only the break before the .:

// clean
@(Link({ exclusive: true }).toMany(
  async () => (await import('./country.entity.js')).Country,
  { sourceKey: 'code' },
))

Secondary issue: the reported line number points at the wrong decorator

In my real file (continent.entity.ts, 43 lines, 3 decorated properties) the warning says:

warning: 1 file(s) had syntax errors and may be partially extracted:
  packages/connect/test/_support/continent.entity.ts (first error at line 14, 4 symbol(s) extracted)

Line 14 is a decorator of the row-1/argument-list shape above, which parses fine in isolation. The actual culprit is the chained decorator at lines 33–41. Deleting lines 33–42 makes the file extract cleanly (9 nodes, no warning); deleting the line-14 decorator instead does not help.

So the "first error at line N" position is taken from a tree-sitter ERROR node that starts well before the construct that actually fails, which sent me to the wrong place for a while. Reporting the position of the failing node — or the whole ERROR range — would make these warnings much more actionable.

Environment

  • graphifyy 0.9.94 (also reproduces on 0.9.53)
  • tree-sitter-typescript 0.23.2 — which is the latest release on PyPI, so there is no newer grammar to bump to; the parse failure likely needs either an upstream grammar fix or a workaround in the extractor
  • tree-sitter 0.25.2, Python 3.14.5
  • macOS 26.7.1 (Darwin 25.6.0), arm64, installed via uv tool install graphifyy

Impact

Low severity, but silent: the warning says "may be partially extracted" and the run otherwise succeeds, so the missing symbols and relations are easy to miss. In my case the @Link relations of one entity are simply absent from the graph, which is exactly the kind of edge the graph is for.

Possibly related: #3597 (export type * partial extraction, also tree-sitter-typescript predating current TS syntax).

Activity

  1. github-actions commented on Oct 23, 2026

    @github-actions

    Thanks for opening this issue, @erayhanoglu. A maintainer will take a look soon.

    If you would like to discuss it in real time, come say hi on our Discord server. For longer-form questions and ideas there is also GitHub Discussions.

    To help us triage, please make sure the report includes what you expected, what actually happened, and the steps (and a small sample) to reproduce it.

  2. Deepjyoti-Sarmah commented on Oct 23, 2026

    @Deepjyoti-Sarmah
    Contributor

    I reproduced this on v8 with the 7-line x.ts: same warning at line 4, and only C in the graph.

    The parse failure is in tree-sitter-typescript 0.23.2, not in the extractor. @(Link().toMany()) already sets has_error on one line; the line break before .toMany only changes the recovery. The ERROR wraps Link() and the . ('Link()\n .'), and toMany() comes back as a separate call expression.

    Three things explain the report:

    • The warning fires only when an ERROR spans more than one line or the file yielded nothing but its file node, so the one-line form is silent even though it also failed to parse.
    • first error at line N is the first ERROR in document order. In continent.entity.ts the single-line ERRORs on the @(Link({...}).toMany(...)) fields at lines 14 and 23 come before the multiline one at line 33, so the warning stops at 14.
    • Decorator edges are missing for every parenthesized decorator, not just broken ones. _ts_decorator_name handles identifier and member_expression and returns None for parenthesized_expression, so @(Link\n.toMany()), which parses cleanly, also emits no edge.

    One correction so a fix targets the right loss: a typed field (a: unknown, declare code: string) is not a graph node even when the file parses cleanly. The field is not dropped; the missing output is the decorator references edge. Methods after the failing decorator still extracted in my tests.

    I'm working on a fix for both the parse recovery and the parenthesized decorator name, and will open a PR.

  3. safishamsi commented on Oct 26, 2026

    @safishamsi
    Member

    Fixed in v0.9.96 via #4715, now on PyPI (pip install graphifyy==0.9.96). Parenthesized/chained TS decorators are recovered instead of dropping later symbols. Thanks for the report, @erayhanoglu.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions