-
Notifications
You must be signed in to change notification settings - Fork 135
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
Program visitor not being run for styled-components macro #121
Comments
Hi @probablyup! I don't know what's up and I'm afraid I don't have the bandwidth to look into it right now :( |
One interesting thing is @jamesknelson was looking into this and switching from |
I'm good with that solution is someone wants to make a pull request. |
@probablyup , I am trying to make a macro for this babel plugin: https://github.com/insin/babel-plugin-react-html-attrs/blob/master/lib/index.js I think it's a problem similar to yours, what do you think? Here it has also been mentioned in: #31 |
* use babel traverse * remove log statement * remove semicolon Closes #121
🎉 This issue has been resolved in version 3.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
@probablyup Sorry to bother you. It looks like the fix implemented for this issue caused a regression for a different issue. I want to make sure we don't cause the issue described here again as we try to fix the regression, but unfortunately the code sandbox link your provided when you created this issue is now gone. Do you happen to have a copy of it, or can you help me understand what was happening? |
Actually I think I understand what you were talking about now. I see where you changed the plugin to traverse inside of the Program visitor. I'll dig into it some more tomorrow. |
OK yeah I am now pretty sure the fix for this issue is wrong and will I believe need to be reverted. I can help you look again at the problem described here and determine its root cause and the correct fix. |
I theorize that your problem is on this line. I'll have to dig to confirm but I suspect you shouldn't requeue something that hasn't been queued yet? The main traversal is still on the program node and you're requeueing one of its children. I still don't quite understand why it would interact with macros. I'll have to take a peek into the Babel code tomorrow to get those answers. |
It seems that |
Can you try dropping the call to requeue entirely. I do not think you need it as you are altering the body of the program which has yet to be traversed. You can test it with the 2.x version of plugin-macros right? |
Relevant babel plugin code: styled-components/babel-plugin-styled-components@e3829d2#diff-1fdf421c05c1140f6d71444ea2b27638L13
Relevant macro code: https://github.com/styled-components/styled-components/blob/master/packages/styled-components/src/macro/index.js
Basically when I switched the root level
JSXAttribute
visitor into one that's a subtraversal of Program (necessary to create the component AST the other visitors then further modify) the part of the babel plugin inside the Program visitor stopped working for macro users.Here's a repro sandbox: https://codesandbox.io/embed/magical-brook-ctyxs (styled-components@* and babel-plugin-styled-components@1.10.1, the text should be green.)
To be totally honest I generally am not great at writing Babel code so maybe I'm just doing something wrong? But it's odd because I have a bunch of tests in the repo to make sure the transforms happen properly and they do seem to function as expected, it's just this Program subtraversal that isn't working for the macro use case...
The text was updated successfully, but these errors were encountered: