gkz / grasp

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

Bad equery replacement case #62

Open ksheedlo opened 9 years ago

ksheedlo commented 9 years ago

I have a minimal case that's causing a bad replacement. I have a series of test suites using Jasmine and I'd like to make sure that we are always using .toBe for strings and never .toEqual. The replacement is not giving me good results.

Here's my minimal case.

expect(foo('wow')).toEqual('bar');

Here's what I expect the replacement to produce:

expect(foo('wow')).toBe('bar');

Here's the actual output:

┌─[ken][Kens-MacBook-Pro][±][use-to-be-with-strings ✗][2.1.2][~/racker/sage]
└─▪ grasp -r -e '$e.toEqual(_str$s)' -R '{{e}}.toBe({{_str$s}})' replace-bug.js
expect(foo('wow')).toBe('wow');

As you can see, Grasp grabs the string nested down in the $e expression and assigns it to _str$s during the replacement. This is giving me incorrect results.