Skip to content

fix!: attach exported class decorators to their class - #104

Merged
exKAZUu merged 2 commits into
mainfrom
fix/exported-class-decorator-ownership
Oct 18, 2026
Merged

exKAZUu merged 2 commits into
mainfrom
fix/exported-class-decorator-ownership

Conversation

@exKAZUu

@exKAZUu exKAZUu commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

Why

Decorators preceding export are siblings of the class, so class/decorator queries miss exported declarations. The JavaScript export rule causes the inherited problem reported in tree-sitter/tree-sitter-typescript#331.

Requirements

  • required: Review fork and upstream issues, avoid duplicate PRs, and address worthwhile improvements in dedicated PRs; backward compatibility is not required.
  • required: Run review-booster and complete-pr concurrently, then release verified changes.
  • required: Exported class decorators must belong to the class declaration so consumers can find classes by their decorators, as requested in the upstream issue.
  • chosen: Preserve canonical declaration and class query captures through a hidden supertype wrapper; directly aliasing the decorated class loses declaration-supertype captures.
  • chosen: Keep the export_statement wrapper and include intervening export/default keywords within the decorated class range, because a class containing its leading decorators and body must span contiguous source text.
  • chosen: Limit decorators before export to class declarations and reject decorators on both sides, matching the TC39 decorators proposal.

Customer Summary

Decorators before or after export now belong to class_declaration. Named exports and named/anonymous default classes retain canonical declaration queries and incremental parsing behavior.

Technical Summary

A hidden decorated-export supertype aliases to declaration and wraps the decorated class alias, preserving both levels of query ancestry. The class-only default-export branch uses the literal default keyword because its declaration form is unambiguous. Update the corpus expectation and regenerate the profiled parser and node types.

Testing

  • MISE_RUST_VERSION=1.99.1 bun run verify: passed; no code-gauge violations in changed code.
  • bun run build/ci: passed.
  • bun wb test test/unit/exportedDecorators.test.ts test/unit/defaultExports.test.ts: 7 tests passed.
  • script/tree-sitter test: all 199 corpus parses passed.
  • bun wb test test/unit/queries.test.ts --grep 'compiles the queries': passed.
  • Focused tests cover canonical queries, decorator ownership/ranges, default classes, comments, following-statement boundaries, incremental export edits, and invalid decorator placements. Full PR CI passed on the current head.

Notes

Breaking tree change: before-export decorators move from export_statement to class_declaration, whose range includes the intervening export/default keywords. Queries requiring those keywords to be direct children of export_statement must adapt.

TypeScript overrides its export and class rules; its corresponding integration is still needed before the upstream TypeScript issue is resolved in that fork. This PR does not address legacy call assignments or other grammar issues.

BREAKING CHANGE: Decorators before export belong to class_declaration rather than export_statement. The class range includes the intervening export keywords.

Co-authored-by: WillBooster (Codex CLI) <agent@willbooster.com>
@exKAZUu exKAZUu self-assigned this Oct 17, 2026
@exKAZUu
exKAZUu merged commit 8505812 into main Oct 18, 2026
10 checks passed
@exKAZUu
exKAZUu deleted the fix/exported-class-decorator-ownership branch October 18, 2026 06:25
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.

1 participant