@@ -1240,7 +1240,9 @@ std::string RelativeTypeName(const FieldDescriptor* field) {
1240
1240
std::string JSExtensionsObjectName (const GeneratorOptions& options,
1241
1241
const FileDescriptor* from_file,
1242
1242
const Descriptor* desc) {
1243
- if (desc->full_name () == " google.protobuf.bridge.MessageSet" ) {
1243
+ if (options.WantEs6 ()) {
1244
+ return TypeNames::JsName (desc->name ()) + " .extensions" ;
1245
+ } else if (desc->full_name () == " google.protobuf.bridge.MessageSet" ) {
1244
1246
// TODO(haberman): fix this for the kImportCommonJs case.
1245
1247
return " jspb.Message.messageSetExtensions" ;
1246
1248
} else {
@@ -2071,7 +2073,7 @@ void Generator::GenerateClassEs6(const GeneratorOptions& options,
2071
2073
2072
2074
printer->Indent ();
2073
2075
2074
- GenerateClassConstructor (options, printer, desc);
2076
+ GenerateClassConstructorAndDeclareExtensionFieldInfo (options, printer, desc);
2075
2077
2076
2078
GenerateClassFieldInfo (options, printer, desc);
2077
2079
@@ -2181,12 +2183,6 @@ void Generator::GenerateClassConstructorAndDeclareExtensionFieldInfo(
2181
2183
GenerateClassExtensionFieldInfo (options, printer, desc);
2182
2184
}
2183
2185
}
2184
- for (int i = 0 ; i < desc->nested_type_count (); i++) {
2185
- if (!IgnoreMessage (desc->nested_type (i))) {
2186
- GenerateClassConstructorAndDeclareExtensionFieldInfo (
2187
- options, printer, desc->nested_type (i));
2188
- }
2189
- }
2190
2186
}
2191
2187
2192
2188
void Generator::GenerateClassFieldInfo (const GeneratorOptions& options,
@@ -3238,9 +3234,8 @@ void Generator::GenerateClassExtensionFieldInfo(const GeneratorOptions& options,
3238
3234
" *\n "
3239
3235
" * @type {!Object<number, jspb.ExtensionFieldInfo>}\n "
3240
3236
" */\n "
3241
- " $class$.extensions = {};\n "
3242
- " \n " ,
3243
- " class" , GetMessagePath (options, desc));
3237
+ " static extensions = {};\n "
3238
+ " \n " );
3244
3239
3245
3240
printer->Print (
3246
3241
" \n "
@@ -3259,9 +3254,8 @@ void Generator::GenerateClassExtensionFieldInfo(const GeneratorOptions& options,
3259
3254
" *\n "
3260
3255
" * @type {!Object<number, jspb.ExtensionFieldBinaryInfo>}\n "
3261
3256
" */\n "
3262
- " $class$.extensionsBinary = {};\n "
3263
- " \n " ,
3264
- " class" , GetMessagePath (options, desc));
3257
+ " static extensionsBinary = {};\n "
3258
+ " \n " );
3265
3259
}
3266
3260
}
3267
3261
@@ -3666,22 +3660,23 @@ void Generator::GenerateExtension(const GeneratorOptions& options,
3666
3660
const TypeNames& type_names,
3667
3661
io::Printer* printer,
3668
3662
const FieldDescriptor* field) const {
3669
- std::string extension_scope =
3670
- (field->extension_scope ()
3671
- ? GetMessagePath (options, field->extension_scope ())
3672
- : GetNamespace (options, field->file ()));
3663
+ std::string extension_scope_name =
3664
+ (field->containing_type ()
3665
+ ? TypeNames::JsName (field->containing_type ()->name ())
3666
+ : GetNamespace (options, field->file ()));
3667
+ std::string extension_object_name =
3668
+ JSExtensionsObjectName (options, field->file (), field->containing_type ());
3669
+ std::string extension_object_field_name = JSObjectFieldName (options, field);
3673
3670
3674
- const std::string extension_object_name = JSObjectFieldName (options, field);
3675
3671
printer->Print (
3676
3672
" \n "
3677
3673
" /**\n "
3678
3674
" * A tuple of {field number, class constructor} for the extension\n "
3679
- " * field named `$nameInComment $`.\n "
3675
+ " * field named `$name $`.\n "
3680
3676
" * @type {!jspb.ExtensionFieldInfo<$extensionType$>}\n "
3681
3677
" */\n "
3682
3678
" $class$.$name$ = new jspb.ExtensionFieldInfo(\n " ,
3683
- " nameInComment" , extension_object_name, " name" , extension_object_name,
3684
- " class" , extension_scope, " extensionType" ,
3679
+ " class" , extension_scope_name, " name" , extension_object_field_name, " extensionType" ,
3685
3680
JSFieldTypeAnnotation (options, field,
3686
3681
/* is_setter_argument = */ false ,
3687
3682
/* force_present = */ true ,
@@ -3695,7 +3690,7 @@ void Generator::GenerateExtension(const GeneratorOptions& options,
3695
3690
" !Object} */ (\n "
3696
3691
" $toObject$),\n "
3697
3692
" $repeated$);\n " ,
3698
- " index" , StrCat (field->number ()), " name" , extension_object_name , " ctor" ,
3693
+ " index" , StrCat (field->number ()), " name" , extension_object_field_name , " ctor" ,
3699
3694
(field->cpp_type () == FieldDescriptor::CPPTYPE_MESSAGE
3700
3695
? type_names.SubmessageTypeRef (field)
3701
3696
: std::string (" null" )),
@@ -3713,12 +3708,11 @@ void Generator::GenerateExtension(const GeneratorOptions& options,
3713
3708
" $binaryWriterFn$,\n "
3714
3709
" $binaryMessageSerializeFn$,\n "
3715
3710
" $binaryMessageDeserializeFn$,\n " ,
3716
- " extendName" ,
3717
- JSExtensionsObjectName (options, field->file (), field->containing_type ()),
3718
- " index" , StrCat (field->number ()), " class" , extension_scope, " name" ,
3719
- extension_object_name, " binaryReaderFn" ,
3720
- JSBinaryReaderMethodName (options, field), " binaryWriterFn" ,
3721
- JSBinaryWriterMethodName (options, field), " binaryMessageSerializeFn" ,
3711
+ " extendName" , extension_object_name, " index" , StrCat (field->number ()),
3712
+ " class" , extension_scope_name, " name" , extension_object_field_name,
3713
+ " binaryReaderFn" , JSBinaryReaderMethodName (options, field),
3714
+ " binaryWriterFn" , JSBinaryWriterMethodName (options, field),
3715
+ " binaryMessageSerializeFn" ,
3722
3716
(field->cpp_type () == FieldDescriptor::CPPTYPE_MESSAGE)
3723
3717
? (type_names.SubmessageTypeRef (field) + " .serializeBinaryToWriter" )
3724
3718
: " undefined" ,
@@ -3735,10 +3729,8 @@ void Generator::GenerateExtension(const GeneratorOptions& options,
3735
3729
" // toObject() will function correctly.\n "
3736
3730
" $extendName$[$index$] = $class$.$name$;\n "
3737
3731
" \n " ,
3738
- " extendName" ,
3739
- JSExtensionsObjectName (options, field->file (), field->containing_type ()),
3740
- " index" , StrCat (field->number ()), " class" , extension_scope, " name" ,
3741
- extension_object_name);
3732
+ " extendName" , extension_object_name, " index" , StrCat (field->number ()),
3733
+ " class" , extension_scope_name, " name" , extension_object_field_name);
3742
3734
}
3743
3735
3744
3736
bool GeneratorOptions::ParseFromOptions (
0 commit comments