esprima

A high-performance, standard-compliant ECMAScript parser producing ESTree-compatible ASTs for JavaScript tooling.

Library
npm
v4.0.1
7,137stars
BSD-2-Clause

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
47/100Fair
Development Activity0
Maintenance0
Community88
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
70/100Good
Architecture74
Code Quality72
Innovation65
Learning Curve68

Esprima is one of the original high-performance ECMAScript parsers for JavaScript, converting JS source code into an ESTree-compatible abstract syntax tree (AST) that other tools can traverse and transform. It was one of the first widely-adopted parsers to expose a stable, standardized AST format, which made it a foundational dependency for a generation of linters, minifiers, code-coverage tools, and IDE tooling built in the JavaScript ecosystem.

It supports parsing modern ECMAScript syntax (through ES2017) plus JSX, and includes companion tools for tokenization, AST traversal/visiting, and syntax validation. While newer parsers like Acorn and Espree have taken over as the default in many toolchains (ESLint moved to Espree), Esprima remains widely depended upon and is still a common building block referenced in parser and static-analysis documentation.

What You Get

  • esprima.parseScript()/parseModule() producing an ESTree-compatible AST from JS source
  • Tokenizer output (esprima.tokenize()) for lexical-analysis use cases
  • JSX syntax support alongside standard ECMAScript syntax
  • Range/location tracking options for mapping AST nodes back to source positions
  • A companion esvalid project for validating an AST’s syntactic correctness

Common Use Cases

  • Building custom static analysis or linting rules that need a JavaScript AST to traverse
  • Powering code transformation, minification, or instrumentation tools that operate on parsed JS
  • Extracting tokens or source positions from JavaScript for editor tooling or syntax highlighting
  • Teaching or prototyping parser/compiler concepts using a well-documented reference JS parser

Under The Hood

Architecture Esprima is a hand-written recursive-descent parser: scanner.ts and tokenizer.ts handle lexical analysis, parser.ts drives grammar-rule parsing into nodes.ts-defined ESTree node shapes, with jsx-parser.ts/jsx-nodes.ts layered on for JSX syntax and error-handler.ts/messages.ts producing standardized syntax error messages. Tech Stack It’s written in TypeScript, compiled to a browser- and Node-compatible dist/ bundle via Webpack, with no runtime dependencies — a deliberate design choice to keep it embeddable in other tools without dependency bloat. Code Quality The project has an extensive test/ directory covering ECMAScript syntax edge cases across versions, and was historically maintained to a high bar as a foundational ecosystem dependency, though it has seen very little activity or new releases since 2018-2019 as tooling gravitated to Acorn/Espree. API Design The API is intentionally minimal — parseScript, parseModule, and tokenize functions each returning a plain ESTree-shaped object — which is precisely why so many other tools were able to adopt it as a drop-in AST source with little integration work.

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