gkz / grasp

JavaScript structural search, replace, and refactor
http://graspjs.com
MIT License
1.28k stars 33 forks source link

find call with specific number of arguments #33

Open ainthek opened 10 years ago

ainthek commented 10 years ago

// this is what I have grasp -s "call[callee.prop=(#forEach,#map,#filter,#reduce)]" -r

now I want to limit the result to calls that have only one argument)

is it possible with -s syntax ?

gkz commented 10 years ago

See discussion in #19

Currently we can't do exact arguments in squery, but we can in equery - but we can't do OR in equery, but we can in squery.

You can do with the equery syntax

grasp -e '__.forEach(__)'
grasp -e '__.map(__)'
grasp -e '__.filter(__)'
grasp -e '__.reduce(__)'

If you want to save the portions you are matching, you can do:

grasp -e '$a.reduce($b)'

PS. -s is on by default, you don't need to use it explicitly unless you have set -e to be the default.