-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Force displayName plugin to run before all other transforms #3209
Conversation
Better diff: https://github.com/babel/babel/pull/3209/files?w=0 |
What if two transforms did this? |
Current coverage is
|
@gaearon What is actually happening here is we're forcing this plugin to run in isolation. Babel's transform pipeline optimizes the traversal process by merging visitors together. Basically making every visitor run at the same time. This is why order is (mostly) insignificant in Babel 6. This sometimes causes issues with one transform "beating" another by hitting a node first and mutating nodes that another plugin wants to touch. What I've done here is hit the top-most node and forced an isolated traversal of the entire tree. So to answer your question of "what if two transforms did this", it would just mean that the order is significant just like Babel 5. Since this transform is not really destructive in any kind of way it doesn't matter that much that it's running before other things. |
Thanks for explaining. 👍 |
Yes |
Another option is for |
Wouldn't this result in duplicated work? Or can Babel detect that this happened? |
I thought this plugin bails when it sees a displayName? But anyways it's a On Thursday, December 24, 2015, Dan Abramov notifications@github.com
|
Yep, I agree. |
I mean technically it's going to revisit the nodes again, but thats pretty insignificant in comparison. I never thought to pull in the actual visitor in another plugin. |
This is bad, we shouldn't be encouraging plugins to be written like this. The gaearon/babel-plugin-react-transform issue doesn't actually explain why this is happening:
What is causing this plugin to not be ran and why is this the only possible fix? |
Okay we can fix this by just crawling up the ancestry looking for appropriate parent nodes, breaking on statements so we don't go too high up. Alternate PR incoming. |
Fixes gaearon/babel-plugin-react-transform#67
cc @gaearon