Skip to content

Conversation

@moofone
Copy link

@moofone moofone commented Oct 3, 2025

Summary

  • Fixes an infinite recursion in the type-query grammar triggered by chained typeof-based queries (e.g., ReturnType) under parallel parsing.
  • Preserves established precedence and AST shape vs type-level indexed access (lookup_type).

Root Cause

  • Self-referential aliases in type-query rules allowed unbounded recursion during balancing.

Solution

  • Bound only the self-recursion; do not raise the precedence of the whole rules.
  • Changes in common/define-grammar.js:
    • common/define-grammar.js:694: _type_query_member_expression_in_type_annotation
      • Wrap rule in seq(...) (no outer prec).
      • Self-alias uses prec.left(1, alias(...)).
    • common/define-grammar.js:845: _type_query_member_expression
      • Wrap rule in seq(...) (no outer prec).
      • Self-alias uses prec.left(1, alias(...)).
    • common/define-grammar.js:859: _type_query_subscript_expression
      • Wrap rule in seq(...) (no outer prec).
      • Self-alias uses prec.left(1, alias(...)).

Tests

  • Added regression corpus: test/corpus/type-query-regression.txt.
  • Updated “Array subscript in type queries” to the established AST:
    • typeof arr[0] parses as a type-level indexed access:
      • value: (lookup_type (type_query (identifier)) (literal_type (number)))
  • Full corpus passes locally after regeneration.

Regeneration

  • Parsers regenerated for TypeScript and TSX with tree-sitter-cli 0.24.4 (LANGUAGE_VERSION 14).

All tests

  • regenerated both parsers and ran the full suite via npx tree-sitter test -r; all tests passed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant