{"id":11916,"library":"recma-parse","title":"recma JavaScript Parser Plugin","description":"recma-parse is a unified plugin for the recma ecosystem, designed to transform JavaScript source code into an Abstract Syntax Tree (AST). It leverages `esast-util-from-js` internally to parse JavaScript according to the ECMA-262 standard, producing ASTs in both esast and estree formats. As of its current stable version, 1.0.0, it is an ESM-only package, strictly requiring Node.js 16 or newer for execution. This package is part of the actively maintained `recma` monorepo, which provides a cohesive suite of tools for processing JavaScript ASTs, akin to how `remark` handles Markdown and `rehype` processes HTML. It differentiates itself by offering a robust, standards-compliant parsing step within the unified transformation pipeline, providing a foundational component for various JavaScript code transformations and analyses.","status":"active","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/mdx-js/recma#main","tags":["javascript","abstract","ast","parse","plugin","recma-plugin","recma","syntax","typescript"],"install":[{"cmd":"npm install recma-parse","lang":"bash","label":"npm"},{"cmd":"yarn add recma-parse","lang":"bash","label":"yarn"},{"cmd":"pnpm add recma-parse","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"recma-parse is a unified plugin and relies on the unified processor for its core functionality.","package":"unified","optional":false},{"reason":"This package is used internally by recma-parse to perform the actual JavaScript parsing.","package":"esast-util-from-js","optional":false}],"imports":[{"note":"'recma-parse' provides a default export only; named imports will result in an error.","wrong":"import { recmaParse } from 'recma-parse'","symbol":"recmaParse","correct":"import recmaParse from 'recma-parse'"},{"note":"'recma-parse' is an ESM-only package since v1.0.0 and does not support CommonJS 'require()' syntax.","wrong":"const recmaParse = require('recma-parse')","symbol":"recmaParse","correct":"import recmaParse from 'recma-parse'"},{"note":"For TypeScript users to import the type definition for parser configuration options.","symbol":"Options","correct":"import type { Options } from 'recma-parse'"}],"quickstart":{"code":"import recmaBuildJsx from 'recma-build-jsx'\nimport recmaJsx from 'recma-jsx'\nimport recmaParse from 'recma-parse'\nimport recmaStringify from 'recma-stringify'\nimport { unified } from 'unified'\n\nasync function processJsx() {\n  const file = await unified()\n    .use(recmaParse)\n    .use(recmaJsx)\n    .use(recmaBuildJsx)\n    .use(recmaStringify)\n    .process('console.log(<em>Hi!</em>)')\n\n  console.log(String(file))\n}\n\nprocessJsx()\n","lang":"javascript","description":"This example demonstrates how to set up a unified pipeline using recma-parse to parse JavaScript, transform JSX elements using recma-jsx and recma-build-jsx, and then serialize the modified AST back into JavaScript code using recma-stringify. It processes a simple JSX expression and outputs the equivalent React.createElement call."},"warnings":[{"fix":"Migrate your project to ESM imports or use dynamic `import()` for compatibility if absolutely necessary. Ensure your Node.js version is 16+.","message":"recma-parse is an ECMAScript Module (ESM) only package. It cannot be directly imported using CommonJS `require()` and requires a Node.js environment configured for ESM (e.g., `\"type\": \"module\"` in `package.json` or using `.mjs` file extensions).","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Never evaluate untrusted JavaScript code directly. Implement strict input validation and sanitization for any code passed to the parser or subsequent plugins.","message":"As recma-parse processes JavaScript code, evaluating potentially unsafe or untrusted input through recma plugins can lead to security vulnerabilities. Always sanitize and validate any user-provided JavaScript code before processing it.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure your project runs on a currently maintained version of Node.js (16+ for v1.x) to maintain compatibility and receive security updates.","message":"recma-parse@1 is compatible with Node.js 16 and newer. Future major releases will drop support for unmaintained Node.js versions, potentially requiring environment upgrades.","severity":"breaking","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Change the import statement to use the default import syntax: `import recmaParse from 'recma-parse'`.","cause":"Attempting to import 'recmaParse' as a named export when 'recma-parse' only provides a default export.","error":"SyntaxError: The requested module 'recma-parse' does not provide an export named 'recmaParse'"},{"fix":"Convert your consuming module to an ES Module (e.g., by adding `\"type\": \"module\"` to your `package.json` or renaming the file to `.mjs`) and use `import recmaParse from 'recma-parse'`.","cause":"Trying to import `recma-parse` using CommonJS `require()` syntax in a CommonJS module, but `recma-parse` is an ESM-only package.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module .../node_modules/recma-parse/index.js from .../your-file.js not supported."}],"ecosystem":"npm"}