{"id":13102,"library":"edgejs-parser","title":"EdgeJS Parser","description":"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.","status":"active","version":"0.2.19","language":"javascript","source_language":"en","source_url":"https://github.com/sajansharmanz/edgejs-parser","tags":["javascript","edge","edgejs","parser","typescript"],"install":[{"cmd":"npm install edgejs-parser","lang":"bash","label":"npm"},{"cmd":"yarn add edgejs-parser","lang":"bash","label":"yarn"},{"cmd":"pnpm add edgejs-parser","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"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.","wrong":"const edgeParser = require('edgejs-parser');","symbol":"edgeParser","correct":"import edgeParser from 'edgejs-parser';"}],"quickstart":{"code":"import edgeParser from 'edgejs-parser';\n\nconst edgeTemplate = `\n@if(user) \n  <h1>Hello, {{ user.name }}!</h1>\n@else\n  <p>Please log in.</p>\n@end\n<a href=\"/dashboard\">Go to Dashboard</a>\n`;\n\ntry {\n  const ast = edgeParser(edgeTemplate);\n  console.log('Successfully parsed template. AST structure (truncated):');\n  console.log(JSON.stringify(ast, null, 2).substring(0, 500) + '...');\n} catch (error) {\n  console.error('Error parsing template:', error.message);\n}\n\n// Example with an invalid template to demonstrate error handling\nconst invalidTemplate = `\n@if(user)\n  <div>Invalid syntax here</div>\n@end`;\n\ntry {\n  edgeParser(invalidTemplate);\n} catch (error) {\n  console.error('\\nError parsing invalid template (expected):', error.message);\n}","lang":"typescript","description":"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."},"warnings":[{"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.","message":"The 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.","severity":"gotcha","affected_versions":">=0.2.0"},{"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.","message":"As 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.","severity":"breaking","affected_versions":"<1.0.0"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":">=0.2.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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.","cause":"Attempting to import the 'edgejs-parser' package using CommonJS `require()` syntax in a Node.js environment.","error":"ERR_REQUIRE_ESM: Must use import to load ES Module: .../node_modules/edgejs-parser/index.js"},{"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.","cause":"The parser encountered an unexpected token or malformed syntax in the provided EdgeJS template, indicating a parsing failure at a specific point.","error":"Parsing error: Unexpected token or invalid syntax at position X in template Y"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":""}