-
Notifications
You must be signed in to change notification settings - Fork 764
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
Correctly support proto3 optional fields in commonjs+dts .d.ts output #1184
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -825,11 +825,11 @@ void PrintProtoDtsMessage(Printer* printer, const Descriptor* desc, | |
"set$js_field_name$(value?: $js_field_type$): " | ||
"$class_name$;\n"); | ||
} | ||
if (field->type() == FieldDescriptor::TYPE_MESSAGE && | ||
if ((field->type() == FieldDescriptor::TYPE_MESSAGE || field->has_optional_keyword()) && | ||
!field->is_repeated() && !field->is_map()) { | ||
printer->Print(vars, "has$js_field_name$(): boolean;\n"); | ||
} | ||
if (field->type() == FieldDescriptor::TYPE_MESSAGE || | ||
if (field->type() == FieldDescriptor::TYPE_MESSAGE || field->has_optional_keyword() || | ||
field->is_repeated() || field->is_map()) { | ||
printer->Print(vars, "clear$js_field_name$(): $class_name$;\n"); | ||
} | ||
|
@@ -852,10 +852,12 @@ void PrintProtoDtsMessage(Printer* printer, const Descriptor* desc, | |
|
||
for (int i = 0; i < desc->oneof_decl_count(); i++) { | ||
const OneofDescriptor* oneof = desc->oneof_decl(i); | ||
vars["js_oneof_name"] = ToUpperCamel(ParseLowerUnderscore(oneof->name())); | ||
printer->Print( | ||
vars, "get$js_oneof_name$Case(): $class_name$.$js_oneof_name$Case;\n"); | ||
printer->Print("\n"); | ||
if (!oneof->is_synthetic()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Btw nice job finding the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, you forget what it's like to find docs via Google instead of using your IDE 😂 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes right.. 😄 |
||
vars["js_oneof_name"] = ToUpperCamel(ParseLowerUnderscore(oneof->name())); | ||
printer->Print( | ||
vars, "get$js_oneof_name$Case(): $class_name$.$js_oneof_name$Case;\n"); | ||
printer->Print("\n"); | ||
} | ||
} | ||
|
||
printer->Print( | ||
|
@@ -885,7 +887,7 @@ void PrintProtoDtsMessage(Printer* printer, const Descriptor* desc, | |
} | ||
vars["js_field_name"] = js_field_name; | ||
vars["js_field_type"] = AsObjectFieldType(field, file); | ||
if (field->type() != FieldDescriptor::TYPE_MESSAGE || | ||
if ((field->type() != FieldDescriptor::TYPE_MESSAGE && !field->has_optional_keyword()) || | ||
field->is_repeated()) { | ||
printer->Print(vars, "$js_field_name$: $js_field_type$,\n"); | ||
} else { | ||
|
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.
nit: i'd probably prefer to maybe rewrite the logic as follows:
Probably doesn't make a huge difference, but it seems to make a little bit more sense to me.. :P
WDYT? :)
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.
I'm not sure.
The semantics of the two conditions is only the same when you factor in the proto3 language spec disallowing
optional
on map or repeated fields.I read it as when the field is a message or optional, but not when repeated or a map as opposed to when the field is optional (which implies it's not repeated or a map), or it's a message but not repeated or a map.
I'll leave the final decision up to you though :)
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.
Yeah i think that was my exactly concern.. -- that
optional
is mutually exclusive withrepeated
andmap
so i don't think they should be in aAND
relationship.. :)Yeah right.. although i felt that's a little long-winded.. (and i had some challenge understanding that too) 😅
Where i was thinking as: when the field is optional, or a message that is not repeated or a map.
I feel the latter is simpler and easier to reason. :)
If you are ok both ways, do you mind making the change? Thanks! :)
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.
The change has been made
Not sure what the process is around resolving conversations, so I'll leave this thread here
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 a lot for the change! I guess it doesn't hurt to just leave them open here :D