https://github.com/azz/ast-grep
🔍 Like grep, but more powerful than you can possibly imagine
https://github.com/azz/ast-grep
ast grep javascript search
Last synced: 9 months ago
JSON representation
🔍 Like grep, but more powerful than you can possibly imagine
- Host: GitHub
- URL: https://github.com/azz/ast-grep
- Owner: azz
- License: mit
- Created: 2018-01-13T10:13:45.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-01-15T01:02:50.000Z (over 8 years ago)
- Last Synced: 2025-08-09T01:43:06.642Z (11 months ago)
- Topics: ast, grep, javascript, search
- Language: JavaScript
- Homepage:
- Size: 110 KB
- Stars: 16
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `ast-grep`
[](https://travis-ci.org/azz/ast-grep)
[](https://github.com/prettier/prettier)
[](https://npmjs.org/ast-grep)
[](https://github.com/semantic-release/semantic-release)
[](LICENSE)
> Like grep, but more powerful than you can possibly imagine.
Search your JavaScript files for patterns based on AST shape, rather than substrings or regular expressions.
## Install
With `yarn`:
```shellsession
yarn global add ast-grep
```
With `npm`:
```shellsession
npm install --global ast-grep
```
## Usage
```shellsession
$ ast-grep --help
Options:
--anonymous, -a Ignore all names in the AST [boolean]
--file, -f Load pattern from a file [string]
--help Show help [boolean]
--version Show version number [boolean]
Examples:
ast-grep -a 'fn()' file.js Find all no-arg function calls in
'file.js'.
ast-grep -f pattern.js '**/*.js' Match the pattern in 'pattern.js' across
all JS files.
echo 'foo' | ast-grep 'pattern' Match 'pattern' on standard input.
```
On standard in:
```shellsession
$ echo 'code();' | ast-grep 'code'
code();
$ ast-grep 'foo()' < file.js
foo();
```
On a set of files:
```shellsession
$ ast-grep 'yield* foo();' '**/*.js'
```
## FAQ
### Q. But @azz, `grep` stands for Global Regular Expression Print, this tool doesn't use Regular Expressions!
**A.** I know, but `gastp` doesn't sound great.