Socket
Socket
Sign inDemoInstall

pug-parser

Package Overview
Dependencies
2
Maintainers
3
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    pug-parser

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


Version published
Weekly downloads
1.4M
decreased by-16.2%
Maintainers
3
Install size
47.3 kB
Created
Weekly downloads
 

Readme

Source

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

Keywords

FAQs

Last updated on 25 May 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc