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.
npm install esformatter-parserVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to import and use the `parse` function to generate an Esprima-compatible AST from a JavaScript string, and inspect basic AST properties.
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.
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`.
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.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.
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.
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.
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.