1. pug-parser
The pug parser (takes an array of tokens and converts it to an abstract syntax tree)
pug-parser
Package: pug-parser
Created by: pugjs
Last modified: Sat, 25 Jun 2022 00:06:41 GMT
Version: 6.0.0
License: MIT
Downloads: 6,873,645
Repository: https://github.com/pugjs/pug/tree/master/packages/pug-parser

Install

npm install pug-parser
yarn add pug-parser

pug-parser

The pug parser (takes an array of tokens and converts it to an abstract syntax tree)

Build Status
Dependencies Status
DevDependencies Status
NPM version

Installation

npm install pug-parser

Usage

 var parse = require('pug-parser');

parse(tokens, options)

Convert Pug tokens to an abstract syntax tree (AST).

options can contain the following properties:

  • filename (string): The name of the Pug file; it is included in the produced AST nodes and error handling, if provided.
  • plugins (array): An array of plugins, in the order they should be applied.
  • src (string): The source of the Pug file; it is used in error handling if provided.
 var lex = require('pug-lexer');

var filename = 'my-file.pug';
var src = 'div(data-foo="bar")';
var tokens = lex(src, {filename});

var ast = parse(tokens, {filename, src});

console.log(JSON.stringify(ast, null, '  '))
 {
  "type": "Block",
  "nodes": [
    {
      "type": "Tag",
      "name": "div",
      "selfClosing": false,
      "block": {
        "type": "Block",
        "nodes": [],
        "line": 1,
        "filename": "my-file.pug"
      },
      "attrs": [
        {
          "name": "data-foo",
          "val": "\"bar\"",
          "line": 1,
          "column": 5,
          "filename": "my-file.pug",
          "mustEscape": true
        }
      ],
      "attributeBlocks": [],
      "isInline": false,
      "line": 1,
      "column": 1,
      "filename": "my-file.pug"
    }
  ],
  "line": 0,
  "filename": "my-file.pug"
}

new parse.Parser(tokens, options)

Constructor for a Parser 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 included in the produced AST nodes and error handling, if provided.
  • plugins (array): An array of plugins, in the order they should be applied.
  • src (string): The source of the Pug file; it is used in error handling if provided.

License

MIT

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin