mirror of https://github.com/grpc/grpc-web.git
Correctly support proto3 optional fields in commonjs+dts .d.ts output (#1184)
* Correctly support proto3 optional fields in commonjs+dts .d.ts output Fixes #1072 * Use has_optional_keyword instead of is_optional * Improve the readability of the condition guarding hasXxx .d.ts field generation.
This commit is contained in:
parent
3fcc2a2a8a
commit
eb313c1f3d
|
|
@ -825,11 +825,12 @@ void PrintProtoDtsMessage(Printer* printer, const Descriptor* desc,
|
|||
"set$js_field_name$(value?: $js_field_type$): "
|
||||
"$class_name$;\n");
|
||||
}
|
||||
if (field->type() == FieldDescriptor::TYPE_MESSAGE &&
|
||||
!field->is_repeated() && !field->is_map()) {
|
||||
if (field->has_optional_keyword() ||
|
||||
(field->type() == FieldDescriptor::TYPE_MESSAGE &&
|
||||
!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 +853,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()) {
|
||||
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 +888,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 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue