Registry / serialization / esformatter-parser

esformatter-parser

JSON →
library1.0.0jsnpmunverified

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-parser
INSTALL
IMPORT
SIG · ESFORMATTER-PARSER
E
esformatter-parser
serializationjavascriptv1.0.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
const { parse } = require('esformatter-parser');
import { parse } from 'esformatter-parser';
This package is CommonJS-only and does not export ES Modules.
parse
const parse = require('esformatter-parser').parse;
Alternative CommonJS import style for the named export.

Demonstrates how to import and use the `parse` function to generate an Esprima-compatible AST from a JavaScript string, and inspect basic AST properties.

const { parse } = require('esformatter-parser'); const code = ` const greet = (name) => { console.log('Hello, ' + name + '!'); }; greet('World'); `; try { // The parse function returns an Esprima-compatible AST decorated by Rocambole. const ast = parse(code); console.log('Successfully parsed code into an AST.'); // Example of accessing AST properties (specifics depend on Rocambole/Esprima AST structure) if (ast && ast.body && ast.body.length > 0) { console.log('AST Root Type:', ast.type); console.log('First statement type:', ast.body[0].type); if (ast.body[0].type === 'VariableDeclaration') { console.log('First variable name:', ast.body[0].declarations[0].id.name); } } else { console.log('AST body is empty or malformed.'); } } catch (error) { console.error('Failed to parse code:', error.message); // Note: This package uses older parsers and might struggle with very modern syntax. }
Debug
Known issues
breakingThe 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.
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.
affects: 1.0.0
deprecatedThis 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.
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`.
affects: 1.0.0
gotchaThe 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.
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.
affects: 1.0.0
gotchaThe 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.
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.
affects: 1.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'body')
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.
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.
ERR_REQUIRE_ESM: require() of ES Module ... not supported.
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.
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.
SyntaxError: Unexpected token (XX:YY)
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.
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.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
babylonrequiredCore JavaScript parsing engine, since superseded by @babel/parser.
acorn-to-esprimarequiredTransforms Babylon/Acorn AST into an Esprima-compatible format.
rocambolerequiredDecorates the AST with additional properties and methods for easier traversal and manipulation.
Agent activity
7 hits · last 30 days
node
6
Amazon
1
Resources
esformatter-parser — npm install esformatter-parser · libregistry