edge-parser is a JavaScript/TypeScript library designed to parse the syntax of the Edge template engine, converting template strings into executable JavaScript functions. It is currently stable at version 9.1.0 (published December 2025), with recent releases focusing on features like update expression support and dependency updates. The library provides a programmatic API for tokenizing template input, transforming its Abstract Syntax Tree (AST), and processing tokens into a final JavaScript output, which can then be invoked with template state. A key differentiator is its explicit handling of error tracing within compiled templates via `filename` and `lineNumber` parameters, and highly configurable options for managing template variables (`statePropertyName`) and helper function paths (`escapeCallPath`, `toAttributesCallPath`).
npm install edge-parserVerified import paths — ran on the pinned version, not inferred.
This code demonstrates how to initialize the Edge Parser, tokenize a template string, process the tokens into a JavaScript function, and then execute that function with a given state and helper utilities, including basic error handling.
Migrate all imports from CommonJS `require()` to ES Modules `import` syntax. Ensure your project is configured for ESM (e.g., `"type": "module"` in `package.json`).
Update type imports to use the `edge-parser/types` subpath, e.g., `import type { ParserConfig } from 'edge-parser/types';`Always provide a descriptive `filename` string when calling `parser.tokenize(template, { filename })` and initializing `new EdgeBuffer(filename, ...)`. This `filename` is embedded in the compiled output for error reporting.Carefully review the documentation for each configuration option and ensure the provided values correctly map to the expected global variables or helper functions available at the time the compiled template function is executed. For example, `escapeCallPath: 'escape'` implies an `escape` function will be available in the template's execution scope.
Change `const { Parser } = require('edge-parser');` to `import { Parser } from 'edge-parser';`. Ensure your `package.json` has `"type": "module"` or use a `.mjs` file extension for your script.For versions `>=9.0.0`, ensure you use `import { Parser } from 'edge-parser';`. For versions `<9.0.0`, ensure you are correctly importing named exports (if using `require`, it might be `const { Parser } = require('edge-parser');` or `const Parser = require('edge-parser').Parser;` depending on exact package structure).If using `edge-parser@<9.0.0`, types were likely directly from `edge-parser`. Update your import to `import type { ParserConfig } from 'edge-parser';`. If on `edge-parser@>=9.0.0`, double-check the exact subpath spelling: `import type { ParserConfig } from 'edge-parser/types';`When creating `new Parser()`, ensure `statePropertyName` matches the variable name you intend to pass to the compiled function. When invoking the `new Function(...)` output, pass the state object as the first argument, e.g., `fn(myState, escape, reThrow)`.
No dependency data recorded yet.