gkz / grasp

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

replace width call's arguments #30

Open tianyagongcishi opened 10 years ago

tianyagongcishi commented 10 years ago

i have a method call like below: sayHello("from", { title: "abc", message: "aha" });

how to change the second argument's property name "message" to "info"(only when the method's name is "sayHello" and the first argument is "from")? by the way, i use grasp in nodejs and squery thank you very much!

gkz commented 10 years ago

Using equery:

grasp -e 'sayHello("from", { _:$ps, message: $msg})' -R 'sayHello("from", {\n  {{ps | join ",\n  " }},\n  info: {{msg}}\n})'

results in

sayHello("from", {
  title: "abc",
  info: "aha"
});

not the cleanest way as you can see though perhaps we should:

tianyagongcishi commented 10 years ago

oh,it's so complex,i have use RegExp instead. tks anyway

gkz commented 10 years ago

Yes, it's definitely a use case that needs to be simplified