@@ -30,13 +30,7 @@ StyleSheets.prototype.markAsUsed = function (fullyQualifiedName) {
30
30
const styleSheetName = nameSplit [ 0 ] ;
31
31
const styleSheetProperty = nameSplit [ 1 ] ;
32
32
33
- if ( nameSplit . length === 1 ) {
34
- Object . keys ( this . styleSheets ) . forEach ( ( key ) => {
35
- this . styleSheets [ key ] = this . styleSheets [ key ] . filter (
36
- ( property ) => property . key . name !== styleSheetName
37
- ) ;
38
- } ) ;
39
- } else if ( this . styleSheets [ styleSheetName ] ) {
33
+ if ( this . styleSheets [ styleSheetName ] ) {
40
34
this . styleSheets [ styleSheetName ] = this . styleSheets [ styleSheetName ] . filter (
41
35
( property ) => property . key . name !== styleSheetProperty
42
36
) ;
@@ -122,6 +116,14 @@ const astHelpers = {
122
116
) ;
123
117
} ,
124
118
119
+ getDestructuringAssignmentParts : function ( node ) {
120
+ if ( node && node . id && node . id . type === 'ObjectPattern' && node . id . properties && node . init ) {
121
+ return [ node . init . name , node . id . properties ] ;
122
+ }
123
+
124
+ return [ null , null ] ;
125
+ } ,
126
+
125
127
getStyleSheetName : function ( node ) {
126
128
if ( node && node . parent && node . parent . id ) {
127
129
return node . parent . id . name ;
@@ -470,24 +472,16 @@ const astHelpers = {
470
472
}
471
473
} ,
472
474
473
- getPotentialStyleReferenceFromArrayExpression : function ( node ) {
474
- if ( node && node . type === 'Identifier' && node . name ) {
475
- return node . name ;
476
- }
477
- } ,
475
+ getPotentialDestructuredStyleReferences : function ( node ) {
476
+ const [ styleSheetName , properties ] = this . getDestructuringAssignmentParts ( node ) ;
478
477
479
- getPotentialStyleReferenceFromJSXExpressionContainer : function ( node ) {
480
- if (
481
- node
482
- && node . expression
483
- && node . expression . type === 'Identifier'
484
- && node . expression . name
485
- && node . parent
486
- && node . parent . name
487
- && [ 'style' , 'textStyle' ] . includes ( node . parent . name . name )
488
- ) {
489
- return node . expression . name ;
490
- }
478
+ return styleSheetName && properties
479
+ ? properties . flatMap ( ( property ) =>
480
+ property . key && property . key . type === 'Identifier' && property . key . name
481
+ ? `${ styleSheetName } .${ property . key . name } `
482
+ : [ ]
483
+ )
484
+ : [ ] ;
491
485
} ,
492
486
493
487
isEitherShortHand : function ( property1 , property2 ) {
0 commit comments