@react-pug/pug-lexer
v0.1.7
Published
The pug lexer (takes a string and converts it to an array of tokens)
Readme
@react-pug/pug-lexer
The Pug lexer. This module is responsible for taking a string and converting it into an array of tokens.
Installation
npm install @react-pug/pug-lexerUsage
var lex = require('@react-pug/pug-lexer');lex(str, options)
Convert Pug string to an array of tokens.
options can contain the following properties:
filename(string): The name of the Pug file; it is used in error handling if provided.plugins(array): An array of plugins, in the order they should be applied.
For react-pug usage, this fork also supports modern TypeScript expression syntax inside Pug expressions and attributes, including as, satisfies, typed inline handlers, and spread attrs with TS casts.
console.log(JSON.stringify(lex('div(data-foo="bar")', {filename: 'my-file.pug'}), null, ' '))[
{
"type": "tag",
"line": 1,
"val": "div",
"selfClosing": false
},
{
"type": "attrs",
"line": 1,
"attrs": [
{
"name": "data-foo",
"val": "\"bar\"",
"escaped": true
}
]
},
{
"type": "eos",
"line": 1
}
]new lex.Lexer(str, options)
Constructor for a Lexer class. This is not meant to be used directly unless you know what you are doing.
options may contain the following properties:
filename(string): The name of the Pug file; it is used in error handling if provided.interpolated(boolean): if the Lexer is created as a child lexer for inline tag interpolation (e.g.#[p Hello]). Defaults tofalse.startingLine(integer): the real line number of the first line in the input. It is also used for inline tag interpolation. Defaults to1.plugins(array): An array of plugins, in the order they should be applied.
License
MIT
Notes
- This package is maintained in the
react-pugmonorepo. - It is a forked, vendored copy aligned with
react-pug's TypeScript-in-Pug requirements. - Version numbering was reset under the
@react-pug/*namespace, so0.1.6is newer than the older upstream-derived4.xpackage line previously used here.
Attribution
This package is derived from the original pug-lexer package in the pugjs/pug monorepo:
https://github.com/pugjs/pug/tree/master/packages/pug-lexer
