# pug-parser

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

Latest version **6.0.0** (published 2020-05-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install pug-parser
pnpm add pug-parser
yarn add pug-parser
bun add pug-parser
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: no vulnerabilities; popular repo.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 6.0.0 |
| Published | 2020-05-25 |
| First published | 2015-12-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 35 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 21848 |
| Author | ForbesLindesay |
| Maintainers | forbeslindesay, pug-bot, timothygu |
| Keywords | pug |

## Links

- npm: https://www.npmjs.com/package/pug-parser
- Repository: https://github.com/pugjs/pug/tree/master/packages/pug-parser
- npm.io page: https://npm.io/package/pug-parser

## Dependencies (2)

- [pug-error](https://npm.io/package/pug-error.md) ^2.0.0
- [token-stream](https://npm.io/package/token-stream.md) 1.0.0

## Recent versions

- 6.0.0 (latest) — 2020-05-25
- 6.0.0-canary-2 (canary) — 2020-05-25
- 6.0.0-canary-1 — 2020-05-24
- 5.0.1 — 2019-06-18
- 4.0.2 — 2018-03-08
- 5.0.0 — 2018-03-08
- 4.0.1 — 2018-03-06
- 4.0.0 — 2017-09-06
- 3.0.1 — 2017-08-01
- 3.0.0 — 2017-06-02
- 2.0.2 — 2017-01-24
- 2.0.1 — 2016-06-01
- 2.0.0 — 2016-05-14
- 1.0.0 — 2015-12-23
- 0.0.0 — 2015-12-12

## README

# pug-parser

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

[![Build Status](https://img.shields.io/travis/pugjs/pug-parser/master.svg)](https://travis-ci.org/pugjs/pug-parser)
[![Dependencies Status](https://david-dm.org/pugjs/pug/status.svg?path=packages/pug-parser)](https://david-dm.org/pugjs/pug?path=packages/pug-parser)
[![DevDependencies Status](https://david-dm.org/pugjs/pug/dev-status.svg?path=packages/pug-parser)](https://david-dm.org/pugjs/pug?path=packages/pug-parser&type=dev)
[![NPM version](https://img.shields.io/npm/v/pug-parser.svg)](https://www.npmjs.org/package/pug-parser)

## Installation

    npm install pug-parser

## Usage

```js
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.

```js
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, '  '))
```

```json
{
  "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

---
_Source: https://npm.io/package/pug-parser · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
