gkz / grasp

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

How do I match two calls to the same function in the same block? #124

Open danielrozenberg opened 6 years ago

danielrozenberg commented 6 years ago

I'm trying to match any body block that has two calls to the same (explicitly named) function, e.g. it should match this block:

it('should match this sub-block', () => {
  // do Javascript things
  thisFunctionShouldOnlyBeCalledOnce(123);
  // do JavaScript things
  thisFunctionShouldOnlyBeCalledOnce(456);
  // do JavaScript things
});

And it should not match this block:

it('should match this sub-block', () => {
  // do Javascript things
  thisFunctionShouldOnlyBeCalledOnce(123);
  // do JavaScript things
});

I tried a bunch of things, the "closest" I got were:

But to no avail. Is this something that can be done with grasp?