-
-
Notifications
You must be signed in to change notification settings - Fork 142
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
When there are multiple assignments perfer the outer name. #355
Conversation
@@ -10,7 +10,7 @@ export default t => path => { | |||
let namedNode | |||
|
|||
path.find(path => { | |||
// const X = styled | |||
// X = styled |
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.
This was backwards see: https://astexplorer.net/#/gist/3e299bf92f4651d5230a94ef129e5509/latest
// want to pick the outer name because react-refresh will add HMR variables | ||
// like this: X = _a = styled. We could also consider only doing this if the | ||
// name starts with an underscore. | ||
if (namedNode && !path.isAssignmentExpression()) return true |
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.
I'm also open to hiding this behavior behind a config option as well.
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.
Thank you! This is a great change.
We're running styled-components within metro for react native - and metro runs it's babel plugins before ours. One of the plugins that runs is the HMR module (react-refresh), which changes our styled components from:
into the following:
In this case this plugin assigns the view the name of _c0 and it's preferred to use
Test
. So I've patched thegetName
function to keep traversing if it's the the inner assignment and prefer the outer name. It still falls back to the inner name however.