Registry / serialization / edgejs-parser

edgejs-parser

JSON →
library0.2.19jsnpmunverified

EdgeJS Parser is a specialized JavaScript library designed for parsing HTML and EdgeJS templating syntax, returning an Abstract Syntax Tree (AST). Currently at version 0.2.19, it is built upon the Chevrotain parsing toolkit. Its development is specifically tailored towards the creation of a Prettier plugin for EdgeJS templates, which implies it may not encompass all potential parsing needs or edge cases outside of that particular use-case. As a 0.x.x release, the API may still be subject to changes before a stable 1.0 version. While a formal release cadence isn't specified, updates are likely driven by the needs of its primary Prettier integration.

npm install edgejs-parser
INSTALL
IMPORT
SIG · EDGEJS-PARSER
E
edgejs-parser
serializationjavascriptv0.2.19
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.

edgeParser
import edgeParser from 'edgejs-parser';
const edgeParser = require('edgejs-parser');
This package is an ES Module (`'type': 'module'`). CommonJS `require()` syntax is not supported and will result in a runtime error. Ensure your project is configured for ESM.

This quickstart demonstrates how to install `edgejs-parser` and use its default export to parse a simple EdgeJS template into an Abstract Syntax Tree (AST), including basic error handling for malformed input.

import edgeParser from 'edgejs-parser'; const edgeTemplate = ` @if(user) <h1>Hello, {{ user.name }}!</h1> @else <p>Please log in.</p> @end <a href="/dashboard">Go to Dashboard</a> `; try { const ast = edgeParser(edgeTemplate); console.log('Successfully parsed template. AST structure (truncated):'); console.log(JSON.stringify(ast, null, 2).substring(0, 500) + '...'); } catch (error) { console.error('Error parsing template:', error.message); } // Example with an invalid template to demonstrate error handling const invalidTemplate = ` @if(user) <div>Invalid syntax here</div> @end`; try { edgeParser(invalidTemplate); } catch (error) { console.error('\nError parsing invalid template (expected):', error.message); }
Debug
Known issues
gotchaThe parser is specifically designed for EdgeJS Prettier plugin integration and may not handle all general-purpose parsing requirements for EdgeJS or HTML. Its scope is narrow and might not cover all EdgeJS features or complex HTML structures.
fix
Evaluate if the library's specific scope aligns with your project's parsing needs. For broader or more general parsing, consider alternative, more comprehensive HTML/templating parsers.
affects: >=0.2.0
breakingAs a pre-1.0 library (currently v0.2.19), the API is unstable and subject to breaking changes without major version bumps. The internal AST structure, in particular, is not guaranteed to remain consistent across minor versions.
fix
Always consult the latest documentation and changelog when upgrading 0.x versions. Be prepared to adapt your code to API changes, especially when interacting directly with the AST.
affects: <1.0.0
gotchaThe Abstract Syntax Tree (AST) structure returned by the parser is considered an internal implementation detail and is primarily documented via the 'visitor.js' file in the source. It is not explicitly typed for consumption and may change without notice.
fix
Avoid making assumptions about the exact AST shape. Implement robust error handling for unexpected structures or use the library as intended for its specific Prettier plugin use case, where the AST is an internal concern.
affects: >=0.2.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM: Must use import to load ES Module: .../node_modules/edgejs-parser/index.js
Attempting to import the 'edgejs-parser' package using CommonJS `require()` syntax in a Node.js environment.
fix
Update your module to use ES module syntax: `import edgeParser from 'edgejs-parser';`. Ensure your project's `package.json` specifies `"type": "module"` or that your file uses a `.mjs` extension for ESM context.
Parsing error: Unexpected token or invalid syntax at position X in template Y
The parser encountered an unexpected token or malformed syntax in the provided EdgeJS template, indicating a parsing failure at a specific point.
fix
Review the input template for syntax errors at the indicated position (X). Ensure the template adheres strictly to EdgeJS and HTML parsing rules expected by the library.
Upgrade
Version history
0.2.19latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
edgejs-parser — npm install edgejs-parser · libregistry