styled-components / babel-plugin-styled-components

Improve the debugging experience and add server-side rendering support to styled-components
MIT License
1.07k stars 140 forks source link

When there are multiple assignments perfer the outer name. #355

Closed rockwotj closed 2 years ago

rockwotj commented 3 years ago

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:

const Test = styled.View``;

into the following:

const Test = _c0 = styled.View``;

In this case this plugin assigns the view the name of _c0 and it's preferred to use Test. So I've patched the getName 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.