Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/lint-md/ast-plugin

The simplest abstract syntax tree walker, similar with @Babel plugin.
https://github.com/lint-md/ast-plugin

ast babel babel-plugin plugin

Last synced: about 1 month ago
JSON representation

The simplest abstract syntax tree walker, similar with @Babel plugin.

Awesome Lists containing this project

README

        

# @lint-md/ast-plugin

> The simplest abstract syntax tree walker.

[![Build Status](https://github.com/lint-md/ast-plugin/actions/workflows/build.yml/badge.svg)](https://github.com/lint-md/ast-plugin/actions/workflows/build.yml)

## Install

> npm i --save ast-plugin

## Usage

- Traverse Ast plugins

```js
import { Ast, Plugin } from 'ast-plugin';

new Ast(ast).traverse([
new TestPlugin(cfg),
// ...
]);
```

- Write an ast plugin

```js
import { Ast, Plugin } from 'ast-plugin';

class TestPlugin extends Plugin {

pre = () => {
};

visitor = () => {
return {
// process node with type = 'text'
text: ast => {
console.log(ast.node);
ast.segment();
},
};
};

post = () => {
};
}
```

## Used by

- [lint-md](https://github.com/lint-md/lint-md) Cli tool to lint your markdown file for Chinese.

## License

MIT@[hustcc](https://github.com/hustcc).