{"id":13136,"library":"esformatter-parser","title":"ESFormatter Parser","description":"esformatter-parser is an abandoned internal utility package primarily developed for esformatter. It provides a specialized JavaScript parser that wraps around several other parsing tools: Babylon (the predecessor to @babel/parser), acorn-to-esprima, and rocambole. Its core function is to parse JavaScript code using Babylon, then transform the resulting Abstract Syntax Tree (AST) into an Esprima-compatible format using acorn-to-esprima, and finally decorate it with rocambole for enhanced traversal and manipulation within the esformatter ecosystem. This approach allowed esformatter to leverage Babylon's modern JavaScript parsing capabilities while maintaining compatibility with its Esprima-based AST processing logic. The package's current stable version is 1.0.0, released over six years ago, and it is no longer actively maintained or updated. Its release cadence was tied directly to esformatter's development, which has also ceased. Key differentiators include its unique combination of parsers to achieve specific AST compatibility, rather than serving as a general-purpose parser for direct application use.","status":"abandoned","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/millermedeiros/esformatter-parser","tags":["javascript","babel","babylon","esformatter","esprima","parser","rocambole"],"install":[{"cmd":"npm install esformatter-parser","lang":"bash","label":"npm"},{"cmd":"yarn add esformatter-parser","lang":"bash","label":"yarn"},{"cmd":"pnpm add esformatter-parser","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core JavaScript parsing engine, since superseded by @babel/parser.","package":"babylon","optional":false},{"reason":"Transforms Babylon/Acorn AST into an Esprima-compatible format.","package":"acorn-to-esprima","optional":false},{"reason":"Decorates the AST with additional properties and methods for easier traversal and manipulation.","package":"rocambole","optional":false}],"imports":[{"note":"This package is CommonJS-only and does not export ES Modules.","wrong":"import { parse } from 'esformatter-parser';","symbol":"parse","correct":"const { parse } = require('esformatter-parser');"},{"note":"Alternative CommonJS import style for the named export.","symbol":"parse","correct":"const parse = require('esformatter-parser').parse;"}],"quickstart":{"code":"const { parse } = require('esformatter-parser');\n\nconst code = `\nconst greet = (name) => {\n  console.log('Hello, ' + name + '!');\n};\n\ngreet('World');\n`;\n\ntry {\n  // The parse function returns an Esprima-compatible AST decorated by Rocambole.\n  const ast = parse(code);\n  console.log('Successfully parsed code into an AST.');\n\n  // Example of accessing AST properties (specifics depend on Rocambole/Esprima AST structure)\n  if (ast && ast.body && ast.body.length > 0) {\n    console.log('AST Root Type:', ast.type);\n    console.log('First statement type:', ast.body[0].type);\n    if (ast.body[0].type === 'VariableDeclaration') {\n      console.log('First variable name:', ast.body[0].declarations[0].id.name);\n    }\n  } else {\n    console.log('AST body is empty or malformed.');\n  }\n\n} catch (error) {\n  console.error('Failed to parse code:', error.message);\n  // Note: This package uses older parsers and might struggle with very modern syntax.\n}","lang":"javascript","description":"Demonstrates how to import and use the `parse` function to generate an Esprima-compatible AST from a JavaScript string, and inspect basic AST properties."},"warnings":[{"fix":"There is no direct fix for this package. For modern JavaScript parsing, migrate to `@babel/parser` or `acorn` directly, or use actively maintained formatting tools that incorporate them.","message":"The underlying `babylon` package (a dependency of esformatter-parser) has been deprecated and replaced by `@babel/parser`. This means `esformatter-parser` relies on an outdated parser version, potentially leading to incorrect parsing or failures for newer JavaScript syntax features.","severity":"breaking","affected_versions":"1.0.0"},{"fix":"Avoid using this package. For formatting or AST manipulation, consider actively maintained alternatives like Prettier, ESLint, or direct usage of `@babel/parser` or `acorn` with tools like `estraverse` or `ast-types`.","message":"This package is considered abandoned. It has not been updated in over six years and will not receive updates for new JavaScript syntax, bug fixes, or security patches. Using it in new projects is strongly discouraged.","severity":"deprecated","affected_versions":"1.0.0"},{"fix":"Always use `const { parse } = require('esformatter-parser');` for importing this package in both CommonJS and potentially in ES Modules via a compatibility layer or by explicitly setting `type: \"commonjs\"` in `package.json` for relevant files.","message":"The package uses a CommonJS module system. Attempting to `import { parse } from 'esformatter-parser'` in an ES Module context will result in a module resolution error or unexpected behavior, particularly in Node.js environments configured for ESM.","severity":"gotcha","affected_versions":"1.0.0"},{"fix":"Ensure that any downstream tools or logic expecting an AST are compatible with the Esprima format. If migrating from this package, be prepared for potential AST structure changes.","message":"The AST generated by `esformatter-parser` is an Esprima-compatible AST (decorated by Rocambole). While widely used, this format may differ from the ASTs generated by Babel's modern parsers or Acorn directly, which can cause incompatibility with tools expecting a different AST structure or specific non-standardized properties.","severity":"gotcha","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":"Review the input JavaScript code for syntax errors. Ensure that the code does not use very recent JavaScript features (e.g., optional chaining, nullish coalescing, top-level await) that were introduced after `babylon@6.8.0`'s release. If modern syntax is required, this package cannot be used.","cause":"The input code contains syntax errors or features not supported by the outdated `babylon` parser used internally, leading to a failed parse and an incomplete or `undefined` AST object.","error":"TypeError: Cannot read properties of undefined (reading 'body')"},{"fix":"This specific error message is unlikely to occur for *this* package, as it is CJS. However, if using other CJS dependencies in an ESM project, you might encounter similar errors. The problem is usually trying to *import* an ESM module using `require`. For this CJS package, ensure your consuming code is either CJS or uses dynamic `import()` if bridging from ESM to CJS.","cause":"Attempting to `require()` this CommonJS package within an environment (e.g., a Node.js project with `\"type\": \"module\"` in `package.json`) that is strictly enforcing ES Modules.","error":"ERR_REQUIRE_ESM: require() of ES Module ... not supported."},{"fix":"Update your JavaScript code to be compatible with older ECMAScript standards (ES2016 or earlier mostly) or switch to a modern parser such as `@babel/parser` or `acorn` that supports the latest ECMAScript features.","cause":"The `babylon` parser (a dependency) encountered a syntax construct that it did not recognize, likely due to the input code using modern JavaScript syntax that was introduced after `babylon@6.8.0` was released.","error":"SyntaxError: Unexpected token (XX:YY)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":""}