Registry / serialization / meriyah

meriyah

JSON →
library7.1.0jsnpmunverified

Meriyah is a highly performant and stable JavaScript parser, currently at version 7.1.0, designed for 100% compliance with the ECMAScript® 2024 (ES-262 15th Edition) standard. It provides an ESTree-compatible Abstract Syntax Tree and operates without backtracking, contributing to its low memory footprint. While it actively supports Annex B (Web Browsers) features, JSX parsing, and select TC39 Stage 3 proposals like Decorators and JSON Modules via an opt-in `next` flag, it notably does *not* support TypeScript or Flow syntax. The project maintains a steady release cadence, frequently updating to reflect the latest ECMAScript specifications and address bug fixes, as evidenced by recent v6 and v7 patch and minor releases, ensuring it remains a cutting-edge tool for syntactic analysis.

npm install meriyah
INSTALL
IMPORT
SIG · MERIYAH
M
meriyah
serializationjavascriptv7.1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parse
import { parse } from 'meriyah';
const { parse } = require('meriyah');
Meriyah is primarily an ESM package. While bundlers or transpilers might enable `require`, direct CJS `require` might not work natively in modern Node.js environments without specific configurations.
isParseError
import { isParseError } from 'meriyah';
import isParseError from 'meriyah';
This utility function, available since v7.1.0, is a named export useful for robustly checking if an error originated from Meriyah's parsing process.
ParserOptions
import type { ParserOptions } from 'meriyah';
import { ParserOptions } from 'meriyah';
For TypeScript users, `ParserOptions` is a type definition and should be imported using `import type` to avoid runtime side effects or errors.

Demonstrates parsing a complex JavaScript module with various features, including ESNext proposals, web compatibility, location tracking, and error handling.

import { parse, isParseError } from 'meriyah'; import type { Program } from 'estree'; // Assuming ESTree types are needed for the result const javascriptCode = ` // This is a complex JavaScript module demonstrating various features. import { someUtil } from './utils.js'; @debounce(300) class MyClass { #privateField = 42; // Private class field (ES2022) constructor(name) { this.name = name; } // A method with decorators (TC39 Stage 3, requires 'next' option) @log greet(param) { console.log(`Hello, ${this.name}! ${param}`); return someUtil(this.#privateField); } } export const instance = new MyClass('Meriyah User'); // Example of Annex B feature (non-strict mode) // function foo() { 'use strict'; with (obj) {} } // This would error in strict mode // A regular expression with newer features (requires Node.js >= 24 for full validation) const regex = /(?<word>\w+)/d; if ("test".match(regex)) { console.log("Matched!"); } `; try { const ast: Program = parse(javascriptCode, { sourceType: 'module', // Parse as an ES module ranges: true, // Include start/end offsets for each node loc: true, // Include line/column location information next: true, // Enable TC39 Stage 3 proposals (e.g., Decorators) jsx: false, // Explicitly disable JSX (if not needed) webcompat: true, // Enable web compatibility (Annex B) validateRegex: true, // Validate regular expressions with the current JS runtime }); console.log('Successfully parsed AST:'); // console.log(JSON.stringify(ast, null, 2)); // Uncomment to see the full AST console.log(`Program type: ${ast.type}`); console.log(`First statement type: ${ast.body[0].type}`); } catch (e: any) { if (isParseError(e)) { console.error(`Meriyah Parse Error: ${e.message} at line ${e.loc?.line}, column ${e.loc?.column}`); } else { console.error('An unexpected error occurred:', e.message); } }
Debug
Known issues
breakingAs of v7.1.0, assigning to a `CallExpression` is now treated as a runtime error in Annex B (web compatibility) mode. This behavior change aligns with stricter ECMAScript specifications, potentially breaking code that previously relied on this pattern.
fix
Review code that assigns values directly to the result of function calls, especially in contexts where Annex B (webcompat) features are enabled. Refactor such code to avoid this pattern.
affects: >=7.1.0
gotchaMeriyah explicitly does NOT support TypeScript or Flow syntax. It is designed solely for parsing standard ECMAScript and select Stage 3 TC39 proposals.
fix
For projects requiring TypeScript or Flow parsing, consider alternative parsers like `@typescript-eslint/typescript-estree` or `babel-parser`.
affects: >=1.0.0
gotchaRegExp validation depends on the JavaScript runtime. Newer RegExp features (e.g., RegExp modifiers, duplicate named groups) may require Node.js >= 24. Parsing code with these features on older Node.js versions (or other runtimes) might lead to `SyntaxError` if `validateRegex: true` is enabled (the default).
fix
Update your Node.js environment to a version that supports the required RegExp features. Alternatively, set `validateRegex: false` in the parse options to bypass runtime RegExp validation, but be aware this may allow invalid RegExp to parse without error.
affects: >=6.1.0
breakingMeriyah requires Node.js version 20.0.0 or higher. Running Meriyah on older Node.js environments will result in errors.
fix
Ensure your project's Node.js version meets the `engines.node` requirement (>=20.0.0).
affects: >=7.0.0
gotchaParsing code as an ES module, CommonJS module, or with JSX syntax requires explicit options. The default `sourceType` is 'script', and `jsx` is `false`.
fix
For ES modules, use `sourceType: 'module'`. For CommonJS, use `sourceType: 'commonjs'`. For JSX, enable `jsx: true` in the `parse` options.
affects: >=1.0.0
Errors
Common errors & fixes
SyntaxError: The 'import' keyword is not allowed in CommonJS modules.
Attempting to parse ES module syntax (e.g., `import`, `export`) when Meriyah is configured for 'script' or 'commonjs' `sourceType`.
fix
Pass `{ sourceType: 'module' }` to the `parse` options: `parse(code, { sourceType: 'module' });`
SyntaxError: Unexpected token '<'
Parsing JSX syntax (e.g., `<div />`) without enabling the `jsx` option.
fix
Pass `{ jsx: true }` to the `parse` options: `parse(code, { jsx: true });`
SyntaxError: Invalid regular expression: /(?<word>\w+)/d: Invalid group specifier name
Meriyah uses the JavaScript runtime for RegExp validation, and the current Node.js version does not support a specific RegExp feature used in the parsed code.
fix
Update your Node.js environment to a version that supports the required RegExp features (e.g., Node.js >= 24). Alternatively, set `validateRegex: false` in the parse options to bypass runtime RegExp validation.
Upgrade
Version history
7.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources