npm.io
0.2.2 • Published 3 years ago

twig-parser

Licence
Mozilla Public License 2.0
Version
0.2.2
Deps
1
Size
156 kB
Vulns
0
Weekly
0
Stars
3

Twig Parser

This tool transforms a twig template to AST. It uses chevrotain under the hood.

How to use it

import { parse } from 'twig-parser';

const twig = `
  {% set foo = range(0, 3) %}

  {% for i in foo %}
      {{ i }},
  {% endfor %}
`

const { ast, tokens, errors } = parse(twig);

Notes

  1. Whitespace trimming is not supported
  2. The body of the verbatim tag is parsed as a regular template