Skip to content

Commit 4d773f1

Browse files
fix error when rename number variable
1 parent 11c20d1 commit 4d773f1

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

apps/studio/electron/main/assets/styles.ts

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,32 +221,48 @@ function updateTailwindConfigFile(
221221
colorObj.properties.forEach((colorProp) => {
222222
if (
223223
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)
226229
) {
227230
// If the keyName is not provided, we are renaming the root color
228231
if (!keyName) {
229232
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+
}
231241
keyUpdated = true;
232242

233243
// Then we need to update the child css variables or direct color values
234244
if (colorProp.value.type === 'ObjectExpression') {
235245
colorProp.value.properties.forEach((nestedProp) => {
236246
if (
237247
nestedProp.type === 'ObjectProperty' &&
238-
nestedProp.key.type === 'Identifier' &&
248+
(nestedProp.key.type === 'Identifier' ||
249+
nestedProp.key.type === 'NumericLiteral') &&
239250
nestedProp.value.type === 'StringLiteral'
240251
) {
241252
// Special handling for DEFAULT
253+
const keyValue =
254+
nestedProp.key.type === 'Identifier'
255+
? nestedProp.key.name
256+
: String(nestedProp.key.value);
257+
242258
const oldVarName =
243-
nestedProp.key.name === DEFAULT_COLOR_NAME
259+
keyValue === DEFAULT_COLOR_NAME
244260
? parentKey
245-
: `${parentKey}-${nestedProp.key.name}`;
261+
: `${parentKey}-${keyValue}`;
246262
const newVarName =
247-
nestedProp.key.name === DEFAULT_COLOR_NAME
263+
keyValue === DEFAULT_COLOR_NAME
248264
? newName
249-
: `${newName}-${nestedProp.key.name}`;
265+
: `${newName}-${keyValue}`;
250266

251267
nestedProp.value.value = nestedProp.value.value.replace(
252268
new RegExp(`--${oldVarName}`, 'g'),
@@ -317,6 +333,8 @@ async function updateTailwindColorVariable(
317333
theme?: Theme,
318334
): Promise<UpdateResult> {
319335
const [parentKey, keyName] = originalName.split('-');
336+
console.log('parentKey', parentKey);
337+
console.log('keyName', keyName);
320338

321339
if (!parentKey) {
322340
return { success: false, error: `Invalid color key format: ${originalName}` };

0 commit comments

Comments
 (0)