Skip to content

Commit fb9a4b3

Browse files
committed
figma-inspector: added stricter types
1 parent 81ffd8a commit fb9a4b3

File tree

1 file changed

+22
-32
lines changed

1 file changed

+22
-32
lines changed

tools/figma-inspector/backend/utils/export-variables.ts

+22-32
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ interface PropertyInstance {
543543
function generateStructsAndInstances(
544544
variableTree: VariableNode,
545545
collectionName: string,
546-
collectionData: any, // Using any for now, but ideally define a proper interface
546+
collectionData: CollectionData, // using strict type interface
547547
): {
548548
structs: string;
549549
instances: string;
@@ -1069,6 +1069,20 @@ function generateStructsAndInstances(
10691069
instances: instancesCode,
10701070
};
10711071
}
1072+
interface VariableModeData {
1073+
value: string;
1074+
type: string; // 'COLOR', 'FLOAT', 'STRING', 'BOOLEAN'
1075+
refId?: string;
1076+
comment?: string;
1077+
}
1078+
1079+
interface CollectionData {
1080+
name: string; // Original collection name
1081+
formattedName: string; // Sanitized name for Slint globals/structs
1082+
modes: Set<string>; // Sanitized mode names
1083+
variables: Map<string, Map<string, VariableModeData>>; // Map<rowName, Map<modeName, data>>
1084+
// Add other properties if collectionData holds more info
1085+
}
10721086

10731087
// For Figma Plugin - Export function with hierarchical structure
10741088
// Export each collection to a separate virtual file
@@ -1093,26 +1107,7 @@ export async function exportFigmaVariablesToSeparateFiles(
10931107
const exportedFiles: Array<{ name: string; content: string }> = [];
10941108

10951109
// First, initialize the collection structure for ALL collections
1096-
const collectionStructure = new Map<
1097-
string,
1098-
{
1099-
name: string;
1100-
formattedName: string;
1101-
modes: Set<string>;
1102-
variables: Map<
1103-
string,
1104-
Map<
1105-
string,
1106-
{
1107-
value: string;
1108-
type: string;
1109-
refId?: string;
1110-
comment?: string;
1111-
}
1112-
>
1113-
>;
1114-
}
1115-
>();
1110+
const collectionStructure = new Map<string, CollectionData>();
11161111

11171112
// Build a global map of variable paths
11181113
const variablePathsById = new Map<
@@ -1193,17 +1188,12 @@ export async function exportFigmaVariablesToSeparateFiles(
11931188
.get(collectionName)!
11941189
.variables.has(sanitizedRowName)
11951190
) {
1196-
collectionStructure.get(collectionName)!.variables.set(
1197-
sanitizedRowName,
1198-
new Map<
1199-
string,
1200-
{
1201-
value: string;
1202-
type: string;
1203-
refId?: string;
1204-
}
1205-
>(),
1206-
);
1191+
collectionStructure
1192+
.get(collectionName)!
1193+
.variables.set(
1194+
sanitizedRowName,
1195+
new Map<string, VariableModeData>(),
1196+
);
12071197
}
12081198

12091199
// Process values for each mode

0 commit comments

Comments
 (0)