Closed ibash closed 10 years ago
What you want is:
grasp -e '$a.last()' -R 'last({{a}})' t.js
Explanation:
last()
is different from tree.open_elements.last()
, to see the difference, think of the later as (tree.open_elements.last)()
- as you see, the first is a call expression with no arguments on last
, and the second is a call expression with no arguments on tree.open_elements.last
, and this is different.
To just match tree.open_elements.last()
you can use __.last()
, but you want to capture the value, so you can use a named wildcard $a
, so you can access it in the replacement pattern with {{a}}
.
Thank you for pointing me in the right direction and clarifying the difference. What made it clearer was doing acorn.parse('__last()')
vs acorn.parse('__.last()')
and exporting the AST makes total sense now!
Also, thanks for creating grasp, great tool.
I think this would be a good example to make a blog post out of, so other people who how to do this. Would it be OK if I wrote a post about this example?
Sure, I was actually thinking about doing the same for our blog (DataHero) :)
On Sat, Jan 25, 2014 at 2:36 PM, George Zahariev notifications@github.comwrote:
I think this would be a good example to make a blog post out of, so other people who how to do this. Would it be OK if I wrote a post about this example?
— Reply to this email directly or view it on GitHubhttps://github.com/gkz/grasp/issues/18#issuecomment-33302810 .
Islam Sharabash 217.377.9657
Hi, I read http://graspjs.com/blog/2014/01/07/refactoring-javascript-with-grasp/ -- so maybe I need to read more documentation but...
My end goal is to turn
last()
calls like this:Into something like this:
I can detect the
last
identifier like so:grasp -e 'last' lib/html5/parser.js
However -- when I try to detect it with parens I get no results:
grasp -e 'last()' lib/html5/parser.js
I also tried adding wildcards -- but just get an error:
Am I misunderstanding how to use grasp? What am I doing wrong? Or is it something to be debugged?