tree-sitter-typescript

TypeScript and TSX grammars for the tree-sitter incremental parsing framework.

Library
Cargo
v0.23.2
530stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
45/100Fair
Development Activity0
Maintenance20
Community80
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
74/100Good
Architecture78
Code Quality74
Innovation72
Learning Curve70

tree-sitter-typescript provides two tree-sitter grammars — one for TypeScript and one for TSX — that let editors, linters, and static-analysis tools build and incrementally update a concrete syntax tree for TypeScript source files. Because TSX is a genuinely distinct dialect (JSX syntax mixed with TypeScript types), the package ships it as a separate grammar rather than trying to overload a single parser for both.

The grammar is distributed as native bindings for Rust, Node.js, Python, Go, Swift, and C/CMake consumers, so the same underlying parser (generated from grammar.js and compiled C parser tables) can be embedded in editors like Neovim and Helix, in language-server tooling, or in any application that needs a fast, error-tolerant TypeScript parse tree rather than a full type-checking compiler.

What You Get

  • Two separate grammars — typescript and tsx — reflecting that TSX is a distinct dialect from plain TypeScript
  • Native bindings for Rust, Node.js, Python, Go, Swift, and C/CMake so the parser can be embedded in editors and tooling written in any of those languages
  • Query files under queries/ for syntax highlighting and other tree-sitter-consuming features
  • Incremental, error-tolerant parsing suitable for live-editing scenarios rather than a batch compiler pass
  • A CI-tested grammar kept in sync with the upstream tree-sitter grammar DSL and parser generator

Common Use Cases

  • Powering TypeScript/TSX syntax highlighting in editors such as Neovim, Helix, and other tree-sitter-based editors
  • Building structural code search, refactoring tools, or linters that need a real syntax tree rather than regex-based matching
  • Embedding a TypeScript parser in a Rust, Python, or Node.js application via the language-specific bindings
  • Implementing custom static-analysis or code-intelligence tooling that needs incremental re-parsing as a file is edited

Under The Hood

Architecture - The grammars are defined in typescript/grammar.js and tsx/grammar.js using tree-sitter’s grammar DSL, then compiled by the tree-sitter CLI into C parser tables checked into typescript/src and tsx/src. Per-language bindings live under bindings/ (c, rust, node, python, go, swift), each a thin wrapper that loads the compiled parser and exposes it through that language’s native API; queries/ holds tree-sitter query files consumed by editors for highlighting and other features.

Tech Stack - The grammar definitions are JavaScript, but the generated parsers are C (22.7% of the repo), with Rust bindings built via a build.rs script declared in Cargo.toml, Node bindings via binding.gyp, and equivalent packaging for Python (setup.py/pyproject.toml), Go (go.mod), and Swift (Package.swift) — a genuinely polyglot distribution model built around one shared C parser core.

Code Quality - CI (GitHub Actions) runs the grammar’s test corpus on every change; the project has a low but steady maintenance cadence (739 total commits since 2017, most recent release in November 2024) reflecting that TypeScript/TSX grammar changes are infrequent once a language’s syntax stabilizes, though this also means newer TypeScript syntax may lag behind the latest release.

API Design - Consumers require two distinct exports — require('tree-sitter-typescript').typescript and .tsx — which is a deliberate, low-boilerplate way of surfacing that TSX is not simply ‘TypeScript inside a JSX file.’ Each language binding follows that host language’s idiomatic parser API (e.g. tree_sitter::Language in Rust), so developers already familiar with tree-sitter in one language transfer that knowledge easily to another.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search