Skip to content

Commit

Permalink
Use proto3's default values in proto2 when disableProto2Optionals=true
Browse files Browse the repository at this point in the history
  • Loading branch information
tresabhi committed Nov 9, 2024
1 parent c9fc51a commit a475c9b
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 57 deletions.
112 changes: 56 additions & 56 deletions integration/proto2-no-optionals/simple.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,12 @@ export function defaultValue(ctx: Context, field: FieldDescriptorProto): any {

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

0 comments on commit a475c9b

Please sign in to comment.