ast-node-finder
Version:
JSCodeshift find api automatically generated from code
44 lines (32 loc) • 1.53 kB
Markdown
# ast-node-finder

[](https://coveralls.io/github/rajasegar/ast-node-finder?branch=refs/heads/master)
[](https://npmjs.org/package/ast-node-finder)
[](https://github.com/semantic-release/semantic-release)
[](https://conventionalcommits.org)
[jscodeshift](https://github.com/facebook/jscodeshift) find api automatically generated from code
Checkout the api in this [playground](https://rajasegar.github.io/ast-finder/)
Read the [introductory blog post](http://hangaroundtheweb.com/2019/12/ast-finder-finding-ast-nodes-from-code/) for more details.
## Usage
```js
import { findQuery } from 'ast-node-finder';
import { parse } from 'recast';
const source = `foo.bar.baz(1,2,3)`;
const ast = parse(source);
// Pass the node from ast and get the find api
console.log(findQuery(ast.program.body[0].expression));
```
### Output
```js
root.find(j.CallExpression, {
callee: {
object: { object: { name: 'foo' },
property: { name: 'bar' }
},
property: { name: 'baz' }
}
})
.forEach(path => {
// Manipulate the path (node) here
});
```