Like grep, but more powerful than you can possibly imagine.
npm install ast-grepast-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.
With yarn:
``shellsession`
yarn global add ast-grep
With npm:
`shellsession`
npm install --global ast-grep
`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.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:
`shellsession`
$ echo 'code();' | ast-grep 'code'
code();
$ ast-grep 'foo()' < file.js
foo();
On a set of files:
`shellsession`
$ ast-grep 'yield foo();' '/.js'
A. I know, but gastp` doesn't sound great.