File tree Expand file tree Collapse file tree 3 files changed +12
-3
lines changed
test/fixtures/add-display-names Expand file tree Collapse file tree 3 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ export default t => path => {
1010 let namedNode
1111
1212 path . find ( path => {
13- // const X = styled
13+ // X = styled
1414 if ( path . isAssignmentExpression ( ) ) {
1515 namedNode = path . node . left
1616 // const X = { Y: styled }
@@ -19,7 +19,7 @@ export default t => path => {
1919 // class Y { (static) X = styled }
2020 } else if ( path . isClassProperty ( ) ) {
2121 namedNode = path . node . key
22- // let X; X = styled
22+ // const X = styled
2323 } else if ( path . isVariableDeclarator ( ) ) {
2424 namedNode = path . node . id
2525 } else if ( path . isStatement ( ) ) {
@@ -28,7 +28,12 @@ export default t => path => {
2828 }
2929
3030 // we've got an displayName (if we need it) no need to continue
31- if ( namedNode ) return true
31+ // However if this is an assignment expression like X = styled then we
32+ // want to keep going up incase there is Y = X = styled; in this case we
33+ // want to pick the outer name because react-refresh will add HMR variables
34+ // like this: X = _a = styled. We could also consider only doing this if the
35+ // name starts with an underscore.
36+ if ( namedNode && ! path . isAssignmentExpression ( ) ) return true
3237 } )
3338
3439 // foo.bar -> bar
Original file line number Diff line number Diff line change @@ -12,3 +12,4 @@ const WrappedComponent = styled(Inner)``
1212class ClassComponent {
1313 static Child = styled . div ``
1414}
15+ var GoodName = BadName = styled . div `` ;
Original file line number Diff line number Diff line change @@ -28,3 +28,6 @@ class ClassComponent {}
2828ClassComponent . Child = styled . div . withConfig ( {
2929 displayName : "Child"
3030} ) `` ;
31+ var GoodName = BadName = styled . div . withConfig ( {
32+ displayName : "GoodName"
33+ } ) `` ;
You can’t perform that action at this time.
0 commit comments