From 59ea5710eb55e8e2e4903ebb209421a6d8d51145 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Sat, 5 Oct 2024 14:18:26 -0500 Subject: [PATCH] Use empty string for key-value pair --- src/main.ts | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/main.ts b/src/main.ts index 9c9dad9cb..46c8878e5 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1234,6 +1234,7 @@ function generateBaseInstanceFactory( ): Code { const { options, currentFile } = ctx; const fields: Code[] = []; + const keyValuePair = isKeyValuePair(messageDesc.field); // When oneof=unions, we generate a single property with an ADT per `oneof` clause. const processedOneofs = new Set(); @@ -1260,15 +1261,23 @@ function generateBaseInstanceFactory( } const fieldKey = safeAccessor(getFieldName(field, options)); - const val = isWithinOneOf(field) - ? nullOrUndefined(options) - : isMapType(ctx, messageDesc, field) - ? shouldGenerateJSMapType(ctx, messageDesc, field) - ? "new Map()" - : "{}" - : isRepeated(field) - ? "[]" - : defaultValue(ctx, field); + let val; + + if (keyValuePair) { + val = '""'; + } else if (isWithinOneOf(field)) { + val = nullOrUndefined(options); + } else if (isMapType(ctx, messageDesc, field)) { + if (shouldGenerateJSMapType(ctx, messageDesc, field)) { + val = "new Map()"; + } else { + val = "{}"; + } + } else if (isRepeated(field)) { + val = "[]"; + } else { + val = defaultValue(ctx, field); + } fields.push(code`${fieldKey}: ${val}`); }