@@ -1146,12 +1146,12 @@ bool HasRepeatedFields(const GeneratorOptions& options,
1146
1146
return false ;
1147
1147
}
1148
1148
1149
- static const char * kRepeatedFieldArrayName = " . repeatedFields_" ;
1149
+ static const char * kRepeatedFieldArrayName = " repeatedFields_" ;
1150
1150
1151
1151
std::string RepeatedFieldsArrayName (const GeneratorOptions& options,
1152
1152
const Descriptor* desc) {
1153
1153
return HasRepeatedFields (options, desc)
1154
- ? (GetMessagePath (options, desc) + kRepeatedFieldArrayName )
11
8000
54
+ ? (GetMessagePath (options, desc) + " . " + kRepeatedFieldArrayName )
1155
1155
: " null" ;
1156
1156
}
1157
1157
@@ -2027,6 +2027,10 @@ void Generator::GenerateClassEs6(const GeneratorOptions& options,
2027
2027
return ;
2028
2028
}
2029
2029
2030
+
2031
+ std::string prefix = (desc->containing_type () == nullptr ) ?
2032
+ " export " : (" static " + desc->name () + " = " );
2033
+
2030
2034
printer->Print (" \n " );
2031
2035
printer->Print (
2032
2036
" /**\n "
@@ -2044,12 +2048,8 @@ void Generator::GenerateClassEs6(const GeneratorOptions& options,
2044
2048
" * @extends {jspb.Message}\n "
2045
2049
" * @constructor\n "
2046
2050
" */\n "
2047
-
2048
- " // DO NOT SUBMIT: \n "
2049
- " // classprefix = $classprefix$\n "
2050
- " // classname = $classname$ \n "
2051
-
2052
- " export class $classname$ extends jspb.Message {\n " ,
2051
+ " $prefix$class $classname$ extends jspb.Message {\n " ,
2052
+ " prefix" , prefix,
2053
2053
" classname" , desc->name ());
2054
2054
2055
2055
printer->Indent ();
@@ -2159,22 +2159,22 @@ void Generator::GenerateClassConstructorAndDeclareExtensionFieldInfo(
2159
2159
void Generator::GenerateClassFieldInfo (const GeneratorOptions& options,
2160
2160
io::Printer* printer,
2161
2161
const Descriptor* desc) const {
2162
+ const std::string className = GetMessagePath (options, desc);
2162
2163
if (HasRepeatedFields (options, desc)) {
2163
2164
printer->Print (
2164
2165
" /**\n "
2165
2166
" * List of repeated fields within this message type.\n "
2166
2167
" * @private {!Array<number>}\n "
2167
2168
" * @const\n "
2168
2169
" */\n "
2169
- " $classname$$rptfieldarray $ = $rptfields$;\n "
2170
+ " $lhs $ = $rptfields$;\n "
2170
2171
" \n " ,
2171
- " classname " , GetMessagePath (options, desc), " rptfieldarray " ,
2172
- kRepeatedFieldArrayName , " rptfields " ,
2173
- RepeatedFieldNumberList (options, desc));
2172
+ " lhs " , StaticMemberAssignmentLhs (
2173
+ options, className. c_str (), kRepeatedFieldArrayName ) ,
2174
+ " rptfields " , RepeatedFieldNumberList (options, desc));
2174
2175
}
2175
2176
2176
2177
if (HasOneofFields (desc)) {
2177
- const std::string className = GetMessagePath (options, desc);
2178
2178
const std::string assignment = (
2179
2179
options.import_style == GeneratorOptions::kImportEs6
2180
2180
) ? (
@@ -3070,17 +3070,24 @@ const char * methodEndBrace = WantEs6(options) ? "}" : "};";
3070
3070
void Generator::GenerateRepeatedPrimitiveHelperMethods (
3071
3071
const GeneratorOptions& options, io::Printer* printer,
3072
3072
const FieldDescriptor* field, bool untyped) const {
3073
+
3073
3074
const std::string classSymbol = GetMessagePath (options, field->containing_type ());
3075
+ const std::string adderName = JSGetterName (options, field, BYTES_DEFAULT,
3076
+ /* drop_list = */ true );
3077
+ const std::string adderMethodStart = MethodStart (
3078
+ options, classSymbol.c_str (), adderName.c_str ());
3079
+
3074
3080
// clang-format off
3075
3081
printer->Print (
3076
3082
" /**\n "
3077
3083
" * @param {$optionaltype$} value\n "
3078
3084
" * @param {number=} opt_index\n "
3079
3085
" * @return {!$class$} returns this\n "
3080
3086
" */\n "
3081
- " $class$.prototype.$addername$ = function (value, opt_index) {\n "
3087
+ " $methodstart$ (value, opt_index) {\n "
3082
3088
" return jspb.Message.addToRepeatedField(this, "
3083
3089
" $index$" ,
3090
+ " methodstart" , adderMethodStart,
3084
3091
" class" , classSymbol, " addername" ,
3085
3092
" add" + JSGetterName (options, field, BYTES_DEFAULT,
3086
3093
/* drop_list = */ true ),
@@ -3110,16 +3117,23 @@ void Generator::GenerateRepeatedPrimitiveHelperMethods(
3110
3117
void Generator::GenerateRepeatedMessageHelperMethods (
3111
3118
const GeneratorOptions& options, io::Printer* printer,
3112
3119
const FieldDescriptor* field) const {
3120
+
3121
+ const std::string classSymbol = GetMessagePath (options, field->containing_type ());
3122
+ const std::string adderName = JSGetterName (options, field, BYTES_DEFAULT, /* drop_list = */ true );
3123
+ const std::string adderMethodStart = MethodStart (
3124
+ options, classSymbol.c_str (), adderName.c_str ());
3125
+
3113
3126
printer->Print (
3114
3127
" /**\n "
3115
3128
" * @param {!$optionaltype$=} opt_value\n "
3116
3129
" * @param {number=} opt_index\n "
3117
3130
" * @return {!$optionaltype$}\n "
3118
3131
" */\n "
3119
- " $class$.prototype.$addername$ = function (opt_value, opt_index) {\n "
3132
+ " $methodstart$ (opt_value, opt_index) {\n "
3120
3133
" return jspb.Message.addTo$repeatedtag$WrapperField(" ,
3121
- " optionaltype" , JSTypeName (options, field, BYTES_DEFAULT), " class" ,
3122
- GetMessagePath (options, field->containing_type ()), " addername" ,
3134
+ " optionaltype" , JSTypeName (options, field, BYTES_DEFAULT), " class" , classSymbol,
3135
+ " methodstart" , adderMethodStart,
3136
+ " addername" ,
3123
3137
" add" + JSGetterName (options, field, BYTES_DEFAULT,
3124
3138
/* drop_list = */ true ),
3125
3139
" repeatedtag" , (field->is_repeated () ? " Repeated" : " " ));
@@ -4184,6 +4198,17 @@ void Generator::GenerateMethodEnd(const GeneratorOptions& options,
4184
4198
}
4185
4199
}
4186
4200
4201
+ const std::string Generator::StaticMemberAssignmentLhs (
4202
+ const GeneratorOptions& options,
4203
+ const char * classSymbol,
4204
+ const char * fieldName) const {
4205
+ if (WantEs6 (options)) {
4206
+ return std::string (" static " ) + fieldName;
4207
+ } else {
4208
+ return std::string (" " ) + classSymbol + " ." + fieldName;
4209
+ }
4210
+ }
4211
+
4187
4212
} // namespace js
4188
4213
} // namespace compiler
4189
4214
} // namespace protobuf
0 commit comments