gkz / grasp

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

batch #21

Open tianyagongcishi opened 10 years ago

tianyagongcishi commented 10 years ago

if i want to replace many variables in a js file,i can write many command like below: grasp '#a' -R aaa -i a.js grasp '#b' -R bbb -i a.js grasp '#c' -R ccc -i a.js grasp '#d' -R ddd -i a.js ... ...

a.js is very big(>=1MB),so it's very slow,is there a faster way?

gkz commented 10 years ago

There is not a way to do that at the moment. One issue is that one replacement pattern could affect the follow on patterns, so the must be done in order.

Mirael89 commented 10 years ago

This feature is totally needed. It will be very useful for obfuscating code. Currently it can take tokens from file and also it can replace them with contents of another file (-F) so remaining change is to take replacements accordingly line-to-line from it. For exapmle:

grasp -f tokens.txt -replace_per_line repl.txt -i input.js

tokens.txt:

a

b

c

repl.txt: aaa bbb ccc

will be same as: grasp #a -R aaa -i input.js grasp #b -R bbb -i input.js grasp #c -R ccc -i input.js

let it even be slow but this is needed for convenience.