gkz / grasp

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

ability to use named submatches as arguments to filters #35

Open mikesherov opened 10 years ago

mikesherov commented 10 years ago

I wan to transform the following:

a.fn(b, c);
a.fn(b);
a.fn();

to

fn2(a, b, c);
fn2(a, b);
fn2(a);

In order to do so, I attempted the following grasp command:

grasp "call! > member[prop.name=fn]
" -R "fn2({{.args | prepend .callee.obj | join ', '}})"

however, this results in:

fn2(.callee.obj, b, c);
fn2(.callee.obj, b);
fn2(.callee.obj);

i.e. it used .callee.obj as a string literal when I intended a named submatch. Can there be a way to provide named submatches as arguments to filters?