Skip to content

About

Brokk-maintained Tree-sitter grammars for TypeScript and TSX

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

 
 

Repository files navigation

Brokk's TypeScript Grammar for Tree-sitter

CI crates docs.rs

This is the Brokk-owned and independently maintained fork of tree-sitter/tree-sitter-typescript, which provides TypeScript and TSX grammars for Tree-sitter. Brokk maintains this fork for its code-intelligence tooling and publishes the Rust package as brokk-tree-sitter-typescript. It intentionally diverges where Brokk needs language support that is not yet available upstream. Unless you specifically need Brokk's changes, you may prefer the upstream project.

Installation

Add the Brokk-maintained TypeScript crate to your project:

cargo add brokk-tree-sitter-typescript@=0.23.7

Or add it directly to Cargo.toml:

[dependencies]
brokk-tree-sitter-typescript = "=0.23.7"

The npm, Python, Go, Swift, and C bindings retain their upstream-compatible package names but are not published by this fork. The Brokk-namespaced Rust crate prefixes both grammars' native symbols, so it can coexist with the upstream tree-sitter-typescript crate in one executable.

Changes from upstream

Version 0.23.7 accepts using as a contextual identifier in both grammars, including imported function calls, generic calls, bindings, and subscript assignments. A newline after an identifier named using can terminate its expression statement. Existing using and await using declarations retain their assignment-shaped trees. Resource-declaration support remains incomplete: resource for...of bindings are rejected, while some invalid expression and destructuring forms are accepted.

Version 0.23.5 accepts literal ampersands in TSX text and quoted attributes, including URL query strings and ampersands immediately before a closing quote. Named, decimal, and hexadecimal character references retain their existing AST nodes. The TypeScript parser is unchanged from 0.23.4.

Version 0.23.4 lets import types compose with array and indexed-access types, including nested generic members, and with keyof, readonly, unions, and intersections. Both TypeScript and TSX retain the existing import AST shapes.

Version 0.23.3 builds on upstream commit 75b3874edb2dc714fb1fd77a32013d0f8699989f. It adds generic arguments to import() member types, newline-separated keyword property names in type declarations, and abstract override readonly class properties. Expression operators and malformed declarations have separate regression coverage. The generic import change incorporates the public work by @elecnix in upstream pull request 365.

The upstream MIT license and author attribution are preserved.

Development

Use Node.js 24 and the locked dependencies. Parser generation uses exactly Tree-sitter CLI 0.24.4 and tree-sitter-javascript 0.23.1:

npm ci --ignore-scripts --legacy-peer-deps
npm rebuild tree-sitter-cli
npm run generate
git diff --exit-code -- typescript/src tsx/src
npm run test:corpus
npm run lint
cargo fmt --check
cargo test --locked
cargo package --locked
cargo publish --dry-run --locked

The shared corpus runs against both parsers. Dialect-specific type assertions and JSX cases explicitly select their parser. Rust tests also load the upstream and fork grammars together and check malformed near misses.

Releases

This fork publishes only brokk-tree-sitter-typescript on crates.io. Tags use v followed by the Cargo package version and must remain immutable. Package from the clean tagged commit, verify the archive's .cargo_vcs_info.json, and record its SHA-256 before publication.

The first publication requires a short-lived crates.io token supplied through CARGO_REGISTRY_TOKEN to cargo publish --locked. After that bootstrap, configure the crate's trusted publisher for organization BrokkAi, repository tree-sitter-typescript, workflow publish.yml, and environment release. Set the repository variable CARGO_TRUSTED_PUBLISHING to true only once that publisher is configured. Later tagged releases use the protected release environment and the crates.io OIDC workflow.

Upstream bindings

Because TSX and TypeScript are actually two different dialects, this module defines two grammars. Require them as follows:

require("tree-sitter-typescript").typescript; // TypeScript grammar
require("tree-sitter-typescript").tsx; // TSX grammar

For Javascript files with flow type annotations you can use the tsx parser.

References

About

Brokk-maintained Tree-sitter grammars for TypeScript and TSX

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages