-
Notifications
You must be signed in to change notification settings - Fork 478
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't figure out how to make insertBefore work #157
Comments
Same issue with insertAfter by the way. |
OK, I figured out what the issue is. The problem is actually that you operating on the wrong nodes. You should not be looking for The reason why
An expression statements always only has a single expression as a child: {
"type": "ExpressionStatement",
"expression": {
"type": "CallExpression",
...
}
}
Another way to look at it is: Since you are trying to replace the expression to $(...).each(...) + 42; (I know that doesn't make sense, but hopefully gets the point across) With that in mind, here is an updated version your transform: http://astexplorer.net/#/5ZHnqffF3M This is not necessarily something that is easy to catch (it certainly to me a while). Here is what we could do:
Originally I liked (1), but I'm afraid that it's a bit too magical and kind of misleads people into thinking that such mutations are "correct". (2) would be more valuable from an educational perspective. Of course we could also do both 😉 |
Totally makes sense :) Thank you so much. Would not have figured it out without you. I kept my selector since the one you proposed wasn't catching things I wanted to transform such as
Maybe one last question: how to remove the newlines between the stuff I added? It shows
instead of
Also is there a better place to ask those questions than a github issue? |
Class transform - Remove React import only if it should be removed
Long story short: |
I'm trying to replace some things with a for..of loop but I can't find how to make insertBefore work.
Here is an exemple of what I'm trying to do: http://astexplorer.net/#/ejSwWFTL8V/2
If I uncomment line 71 I get the error:
Or it there is a better way to acheive what I need:
The text was updated successfully, but these errors were encountered: