@@ -219,6 +219,18 @@ var UnistyleDependency = {
219219 Ime : 14 ,
220220 Rtl : 15
221221} ;
222+ function getStyleKeyName ( key ) {
223+ if ( ! key ) {
224+ return null ;
225+ }
226+ if ( t4 . isIdentifier ( key ) ) {
227+ return key . name ;
228+ }
229+ if ( t4 . isStringLiteral ( key ) || t4 . isNumericLiteral ( key ) || t4 . isBooleanLiteral ( key ) ) {
230+ return String ( key . value ) ;
231+ }
232+ return null ;
233+ }
222234function getProperty ( property ) {
223235 if ( ! property ) {
224236 return void 0 ;
@@ -389,28 +401,30 @@ function getStylesDependenciesFromObject(path2) {
389401 const stylesheet = path2 . node . arguments [ 0 ] ;
390402 if ( t4 . isObjectExpression ( stylesheet ) ) {
391403 stylesheet ?. properties . forEach ( ( property ) => {
392- if ( ! t4 . isObjectProperty ( property ) || ! t4 . isIdentifier ( property . key ) ) {
404+ if ( ! t4 . isObjectProperty ( property ) ) {
393405 return ;
394406 }
395- if ( t4 . isObjectProperty ( property ) ) {
396- if ( t4 . isObjectExpression ( property . value ) ) {
397- property . value . properties . forEach ( ( innerProp ) => {
398- if ( t4 . isObjectProperty ( innerProp ) && t4 . isIdentifier ( innerProp . key ) && t4 . isIdentifier ( property . key ) && innerProp . key . name === "variants" ) {
399- detectedStylesWithVariants . add ( {
400- label : "variants" ,
401- key : property . key . name
402- } ) ;
403- }
404- } ) ;
405- }
407+ const styleKey = getStyleKeyName ( property . key ) ;
408+ if ( ! styleKey ) {
409+ return ;
410+ }
411+ if ( t4 . isObjectExpression ( property . value ) ) {
412+ property . value . properties . forEach ( ( innerProp ) => {
413+ if ( t4 . isObjectProperty ( innerProp ) && t4 . isIdentifier ( innerProp . key ) && innerProp . key . name === "variants" ) {
414+ detectedStylesWithVariants . add ( {
415+ label : "variants" ,
416+ key : styleKey
417+ } ) ;
418+ }
419+ } ) ;
406420 }
407421 if ( t4 . isArrowFunctionExpression ( property . value ) ) {
408422 if ( t4 . isObjectExpression ( property . value . body ) ) {
409423 property . value . body . properties . forEach ( ( innerProp ) => {
410- if ( t4 . isObjectProperty ( innerProp ) && t4 . isIdentifier ( innerProp . key ) && t4 . isIdentifier ( property . key ) && innerProp . key . name === "variants" ) {
424+ if ( t4 . isObjectProperty ( innerProp ) && t4 . isIdentifier ( innerProp . key ) && innerProp . key . name === "variants" ) {
411425 detectedStylesWithVariants . add ( {
412426 label : "variants" ,
413- key : property . key . name
427+ key : styleKey
414428 } ) ;
415429 }
416430 } ) ;
@@ -493,10 +507,10 @@ function getStylesDependenciesFromFunction(funcPath) {
493507 if ( Array . isArray ( stylePath ) ) {
494508 return ;
495509 }
496- if ( ! stylePath . isIdentifier ( ) ) {
510+ const styleKey = getStyleKeyName ( stylePath . node ) ;
511+ if ( ! styleKey ) {
497512 return ;
498513 }
499- const styleKey = stylePath . node . name ;
500514 const valuePath = propPath . get ( "value" ) ;
501515 if ( Array . isArray ( valuePath ) ) {
502516 return ;
@@ -901,13 +915,12 @@ function index_default() {
901915 if ( detectedDependencies ) {
902916 if ( t6 . isObjectExpression ( arg ) ) {
903917 arg . properties . forEach ( ( property ) => {
904- if ( t6 . isObjectProperty ( property ) && t6 . isIdentifier ( property . key ) && Object . prototype . hasOwnProperty . call ( detectedDependencies , property . key . name ) ) {
905- addDependencies (
906- state ,
907- property . key . name ,
908- property ,
909- detectedDependencies [ property . key . name ] ?? [ ]
910- ) ;
918+ if ( ! t6 . isObjectProperty ( property ) ) {
919+ return ;
920+ }
921+ const styleKey = getStyleKeyName ( property . key ) ;
922+ if ( styleKey && Object . prototype . hasOwnProperty . call ( detectedDependencies , styleKey ) ) {
923+ addDependencies ( state , styleKey , property , detectedDependencies [ styleKey ] ?? [ ] ) ;
911924 }
912925 } ) ;
913926 }
@@ -920,13 +933,12 @@ function index_default() {
920933 const body = t6 . isBlockStatement ( arg . body ) ? arg . body . body . find ( ( statement ) => t6 . isReturnStatement ( statement ) ) ?. argument : arg . body ;
921934 if ( t6 . isObjectExpression ( body ) ) {
922935 body . properties . forEach ( ( property ) => {
923- if ( t6 . isObjectProperty ( property ) && t6 . isIdentifier ( property . key ) && Object . prototype . hasOwnProperty . call ( detectedDependencies , property . key . name ) ) {
924- addDependencies (
925- state ,
926- property . key . name ,
927- property ,
928- detectedDependencies [ property . key . name ] ?? [ ]
929- ) ;
936+ if ( ! t6 . isObjectProperty ( property ) ) {
937+ return ;
938+ }
939+ const styleKey = getStyleKeyName ( property . key ) ;
940+ if ( styleKey && Object . prototype . hasOwnProperty . call ( detectedDependencies , styleKey ) ) {
941+ addDependencies ( state , styleKey , property , detectedDependencies [ styleKey ] ?? [ ] ) ;
930942 }
931943 } ) ;
932944 }
0 commit comments