{"id":16119,"library":"meriyah","title":"Meriyah JavaScript Parser","description":"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.","status":"active","version":"7.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/meriyah/meriyah","tags":["javascript","parsing","ecmascript","parser","estree","esnext","lexer","ast","typescript"],"install":[{"cmd":"npm install meriyah","lang":"bash","label":"npm"},{"cmd":"yarn add meriyah","lang":"bash","label":"yarn"},{"cmd":"pnpm add meriyah","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"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.","wrong":"const { parse } = require('meriyah');","symbol":"parse","correct":"import { parse } from 'meriyah';"},{"note":"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.","wrong":"import isParseError from 'meriyah';","symbol":"isParseError","correct":"import { isParseError } from 'meriyah';"},{"note":"For TypeScript users, `ParserOptions` is a type definition and should be imported using `import type` to avoid runtime side effects or errors.","wrong":"import { ParserOptions } from 'meriyah';","symbol":"ParserOptions","correct":"import type { ParserOptions } from 'meriyah';"}],"quickstart":{"code":"import { parse, isParseError } from 'meriyah';\nimport type { Program } from 'estree'; // Assuming ESTree types are needed for the result\n\nconst javascriptCode = `\n  // This is a complex JavaScript module demonstrating various features.\n  import { someUtil } from './utils.js';\n\n  @debounce(300)\n  class MyClass {\n    #privateField = 42; // Private class field (ES2022)\n\n    constructor(name) {\n      this.name = name;\n    }\n\n    // A method with decorators (TC39 Stage 3, requires 'next' option)\n    @log\n    greet(param) {\n      console.log(`Hello, ${this.name}! ${param}`);\n      return someUtil(this.#privateField);\n    }\n  }\n\n  export const instance = new MyClass('Meriyah User');\n\n  // Example of Annex B feature (non-strict mode)\n  // function foo() { 'use strict'; with (obj) {} } // This would error in strict mode\n  \n  // A regular expression with newer features (requires Node.js >= 24 for full validation)\n  const regex = /(?<word>\\w+)/d; \n  if (\"test\".match(regex)) {\n    console.log(\"Matched!\");\n  }\n`;\n\ntry {\n  const ast: Program = parse(javascriptCode, {\n    sourceType: 'module', // Parse as an ES module\n    ranges: true,        // Include start/end offsets for each node\n    loc: true,           // Include line/column location information\n    next: true,          // Enable TC39 Stage 3 proposals (e.g., Decorators)\n    jsx: false,          // Explicitly disable JSX (if not needed)\n    webcompat: true,     // Enable web compatibility (Annex B)\n    validateRegex: true, // Validate regular expressions with the current JS runtime\n  });\n\n  console.log('Successfully parsed AST:');\n  // console.log(JSON.stringify(ast, null, 2)); // Uncomment to see the full AST\n  console.log(`Program type: ${ast.type}`);\n  console.log(`First statement type: ${ast.body[0].type}`);\n\n} catch (e: any) {\n  if (isParseError(e)) {\n    console.error(`Meriyah Parse Error: ${e.message} at line ${e.loc?.line}, column ${e.loc?.column}`);\n  } else {\n    console.error('An unexpected error occurred:', e.message);\n  }\n}","lang":"typescript","description":"Demonstrates parsing a complex JavaScript module with various features, including ESNext proposals, web compatibility, location tracking, and error handling."},"warnings":[{"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.","message":"As 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.","severity":"breaking","affected_versions":">=7.1.0"},{"fix":"For projects requiring TypeScript or Flow parsing, consider alternative parsers like `@typescript-eslint/typescript-estree` or `babel-parser`.","message":"Meriyah explicitly does NOT support TypeScript or Flow syntax. It is designed solely for parsing standard ECMAScript and select Stage 3 TC39 proposals.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"RegExp 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).","severity":"gotcha","affected_versions":">=6.1.0"},{"fix":"Ensure your project's Node.js version meets the `engines.node` requirement (>=20.0.0).","message":"Meriyah requires Node.js version 20.0.0 or higher. Running Meriyah on older Node.js environments will result in errors.","severity":"breaking","affected_versions":">=7.0.0"},{"fix":"For ES modules, use `sourceType: 'module'`. For CommonJS, use `sourceType: 'commonjs'`. For JSX, enable `jsx: true` in the `parse` options.","message":"Parsing code as an ES module, CommonJS module, or with JSX syntax requires explicit options. The default `sourceType` is 'script', and `jsx` is `false`.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Pass `{ sourceType: 'module' }` to the `parse` options: `parse(code, { sourceType: 'module' });`","cause":"Attempting to parse ES module syntax (e.g., `import`, `export`) when Meriyah is configured for 'script' or 'commonjs' `sourceType`.","error":"SyntaxError: The 'import' keyword is not allowed in CommonJS modules."},{"fix":"Pass `{ jsx: true }` to the `parse` options: `parse(code, { jsx: true });`","cause":"Parsing JSX syntax (e.g., `<div />`) without enabling the `jsx` option.","error":"SyntaxError: Unexpected token '<'"},{"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.","cause":"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.","error":"SyntaxError: Invalid regular expression: /(?<word>\\w+)/d: Invalid group specifier name"}],"ecosystem":"npm"}