@lezer/common

The packed syntax-tree data structure and parser interfaces shared by every Lezer parser

Library
npm
v1.5.3
69 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
31 /100 Needs Attention
Development Activity 8
Maintenance 0
Community 44
Maturity 60
Momentum 12

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
78 /100 Good
Architecture 84
Code Quality 80
Innovation 82
Learning Curve 65

@lezer/common provides the core syntax-tree data structure and parser abstractions that every Lezer-based parser builds on. Lezer is an incremental parser system designed for editor use (it’s the parsing engine behind CodeMirror 6’s language support), and this package defines the memory-efficient, packed tree representation that parse results are stored in, along with the Parser/Input interfaces that concrete language parsers implement.

Rather than producing a conventional AST of allocated node objects, Lezer parsers built on this package output a compact, cursor-navigable tree that can be incrementally reused across edits — critical for keeping syntax highlighting and code folding fast in a live text editor as the user types.

What You Get

  • The Tree type: a compact, packed syntax-tree representation with cursor-based traversal instead of individually allocated node objects
  • TreeCursor and SyntaxNode for navigating and inspecting parsed trees
  • The abstract Parser and Input interfaces that concrete Lezer parsers (e.g. @lezer/javascript, @lezer/python) implement
  • NodeType/NodeSet and NodeProp for attaching typed metadata to grammar node kinds
  • Tree-mixing (mix.ts) support for embedding one language’s parse tree inside another (e.g. JS inside HTML <script> tags)
  • Incremental re-parsing support so edits to a document only reparse the changed region, not the whole file

Common Use Cases

  • Building or consuming a Lezer-generated parser for a programming language inside an editor (most commonly CodeMirror 6)
  • Implementing syntax highlighting, code folding, or bracket matching against a Lezer parse tree
  • Embedding one language’s grammar inside another (e.g. CSS/JS inside HTML) via tree mixing
  • Writing editor tooling that needs incremental reparsing to stay responsive on large documents
  • Building static analysis or linting tools on top of an existing Lezer grammar’s tree output

Under The Hood

Architecture — The package is intentionally small and focused: tree.ts (~1,700 lines) implements the packed Tree/TreeBuffer/TreeCursor data structures at the core of the library, parse.ts defines the abstract Parser/PartialParser/Input interfaces concrete grammars implement, mix.ts implements the language-nesting/mixed-parsing machinery (e.g. embedding JS inside HTML), and index.ts just re-exports the public surface. Concrete language parsers (generated by the separate @lezer/generator from a grammar file) depend on this package for the tree/parser abstractions rather than reimplementing tree storage themselves — which is what keeps every Lezer-based language parser interoperable and lets CodeMirror 6 treat them uniformly.

Tech Stack — Pure TypeScript, compiled to both ESM (dist/index.js) and CJS (dist/index.cjs) via a small custom build.js using @marijn/buildtool. It has zero runtime dependencies — the packed tree format is implemented from scratch rather than wrapping an existing parsing library, which keeps it lightweight enough to load in a browser-based editor.

Code Quality — Tests live under test/test-tree.ts, run with Mocha, focused specifically on tree construction/navigation correctness (the highest-risk area given the packed binary-like tree representation). Primary development for this and Marijn Haverbeke’s other editor projects (CodeMirror, Lezer) now happens on his self-hosted Forgejo instance at code.haverbeke.berlin — the GitHub repository is a kept-in-sync mirror (commits and npm releases continue to land here), not an abandoned copy, but issues/PRs are handled upstream rather than on GitHub.

API Design — The public surface centers on a handful of well-documented types (Tree, TreeCursor, SyntaxNode, NodeType) with consistent cursor-based traversal patterns across all of them, and the canonical reference docs live on the Lezer website rather than in inline comments, so newcomers are expected to read the docs site rather than infer usage from types alone. Because this package is rarely used standalone — it’s almost always pulled in transitively by a concrete language parser or CodeMirror itself — most developers interact with a thin slice of its API (walking a SyntaxNode tree) rather than the full interface surface.

Used by 18 apps in this directory

Rust
67%
MIT

Bun

Developer Tools

96,068

An all-in-one JavaScript and TypeScript toolkit — one Rust-and-JavaScriptCore binary that replaces Node.js, npm, a bundler, and a test runner with faster equivalents.

View details
92
Repo Health
91
Technical
64
Dependency
Built with
Rust 67%
C++ 19%
TypeScript 10%
Updated 5 days ago
Go
64%
Apache 2.0

Coroot

Analytics · Monitoring

7,940

eBPF-powered observability with AI root cause analysis — zero code changes required, full-stack visibility out of the box.

View details
88
Repo Health
80
Technical
66
Dependency
Built with
Go 64%
Vue 34%
Updated 1 weeks ago
Ruby
61%
GPL 2.0

Discourse

Community

47,915

Open-source community platform with dynamic trust levels, real-time chat, and a powerful plugin architecture for self-hosted forums.

View details
89
Repo Health
89
Technical
67
Dependency
Built with
Ruby 61%
JavaScript 32%
Updated 4 days ago
Java
34%
Apache 2.0

Enso

Analytics · Data Engineering · Low Code Platforms

7,441

A visual and textual programming platform for data prep and analysis where the node graph and the underlying Enso code are always perfectly in sync, built by an Alteryx co-founder on a GraalVM engine.

View details
59
Repo Health
90
Technical
61
Dependency
Built with
Java 34%
TypeScript 27%
Scala 26%
Updated 1 months ago
TypeScript
64%
Other

Epicenter

Developer Tools · Knowledge Management · Note Taking

4,808

A local-first monorepo led by Whispering, an open-source speech-to-text app, built on an MIT toolkit that turns your data into plain Markdown and SQLite files you own instead of a database you rent.

View details
88
Repo Health
90
Technical
64
Dependency
Built with
TypeScript 64%
HTML 13%
Svelte 13%
Updated 5 days ago
TypeScript
58%
AGPL 3.0

Frappe Books

Invoicing Finance

4,990

Offline desktop accounting with double-entry, POS, and custom invoice templates

View details
89
Repo Health
77
Technical
73
Dependency
Built with
TypeScript 58%
Vue 39%
Updated 1 weeks ago
Rust
65%
Other

GitButler

AI Development · Developer Tools · Devops

21,726

Git, but better — a modern version control client with stacked branches, parallel workflows, unlimited undo, and first-class support for AI-powered development.

View details
89
Repo Health
84
Technical
66
Dependency
Built with
Rust 65%
TypeScript 22%
Svelte 10%
Updated 4 days ago
TypeScript
48%
AGPL 3.0

Grafana

Analytics · Monitoring

76,962

The open-source observability platform that unifies metrics, logs, and traces from any data source into dynamic, queryable dashboards.

View details
95
Repo Health
91
Technical
63
Dependency
Built with
TypeScript 48%
Go 46%
Updated 4 days ago
TypeScript
77%
Other

Joplin

Note Taking

56,513

The privacy-first, open-source note-taking app with end-to-end encrypted sync, AI assistance, and a powerful plugin ecosystem across every platform.

View details
93
Repo Health
87
Technical
60
Dependency
Built with
TypeScript 77%
JavaScript 14%
Updated 5 days ago

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