Skip to content

Commit e5011de

Browse files
committed
Fix generated code for repeated field 'addFoo' helper methods.
1 parent 2a80405 commit e5011de

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

generator/js_generator.cc

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3134,14 +3134,16 @@ void Generator::GenerateRepeatedPrimitiveHelperMethods(
31343134
const FieldDescriptor* field, bool untyped) const {
31353135

31363136
const std::string classSymbol = GetMessagePath(options, field->containing_type());
3137-
const std::string adderName = JSGetterName(options, field, BYTES_DEFAULT,
3138-
/* drop_list = */ true);
3137+
const std::string adderName = std::string("add") +
3138+
JSGetterName(options, field, BYTES_DEFAULT, /* drop_list = */ true);
31393139
const std::string adderMethodStart = MethodStart(
31403140
options, classSymbol.c_str(), adderName.c_str());
31413141

31423142
// clang-format off
31433143
printer->Print(
31443144
"/**\n"
3145+
" * Adds a value to the repeated field $field_name$ \n"
3146+
" *\n"
31453147
" * @param {$optionaltype$} value\n"
31463148
" * @param {number=} opt_index\n"
31473149
" * @return {!$class$} returns this\n"
@@ -3150,9 +3152,8 @@ void Generator::GenerateRepeatedPrimitiveHelperMethods(
31503152
" return jspb.Message.addToRepeatedField(this, "
31513153
"$index$",
31523154
"methodstart", adderMethodStart,
3153-
"class", classSymbol, "addername",
3154-
"add" + JSGetterName(options, field, BYTES_DEFAULT,
3155-
/* drop_list = */ true),
3155+
"class", classSymbol,
3156+
"addername", adderName,
31563157
"optionaltype",
31573158
JSFieldTypeAnnotation(
31583159
options, field,
@@ -3183,23 +3184,26 @@ void Generator::GenerateRepeatedMessageHelperMethods(
31833184
const FieldDescriptor* field) const {
31843185

31853186
const std::string classSymbol = GetMessagePath(options, field->containing_type());
3186-
const std::string adderName = JSGetterName(options, field, BYTES_DEFAULT, /* drop_list = */ true);
3187+
const std::string adderName = std::string("add") +
3188+
JSGetterName(options, field, BYTES_DEFAULT, /* drop_list = */ true);
31873189
const std::string adderMethodStart = MethodStart(
31883190
options, classSymbol.c_str(), adderName.c_str());
31893191

31903192
printer->Print(
31913193
"/**\n"
3194+
" * Adds a value to the repeated field $field_name$ \n"
3195+
" *\n"
31923196
" * @param {!$optionaltype$=} opt_value\n"
31933197
" * @param {number=} opt_index\n"
31943198
" * @return {!$optionaltype$}\n"
31953199
" */\n"
31963200
"$methodstart$(opt_value, opt_index) {\n"
31973201
" return jspb.Message.addTo$repeatedtag$WrapperField(",
3198-
"optionaltype", JSTypeName(options, field, BYTES_DEFAULT), "class", classSymbol,
3202+
"optionaltype", JSTypeName(options, field, BYTES_DEFAULT),
3203+
"field_name", field->name(),
3204+
"class", classSymbol,
31993205
"methodstart", adderMethodStart,
3200-
"addername",
3201-
"add" + JSGetterName(options, field, BYTES_DEFAULT,
3202-
/* drop_list = */ true),
3206+
"addername", adderName,
32033207
"repeatedtag", (field->is_repeated() ? "Repeated" : ""));
32043208

32053209
printer->Annotate("addername", field);
@@ -3209,8 +3213,8 @@ void Generator::GenerateRepeatedMessageHelperMethods(
32093213
"\n"
32103214
"\n",
32113215
"index", JSFieldIndex(field), "oneofgroup",
3212-
(InRealOneof(field) ? (", " + JSOneofArray(options, field)) : ""), "class",
3213-
type_names.SubmessageTypeRef(field));
3216+
(InRealOneof(field) ? (", " + JSOneofArray(options, field)) : ""),
3217+
"class", type_names.SubmessageTypeRef(field));
32143218
}
32153219

32163220
void Generator::GenerateClassExtensionFieldInfo(const GeneratorOptions& options,

0 commit comments

Comments
 (0)