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

View File

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