You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to factor addEventLister code to a library function, essentially turning this:
foo.bar.addEventListener('mousemove',callback);
into this :
factorizedFunction(foo.bar,'mousemove',callback);
Let's consider an nested example:
foo.bar.addEventListener("mousedown",function(evt){//do some stuffevt.preventDefault();evt.stopPropagation();document.body.addEventListener("mouseup",functionleMe(evt){//do some other stuffdocument.body.removeEventListener("mouseup",leMe);});});
I'm using Equery which works great for this, running this on the above code: $ grasp -e '$target.addEventListener($eventName, $callback, _$capture)' test.js
outputs this :
1-13:(multiline):
foo.bar.addEventListener("mousedown", function(evt)
{
//do some stuff
evt.preventDefault();
evt.stopPropagation();
document.body.addEventListener("mouseup", function leMe(evt)
{
//do some other stuff
document.body.removeEventListener("mouseup", leMe);
});
});
8-12:(multiline):
document.body.addEventListener("mouseup", function leMe(evt)
{
//do some other stuff
document.body.removeEventListener("mouseup", leMe);
});
So far so good, just notice that nested match is printed after surrounding one.
Now, when running my replace : $ grasp -e '$target.addEventListener($eventName, $callback, _$capture)' -iR 'factorizedFunction({{target}}, {{eventName}}, {{callback}}{{capture | before ", "}})' test.js
results in the following code :
factorizedFunction(foo.bar,"mousedown",function(evt){//do some stuffevt.preventDefault();evt.stopPropagation();document.body.addEventListener("mouseup",functionleMe(evt){//do some other stuffdocument.body.removeEventListener("mouseup",leMe);});});
As you can see the nested match is not replaced, I guess because it is treated after.
As a workaround I run the command as long as I find matches in my code base.
PS : Great Job guys, grasp is a fantastic tool ! 👍
The text was updated successfully, but these errors were encountered:
thereforeiam
changed the title
Probleme replacing nested match
Problem replacing nested match
Apr 16, 2015
I'm trying to factor addEventLister code to a library function, essentially turning this:
into this :
Let's consider an nested example:
I'm using Equery which works great for this, running this on the above code:
$ grasp -e '$target.addEventListener($eventName, $callback, _$capture)' test.js
outputs this :
So far so good, just notice that nested match is printed after surrounding one.
Now, when running my replace :
$ grasp -e '$target.addEventListener($eventName, $callback, _$capture)' -iR 'factorizedFunction({{target}}, {{eventName}}, {{callback}}{{capture | before ", "}})' test.js
results in the following code :
As you can see the nested match is not replaced, I guess because it is treated after.
As a workaround I run the command as long as I find matches in my code base.
PS : Great Job guys, grasp is a fantastic tool ! 👍
The text was updated successfully, but these errors were encountered: