@@ -221,32 +221,48 @@ function updateTailwindConfigFile(
221
221
colorObj . properties . forEach ( ( colorProp ) => {
222
222
if (
223
223
colorProp . type === 'ObjectProperty' &&
224
- colorProp . key . type === 'Identifier' &&
225
- colorProp . key . name === parentKey
224
+ ( colorProp . key . type === 'Identifier' ||
225
+ colorProp . key . type === 'NumericLiteral' ) &&
226
+ ( colorProp . key . type === 'Identifier'
227
+ ? colorProp . key . name === parentKey
228
+ : String ( colorProp . key . value ) === parentKey )
226
229
) {
227
230
// If the keyName is not provided, we are renaming the root color
228
231
if ( ! keyName ) {
229
232
if ( parentKey && newName !== parentKey ) {
230
- colorProp . key . name = newName ;
233
+ if ( colorProp . key . type === 'Identifier' ) {
234
+ colorProp . key . name = newName ;
235
+ } else {
236
+ colorProp . key = {
237
+ type : 'Identifier' ,
238
+ name : newName ,
239
+ } ;
240
+ }
231
241
keyUpdated = true ;
232
242
233
243
// Then we need to update the child css variables or direct color values
234
244
if ( colorProp . value . type === 'ObjectExpression' ) {
235
245
colorProp . value . properties . forEach ( ( nestedProp ) => {
236
246
if (
237
247
nestedProp . type === 'ObjectProperty' &&
238
- nestedProp . key . type === 'Identifier' &&
248
+ ( nestedProp . key . type === 'Identifier' ||
249
+ nestedProp . key . type === 'NumericLiteral' ) &&
239
250
nestedProp . value . type === 'StringLiteral'
240
251
) {
241
252
// Special handling for DEFAULT
253
+ const keyValue =
254
+ nestedProp . key . type === 'Identifier'
255
+ ? nestedProp . key . name
256
+ : String ( nestedProp . key . value ) ;
257
+
242
258
const oldVarName =
243
- nestedProp . key . name === DEFAULT_COLOR_NAME
259
+ keyValue === DEFAULT_COLOR_NAME
244
260
? parentKey
245
- : `${ parentKey } -${ nestedProp . key . name } ` ;
261
+ : `${ parentKey } -${ keyValue } ` ;
246
262
const newVarName =
247
- nestedProp . key . name === DEFAULT_COLOR_NAME
263
+ keyValue === DEFAULT_COLOR_NAME
248
264
? newName
249
- : `${ newName } -${ nestedProp . key . name } ` ;
265
+ : `${ newName } -${ keyValue } ` ;
250
266
251
267
nestedProp . value . value = nestedProp . value . value . replace (
252
268
new RegExp ( `--${ oldVarName } ` , 'g' ) ,
@@ -317,6 +333,8 @@ async function updateTailwindColorVariable(
317
333
theme ?: Theme ,
318
334
) : Promise < UpdateResult > {
319
335
const [ parentKey , keyName ] = originalName . split ( '-' ) ;
336
+ console . log ( 'parentKey' , parentKey ) ;
337
+ console . log ( 'keyName' , keyName ) ;
320
338
321
339
if ( ! parentKey ) {
322
340
return { success : false , error : `Invalid color key format: ${ originalName } ` } ;
0 commit comments