

Grasp: Structural Search and Replace for JavaScript - jashkenas
http://graspjs.com

======
feistyio
Fun facts:

Grasp is by the author of LiveScript[1].

This was submitted by the author of CoffeeScript[2]

[1] [https://github.com/gkz/LiveScript](https://github.com/gkz/LiveScript)

[2]
[https://github.com/jashkenas/CoffeeScript](https://github.com/jashkenas/CoffeeScript)

~~~
GeZe
I plan to add support for both LiveScript and CoffeeScript to grasp in the
future.

PS. If anyone has any questions about grasp please let me know!

------
gunn
The CLI in the demo is amazing. I had to investigate how I could run 'rm -r'
instantly.

The answer is: [https://github.com/gkz/grasp/blob/gh-
pages/assets/js/command...](https://github.com/gkz/grasp/blob/gh-
pages/assets/js/command.js#L201)

~~~
jashkenas
And what's even neater is how the JavaScript you linked to looks fairly normal
(and efficient) at first glance...

But the real source lies here: [https://github.com/gkz/grasp/blob/gh-
pages/assets/_ls/comman...](https://github.com/gkz/grasp/blob/gh-
pages/assets/_ls/command.ls#L136-L146)

------
CGamesPlay
I released something similar to this, jsgrep, but the query syntax is actual
JS with special variables marking the placeholders. I think the patch syntax
makes more intuitive sense in jsgrep; although it is more limited:

    
    
      $ cat c.js
      f(x < y, x == z);
      $ grasp bi --replace '{{.r}}+{{.l}}' c.js
      f(y+x, z+x);
    

In jsgrep, the same substitution could be made by:

    
    
      -f(A < B, B == C)
      +f(A + B, B + C)
    

jsgrep:
[https://github.com/facebook/jsgrep](https://github.com/facebook/jsgrep)

~~~
monjaro
jsgrep looks very neat as well. I like the patch syntax. However, I don't
think this example is quite equivalent. In the grasp example, it replaces
every binary operator, not just that specific call. Could you show how to
represent the same thing in jsgrep?

~~~
CGamesPlay
Not possible in jsgrep without enumerating all of the binary options (I can't
think of a good reason for needing to do that though). It's more suited for
doing API changes:

    
    
      -foo(A, B, true)
      +fooWithOption(A, B)

------
CWIZO
This is really amazing. I'll try t out on our codebase first thing on Monday.

I've asked on GH, but I guess I can repeat the question here: any plans to
create a SublimeText plugin for this?

Great job!

~~~
GeZe
Looks like someone has started one: [https://github.com/joneshf/sublime-
grasp](https://github.com/joneshf/sublime-grasp)

------
roryokane
Another structural-editing tool is ydiff
([http://yinwang0.wordpress.com/2012/01/03/ydiff/](http://yinwang0.wordpress.com/2012/01/03/ydiff/)),
which can display structural diffs between JavaScript files. Demo:
[http://www.yinwang.org/resources/nav1-nav2.html](http://www.yinwang.org/resources/nav1-nav2.html)

------
gfodor
this is one of those things that makes you wonder why it isn't already a
standard tool. my only guess is perhaps the net benefit to something like this
isn't high compared to grep. either way, great work.

