ast-grep
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
:
yarn global add ast-grep
With npm
:
npm install --global ast-grep
Usage
$ ast-grep --helpOptions: --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.js -a 'fn()' file.js Find all no-arg function calls in 'file.js'. ast-grep.js -f pattern.js '**/*.js' Match the pattern in 'pattern.js' across all JS files. echo 'foo' | ast-grep.js 'pattern' Match 'pattern' on standard input.
On standard in:
$ echo 'code();' | ast-grep 'code'code();$ ast-grep 'foo()' < file.jsfoo();
On a set of files:
$ ast-grep 'yield* foo();' '**/*.js'
FAQ
grep
stands for Global Regular Expression Print, this tool doesn't use Regular Expressions!
Q. But @azz, A. I know, but gastp
doesn't sound great.