fix(csv-loader): use commas in generated type declarations

Update `type-gen.ts` to replace semicolons with commas in the
generated TypeScript type definitions to ensure valid syntax.
This commit is contained in:
hypercross 2026-04-22 19:23:49 +08:00
parent eef3dbfac8
commit 89be2783d1
2 changed files with 7 additions and 8 deletions

View File

@ -247,7 +247,7 @@ describe("parseCsv - type declarations", () => {
expect(result.typeDefinition).toContain("export type IntentEffects =");
// IntentEffect should reference IntentEffectTarget, not expand it
expect(result.typeDefinition).toContain(
"[IntentEffectTarget; string; int]",
"[IntentEffectTarget, string, int]",
);
// IntentEffects should reference IntentEffect, not expand it
expect(result.typeDefinition).toContain("IntentEffect[]");
@ -281,9 +281,9 @@ describe("parseCsv - type declarations", () => {
});
expect(typeResult.typeDefinition).toContain("export type Type =");
expect(typeResult.typeDefinition).toContain("[Type; int][]");
expect(typeResult.typeDefinition).toContain("[Type, int][]");
expect(typeResult.typeDefinition).toContain(
"readonly items: [Type; int][];",
"readonly items: [Type, int][];",
);
});

View File

@ -6,15 +6,14 @@ function resolveReferencesInSchemaString(
schemaString: string,
resourceNames: Map<string, string>,
): string {
return schemaString.replace(
/@([a-zA-Z0-9\-_]+)(\[\])?/g,
(_match, tableName, arraySuffix) => {
return schemaString
.replace(/@([a-zA-Z0-9\-_]+)(\[\])?/g, (_match, tableName, arraySuffix) => {
const typeName =
resourceNames.get(tableName) ||
tableName.charAt(0).toUpperCase() + tableName.slice(1);
return arraySuffix ? `${typeName}[]` : typeName;
},
);
})
.replace(/; ?/g, ", ");
}
/**