# @textlint/ast-traverse

> TxtNode traverse library

Latest version **15.8.0** (published 2026-08-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install @textlint/ast-traverse
pnpm add @textlint/ast-traverse
yarn add @textlint/ast-traverse
bun add @textlint/ast-traverse
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 15.8.0 |
| Published | 2026-08-01 |
| First published | 2018-01-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 25.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 3181 |
| Author | azu |
| Maintainers | azu, textlint-user |
| Keywords | AST, traverse |

## Links

- npm: https://www.npmjs.com/package/@textlint/ast-traverse
- Repository: https://github.com/textlint/textlint
- Homepage: https://github.com/textlint/textlint/tree/master/packages/@textlint/ast-traverse
- Issues: https://github.com/textlint/textlint/issues
- npm.io page: https://npm.io/package/@textlint/ast-traverse

## Dependencies (1)

- [@textlint/ast-node-types](https://npm.io/package/@textlint/ast-node-types.md) 15.8.0

## Alternatives

- [update-check](https://npm.io/package/update-check.md) — 4.0M weekly downloads
- [react-native-onesignal](https://npm.io/package/react-native-onesignal.md) — 134.5K weekly downloads
- [react-redux-toastr](https://npm.io/package/react-redux-toastr.md) — 33.7K weekly downloads
- [@nocobase/plugin-notification-manager](https://npm.io/package/@nocobase/plugin-notification-manager.md) — 2.0K weekly downloads
- [react-simple-toasts](https://npm.io/package/react-simple-toasts.md) — 1.9K weekly downloads

## Recent versions

- 15.8.0 (latest) — 2026-08-01
- 13.4.2-next.0 (next) — 2024-02-02
- 12.0.0-beta.3 (beta) — 2021-05-24
- 2.1.0-alpha.0f2fd6f9 (canary) — 2018-07-16
- 15.7.1 — 2026-05-18
- 15.7.0 — 2026-05-14
- 15.6.1 — 2026-05-11
- 15.6.0 — 2026-04-26
- 15.5.4 — 2026-04-09
- 15.5.2 — 2026-02-21
- 15.5.1 — 2026-01-19
- 15.5.0 — 2025-12-07
- 15.4.1 — 2025-12-03
- 15.4.0 — 2025-11-17
- 15.3.0 — 2025-11-10
- … 93 more at https://npm.io/package/@textlint/ast-traverse/versions

## README

# @textlint/ast-traverse

@textlint/ast-traverse provide traversal functions for [TxtAST](https://github.com/textlint/textlint/blob/master/docs/txtnode.md "TxtAST").

This traverse function is a fork of [estraverse](https://github.com/estools/estraverse "Estraverse") for [@textlint/markdown-to-ast](https://github.com/textlint/textlint/tree/master/packages/@textlint/markdown-to-ast/ "textlint/markdown-to-ast").

This library is a part of [textlint/textlint](https://github.com/textlint/textlint "textlint/textlint").

## Installation

```
npm install @textlint/ast-traverse
```

## Usage

```js
var parse = require("@textlint/markdown-to-ast").parse,
    Syntax = require("@textlint/markdown-to-ast").Syntax;
var traverse = require("@textlint/ast-traverse").traverse,
    VisitorOption = require("@textlint/ast-traverse").VisitorOption;
var AST = parse("# Header\nHello*world*");
traverse(AST, {
    enter(node) {
        console.log("enter", node.type);
        if (node.type === Syntax.Strong) {
            return VisitorOption.Skip;
        }
    },
    leave(node) {
        console.log("leave", node.type);
    }
});
```

Traversal rule is the same with [Estraverse](https://github.com/estools/estraverse "Estraverse").

## Example

Markdown:

```markdown
Hello *world*
```

AST:

```json
{
    "start_line": 1,
    "start_column": 1,
    "end_line": 0,
    "children": [
        {
            "start_line": 1,
            "start_column": 1,
            "end_line": 0,
            "inline_content": [
                {
                    "c": "Hello",
                    "raw": "Hello",
                    "loc": {
                        "start": {
                            "line": 1,
                            "column": 0
                        },
                        "end": {
                            "line": 1,
                            "column": 5
                        }
                    },
                    "range": [
                        0,
                        5
                    ],
                    "type": "Str"
                },
                {
                    "c": " ",
                    "raw": " ",
                    "loc": {
                        "start": {
                            "line": 1,
                            "column": 5
                        },
                        "end": {
                            "line": 1,
                            "column": 6
                        }
                    },
                    "range": [
                        5,
                        6
                    ],
                    "type": "Str"
                },
                {
                    "c": [
                        {
                            "c": "world",
                            "raw": "world",
                            "loc": {
                                "start": {
                                    "line": 1,
                                    "column": 0
                                },
                                "end": {
                                    "line": 1,
                                    "column": 5
                                }
                            },
                            "range": [
                                0,
                                5
                            ],
                            "type": "Str"
                        }
                    ],
                    "raw": "*world*",
                    "loc": {
                        "start": {
                            "line": 1,
                            "column": 6
                        },
                        "end": {
                            "line": 1,
                            "column": 13
                        }
                    },
                    "range": [
                        6,
                        13
                    ],
                    "type": "Emphasis"
                }
            ],
            "children": [],
            "raw": "Hello *world*",
            "loc": {
                "start": {
                    "line": 1,
                    "column": 0
                },
                "end": {
                    "line": 1,
                    "column": 13
                }
            },
            "range": [
                0,
                13
            ],
            "type": "Paragraph"
        }
    ],
    "raw": "Hello *world*",
    "loc": {
        "start": {
            "line": 1,
            "column": 0
        },
        "end": {
            "line": 1,
            "column": 13
        }
    },
    "range": [
        0,
        13
    ],
    "type": "Document"
}
```

Traversal all from Root(Document node):

```
[enter, Syntax.Document],
// # Header
[enter, Syntax.Header],
[enter, Syntax.Str],
[leave, Syntax.Str],
[leave, Syntax.Header],
// => Paragraph
[enter, Syntax.Paragraph],
[enter, Syntax.Str],
[leave, Syntax.Str],
// *world*
[enter, Syntax.Emphasis],
[enter, Syntax.Str],
[leave, Syntax.Str],
[leave, Syntax.Emphasis],
// <= Paragraph
[leave, Syntax.Paragraph],
// End
[leave, Syntax.Document]
```

## NOTE

You want to set property on Node.

Bad example:

```js
var TraverseController = require("@textlint/ast-traverse").Controller;
var controller = new TraverseController();
controller.traverse(ast, {
    enter: function (node, parent) {
        node.parent = parent;// it cause a circular reference!
        // do something
        something(node);
    }
});
```

`node.parent = parent;` cause a circular reference!

Correct example:

```js
var TraverseController = require("@textlint/ast-traverse").Controller;
var controller = new TraverseController();
controller.traverse(ast, {
    enter: function (node, parent) {
        // set property as non-enumerable value
        Object.defineProperty(node, "parent", {
            value: parent
        });
        // do something
        something(node);
    }
});
```


## Contributing

1. Fork it!
2. Create your feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request :D

## License

MIT

and 

Includes [Estraverse](https://github.com/estools/estraverse "Estraverse")
    
    Copyright (C) 2012-2013 Yusuke Suzuki
    https://github.com/estools/estraverse/blob/master/LICENSE.BSD

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