Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

ssilve1989
Copy link
Contributor

References #139

Copy link
Contributor

@philikon philikon left a 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) {
Copy link
Contributor

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
Copy link
Contributor

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 });
Copy link
Contributor

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) ||
Copy link
Contributor

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?

Base automatically changed from master to main March 14, 2021 15:29
@elderapo
Copy link

elderapo commented Feb 2, 2022

Any chance we can get this merged? :)

@stephenh
Copy link
Owner

stephenh commented Feb 3, 2022

@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 main, add the test, that would be great!

@deser
Copy link

deser commented Mar 17, 2022

@ssilve1989 any change to merge? :)

@deser
Copy link

deser commented Mar 30, 2022

@philikon any change to merge? :)

@garrappachc
Copy link

Please merge this 🙏

@stephenh stephenh force-pushed the main branch 4 times, most recently from cdf2835 to 7017d4c Compare May 28, 2022 17:39
zfy0701 added a commit to sentioxyz/ts-proto that referenced this pull request Jan 5, 2023
@stephenh
Copy link
Owner

A lot of work for proto2 optional fields was just done in #1007 that hopefully addresses this, so going to close this out.

@stephenh stephenh closed this Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants