From 89be2783d15a87a02988b4125bfa76c4728ad8c7 Mon Sep 17 00:00:00 2001 From: hypercross Date: Wed, 22 Apr 2026 19:23:49 +0800 Subject: [PATCH] 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. --- src/csv-loader/tests/parseCsv-typeDeclarations.test.ts | 6 +++--- src/csv-loader/type-gen.ts | 9 ++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/csv-loader/tests/parseCsv-typeDeclarations.test.ts b/src/csv-loader/tests/parseCsv-typeDeclarations.test.ts index 37daa19..50545da 100644 --- a/src/csv-loader/tests/parseCsv-typeDeclarations.test.ts +++ b/src/csv-loader/tests/parseCsv-typeDeclarations.test.ts @@ -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][];", ); }); diff --git a/src/csv-loader/type-gen.ts b/src/csv-loader/type-gen.ts index 94a1ffc..7b5a248 100644 --- a/src/csv-loader/type-gen.ts +++ b/src/csv-loader/type-gen.ts @@ -6,15 +6,14 @@ function resolveReferencesInSchemaString( schemaString: string, resourceNames: Map, ): 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, ", "); } /**