Espree is a high-performance, Esprima-compatible JavaScript parser built upon the modular Acorn parsing library. It is the default parser used by ESLint and is designed to produce Abstract Syntax Trees (ASTs) that are highly consistent with the Esprima API, making it a drop-in replacement in many scenarios. The package is currently at stable version 11.2.0 and receives active maintenance with frequent updates, typically on a monthly or bi-monthly schedule for minor and patch releases. Key differentiators include its robust support for all modern ECMAScript features up to ES2026 (ECMAScript 17), comprehensive parsing options for fine-grained control over AST output (including ranges, locations, comments, and tokens), and official TypeScript type definitions since v11.1.0, enhancing developer experience for TypeScript projects.
npm install espreeVerified import paths — ran on the pinned version, not inferred.
Demonstrates parsing JavaScript code into an AST and extracting tokens and comments using various options, including `ecmaVersion: 'latest'` and `sourceType: 'module'`.
Upgrade your Node.js environment to `^20.19.0 || ^22.13.0 || >=24`.
Update any code that relies on the exact `range` of the `Program` node to account for its new, expanded span.
When using `espree.parse()`, always ensure `tokens: true` and `comment: true` are set in the options if you need these details in the AST output.
Set `ecmaVersion: 'latest'` or specify a modern year (e.g., `ecmaVersion: 2024`) in the parse options object.
If your project uses ESM, use `import * as espree from "espree";` to import the library. Ensure your `package.json` has `"type": "module"` or files end with `.mjs`.
For ESM, correctly import the module as a namespace: `import * as espree from "espree";`. Then, call `espree.parse(code)`.
No dependency data recorded yet.