Skip to content

Commit

Permalink
createBaseX return recursive base message
Browse files Browse the repository at this point in the history
  • Loading branch information
tresabhi committed Oct 5, 2024
1 parent 938aaf8 commit dbfe8c0
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,10 @@ export function getFieldOptionsJsType(
export function defaultValue(ctx: Context, field: FieldDescriptorProto): any {
const { typeMap, options, utils, currentFile } = ctx;

if (options.noDefaultsForOptionals) {
if (
options.noDefaultsForOptionals ||
(!ctx.currentFile.isProto3Syntax && field.label === FieldDescriptorProto_Label.LABEL_OPTIONAL))
{
return options.useNullAsOptional ? null : undefined;
}

Expand Down Expand Up @@ -287,6 +290,9 @@ export function defaultValue(ctx: Context, field: FieldDescriptorProto): any {
}
return "new Uint8Array(0)";
case FieldDescriptorProto_Type.TYPE_MESSAGE:
if (!ctx.currentFile.isProto3Syntax) {
return code`createBase${messageToTypeName(ctx, field.typeName)}()`;
}
case FieldDescriptorProto_Type.TYPE_GROUP:
default:
return nullOrUndefined(options);
Expand Down

0 comments on commit dbfe8c0

Please sign in to comment.