-
Notifications
You must be signed in to change notification settings - Fork 349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: support proto2 optional #162
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for picking this up! left a few comments/suggestions/questions.
@@ -847,6 +851,11 @@ function generateEncode( | |||
) | |||
.addStatement('%L', writeSnippet(`message.${fieldName}`)) | |||
.endControlFlow(); | |||
} else if (field.label === FieldDescriptorProto.Label.LABEL_OPTIONAL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where is proto3Optional handled in this if/elseif/.../else
block? Should that not also be handled here?
return ( | ||
(options.useOptionals && isMessage(field) && !isRepeated(field)) || | ||
field.proto3Optional || | ||
field.label === FieldDescriptorProto.Label.LABEL_OPTIONAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
really seems like we could use an isOptionalField
helper...
@@ -377,7 +377,7 @@ export function toTypeName( | |||
field: FieldDescriptorProto, | |||
options: Options | |||
): TypeName { | |||
let type = basicTypeName(typeMap, field, options, { keepValueType: false }); | |||
let type = basicTypeName(typeMap, field, options, { keepValueType: true }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this change?
(!isWithinOneOf(field) && | ||
isMessage(field) && | ||
!options.useOptionals && | ||
field.label !== FieldDescriptorProto.Label.LABEL_REQUIRED) || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice. can we get a test?
Any chance we can get this merged? :) |
@elderapo unfortunately the PR is pretty out of date, and had several unanswered questions from the original review, plus an ask for a test, so as-is, chances of being merged are low. If you'd like to pick it up, rebase on |
@ssilve1989 any change to merge? :) |
@philikon any change to merge? :) |
Please merge this 🙏 |
cdf2835
to
7017d4c
Compare
A lot of work for proto2 optional fields was just done in #1007 that hopefully addresses this, so going to close this out. |
References #139