-
-
Notifications
You must be signed in to change notification settings - Fork 141
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
Rewrite to the new, private API #5
Conversation
With the new private API, all the IIFEs are unnecessary since we can just pass an object to the styled() calls. This commit updates the plugin and the tests to reflect the new, much better behaviour. This way we can take full advantage of styled-components/styled-components#227 when it's merged!
aa61012
to
fe17962
Compare
} | ||
// styled call without variable | ||
if (!target) { | ||
target = getTarget(path.node.tag) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getting target from path.node.tag works for all tests. In which cases you need to determine it differently?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, once it's path.node.right.tag
, once path.node.init.tag
and every other time path.node.tag
. Or are you saying we can just always use path.node.tag
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, in my understanding it's always path.node.tag of TaggedTemplateExpression
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, thanks! Updated!
) | ||
path._styledComponentsSeen = true | ||
|
||
path.replaceWith(styledCall) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we got rid of wrapping, code above can be reduced to
// Put together the styled call with the template literal
// to get the finished styled({ })`` form! 🎉
path.node.tag = call.expression
No need to mark with _styledComponentsSeen
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing, thanks!
I've been thinking of similar change, but I thought of less intrusive conversion of |
I don't think that's a concern, since we can just publish a new major version with a peerDep to the new styled-components version that supports it. I don't remember why we decided to not do it that way though, but now it doesn't really matter and I don't want to rewrite it 😉 |
With the new private API, all the IIFEs are unnecessary since we can just pass an object to the styled() calls. This commit updates the plugin and the tests to reflect the new result. Need to wait for styled-components/styled-components#227 (which introduces the new API) to be merged before releasing.
Please review the code @vdanchenkov, I'm not very familiar with writing babel plugins, so if you see things that could be done easier please let me know!
@geelen please review the result of the conversion in the
after.js
files of the fixtures!