Skip to content

Support protobuf extend keyword when in kImportEs6 mode #8

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

Merged
merged 116 commits into from
Jul 6, 2023
Merged
Changes from all commits
Commits
Show all changes
116 commits
Select commit Hold shift + click to select a range
8e69d39
ensure can modify generator and use in rule_ts_proto repo
Jun 28, 2023
c0b7014
prototyping extend keyword changes
Jun 28, 2023
302fe4b
attempting to correctly build JS output
Jun 28, 2023
58e3e4d
attempting to correctly build JS output
Jun 28, 2023
180688f
attempting to correctly build JS output
Jun 28, 2023
2b68a05
attempting to correctly build JS output
Jun 28, 2023
85fb511
attempting to correctly build JS output
Jun 28, 2023
73e5689
attempting to correctly build JS output
Jun 28, 2023
d38e598
attempting to correctly build JS output
Jun 28, 2023
dbbec94
attempting to correctly build JS output
Jun 28, 2023
2a257ab
attempting to correctly build JS output
Jun 28, 2023
964e817
attempting to correctly build JS output
Jun 28, 2023
cfb19ed
attempting to correctly build JS output
Jun 28, 2023
64f0edb
attempting to correctly build JS output
Jun 28, 2023
6d7f747
attempting to correctly build JS output
Jun 28, 2023
36fe2b7
attempting to correctly build JS output
Jun 28, 2023
6235ab7
attempting to correctly build JS output
Jun 28, 2023
13e9051
attempting to correctly build JS output
Jun 28, 2023
d05baf1
attempting to correctly build JS output
Jun 29, 2023
c790739
attempting to correctly build JS output
Jun 29, 2023
1281223
attempting to correctly build JS output
Jun 29, 2023
cfcc060
attempting to correctly build JS output
Jun 29, 2023
98b3480
attempting to correctly build JS output
Jun 29, 2023
3af9fe1
attempting to correctly build JS output
Jun 29, 2023
71ad097
attempting to correctly build JS output
Jun 29, 2023
8fa99e8
attempting to correctly build JS output
Jun 29, 2023
3ce9b68
attempting to correctly build JS output
Jun 29, 2023
f0444be
attempting to correctly build JS output
Jun 29, 2023
6fcc428
attempting to correctly build JS output
Jun 29, 2023
e713a2d
attempting to correctly build JS output
Jun 29, 2023
b2bffc7
attempting to correctly build JS output
Jun 29, 2023
630410f
attempting to correctly build JS output
Jun 29, 2023
2815f82
attempting to correctly build JS output
Jun 29, 2023
94cddd9
attempting to correctly build JS output
Jun 29, 2023
6338e3a
attempting to correctly build JS output
Jun 29, 2023
8a5407f
attempting to correctly build JS output
Jun 29, 2023
8f7ab37
attempting to correctly build JS output
Jun 29, 2023
c175e83
attempting to correctly build JS output
Jun 29, 2023
5962b51
attempting to correctly build JS output
Jun 29, 2023
c1aec6f
attempting to correctly build JS output
Jun 29, 2023
54f9dac
attempting to correctly build JS output
Jun 29, 2023
5a6323e
attempting to correctly build JS output
Jun 29, 2023
958d33a
attempting to correctly build JS output
Jun 29, 2023
652b4f5
attempting to correctly build JS output
Jun 29, 2023
998eeea
attempting to correctly build JS output
Jun 29, 2023
ffbf8d2
attempting to correctly build JS output
Jun 29, 2023
c1226e9
attempting to correctly build JS output
Jun 29, 2023
ae84672
attempting to correctly build JS output
Jun 29, 2023
a91e71b
attempting to correctly build JS output
Jun 29, 2023
bb5d672
attempting to correctly build JS output
Jun 29, 2023
5d54f79
attempting to correctly build JS output
Jun 29, 2023
65e94ea
attempting to correctly build JS output
Jun 29, 2023
1decd0f
attempting to correctly build JS output
Jun 29, 2023
0e4846c
attempting to correctly build JS output
Jun 29, 2023
4eb5c18
attempting to correctly build JS output
Jun 29, 2023
50c840a
attempting to correctly build JS output
Jun 29, 2023
f75985c
attempting to correctly build JS output
Jun 29, 2023
da9ae61
attempting to correctly build JS output
Jun 29, 2023
a2c7f87
attempting to correctly build JS output
Jun 29, 2023
f6f04b0
attempting to correctly build JS output
Jun 29, 2023
80428b4
attempting to correctly build JS output
Jun 29, 2023
35e0e5d
attempting to correctly build JS output
Jun 30, 2023
7ee09e4
attempting to correctly build JS output
Jun 30, 2023
9715fbe
attempting to correctly build JS output
Jun 30, 2023
217f160
attempting to correctly build JS output
Jun 30, 2023
2ce6c58
attempting to correctly build JS output
Jun 30, 2023
a669d5a
attempting to correctly build JS output
Jun 30, 2023
b76ad7d
attempting to correctly build JS output
Jun 30, 2023
d6e5b5f
attempting to correctly build JS output
Jun 30, 2023
ee2625f
attempting to correctly build JS output
Jun 30, 2023
f870bfe
attempting to correctly build JS output
Jun 30, 2023
91be003
attempting to correctly build JS output
Jun 30, 2023
2d68860
attempting to correctly build JS output
Jun 30, 2023
272294d
attempting to correctly build JS output
Jun 30, 2023
a1f9c5f
attempting to correctly build JS output
Jun 30, 2023
d601ddf
attempting to correctly build JS output
Jun 30, 2023
d9a0977
attempting to correctly build JS output
Jun 30, 2023
9731486
attempting to correctly build JS output
Jun 30, 2023
5a6bf85
attempting to correctly build JS output
Jun 30, 2023
f9858b8
attempting to correctly build JS output
Jun 30, 2023
5f77a0d
attempting to correctly build JS output
Jun 30, 2023
4778223
attempting to correctly build JS output
Jun 30, 2023
198d9ad
attempting to correctly build JS output
Jun 30, 2023
71ff7ab
attempting to correctly build JS output
Jun 30, 2023
a1d55c3
attempting to correctly build JS output
Jun 30, 2023
acb2203
attempting to correctly build JS output
Jun 30, 2023
9b449a7
attempting to correctly build JS output
Jun 30, 2023
92a92f4
attempting to correctly build JS output
Jun 30, 2023
0a02445
attempting to correctly build JS output
Jun 30, 2023
cec5c7f
attempting to correctly build JS output
Jun 30, 2023
cf99fd4
attempting to correctly build JS output
Jun 30, 2023
88dc6f7
attempting to correctly build JS output
Jun 30, 2023
01de228
attempting to correctly build JS output
Jun 30, 2023
b7a91cf
attempting to correctly build JS output
Jun 30, 2023
7221b0c
attempting to correctly build JS output
Jun 30, 2023
d6ba69f
attempting to correctly build JS output
Jun 30, 2023
eb4b49b
attempting to correctly build JS output
Jun 30, 2023
f76615d
attempting to correctly build JS output
Jun 30, 2023
fa53cee
attempting to correctly build JS output
Jun 30, 2023
03f198b
attempting to correctly build JS output
Jun 30, 2023
8358534
attempting to correctly build JS output
Jun 30, 2023
c33629e
attempting to correctly build JS output
Jun 30, 2023
7c0d602
attempting to correctly build JS output
Jun 30, 2023
e83ba57
attempting to correctly build JS output
Jun 30, 2023
da92fe3
attempting to correctly build JS output
Jun 30, 2023
8bae620
now building TS successfully; clean code/comments
Jun 30, 2023
48e23d1
now building TS successfully; clean code/comments
Jun 30, 2023
55aefd9
now building TS successfully; clean code/comments
Jun 30, 2023
f53dfbe
now building TS successfully; clean code/comments
Jun 30, 2023
a9dc3d9
now building TS successfully; clean code/comments
Jun 30, 2023
f648d39
now building TS successfully; clean code/comments
Jun 30, 2023
3c92f26
now building TS successfully; clean code/comments
Jun 30, 2023
c8d9a65
now building TS with extensions successfully
Jun 30, 2023
562e77b
now building TS with extensions successfully
Jun 30, 2023
20e9e3d
now building TS with extensions successfully
Jun 30, 2023
9c4ced4
now building TS with extensions successfully
Jun 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 25 additions & 33 deletions generator/js_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,9 @@ std::string RelativeTypeName(const FieldDescriptor* field) {
std::string JSExtensionsObjectName(const GeneratorOptions& options,
const FileDescriptor* from_file,
const Descriptor* desc) {
if (desc->full_name() == "google.protobuf.bridge.MessageSet") {
if (options.WantEs6()) {
return TypeNames::JsName(desc->name()) + ".extensions";
} else if (desc->full_name() == "google.protobuf.bridge.MessageSet") {
// TODO(haberman): fix this for the kImportCommonJs case.
return "jspb.Message.messageSetExtensions";
} else {
Expand Down Expand Up @@ -2071,7 +2073,7 @@ void Generator::GenerateClassEs6(const GeneratorOptions& options,

printer->Indent();

GenerateClassConstructor(options, printer, desc);
GenerateClassConstructorAndDeclareExtensionFieldInfo(options, printer, desc);

GenerateClassFieldInfo(options, printer, desc);

Expand Down Expand Up @@ -2181,12 +2183,6 @@ void Generator::GenerateClassConstructorAndDeclareExtensionFieldInfo(
GenerateClassExtensionFieldInfo(options, printer, desc);
}
}
for (int i = 0; i < desc->nested_type_count(); i++) {
if (!IgnoreMessage(desc->nested_type(i))) {
GenerateClassConstructorAndDeclareExtensionFieldInfo(
options, printer, desc->nested_type(i));
}
}
}

void Generator::GenerateClassFieldInfo(const GeneratorOptions& options,
Expand Down Expand Up @@ -3238,9 +3234,8 @@ void Generator::GenerateClassExtensionFieldInfo(const GeneratorOptions& options,
" *\n"
" * @type {!Object<number, jspb.ExtensionFieldInfo>}\n"
" */\n"
"$class$.extensions = {};\n"
"\n",
"class", GetMessagePath(options, desc));
"static extensions = {};\n"
"\n");

printer->Print(
"\n"
Expand All @@ -3259,9 +3254,8 @@ void Generator::GenerateClassExtensionFieldInfo(const GeneratorOptions& options,
" *\n"
" * @type {!Object<number, jspb.ExtensionFieldBinaryInfo>}\n"
" */\n"
"$class$.extensionsBinary = {};\n"
"\n",
"class", GetMessagePath(options, desc));
"static extensionsBinary = {};\n"
"\n");
}
}

Expand Down Expand Up @@ -3666,22 +3660,23 @@ void Generator::GenerateExtension(const GeneratorOptions& options,
const TypeNames& type_names,
io::Printer* printer,
const FieldDescriptor* field) const {
std::string extension_scope =
(field->extension_scope()
? GetMessagePath(options, field->extension_scope())
: GetNamespace(options, field->file()));
std::string extension_scope_name =
(field->containing_type()
? TypeNames::JsName(field->containing_type()->name())
: GetNamespace(options, field->file()));
std::string extension_object_name =
JSExtensionsObjectName(options, field->file(), field->containing_type());
std::string extension_object_field_name = JSObjectFieldName(options, field);

const std::string extension_object_name = JSObjectFieldName(options, field);
printer->Print(
"\n"
"/**\n"
" * A tuple of {field number, class constructor} for the extension\n"
" * field named `$nameInComment$`.\n"
" * field named `$name$`.\n"
" * @type {!jspb.ExtensionFieldInfo<$extensionType$>}\n"
" */\n"
"$class$.$name$ = new jspb.ExtensionFieldInfo(\n",
"nameInComment", extension_object_name, "name", extension_object_name,
"class", extension_scope, "extensionType",
"class", extension_scope_name, "name", extension_object_field_name, "extensionType",
JSFieldTypeAnnotation(options, field,
/* is_setter_argument = */ false,
/* force_present = */ true,
Expand All @@ -3695,7 +3690,7 @@ void Generator::GenerateExtension(const GeneratorOptions& options,
"!Object} */ (\n"
" $toObject$),\n"
" $repeated$);\n",
"index", StrCat(field->number()), "name", extension_object_name, "ctor",
"index", StrCat(field->number()), "name", extension_object_field_name, "ctor",
(field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE
? type_names.SubmessageTypeRef(field)
: std::string("null")),
Expand All @@ -3713,12 +3708,11 @@ void Generator::GenerateExtension(const GeneratorOptions& options,
" $binaryWriterFn$,\n"
" $binaryMessageSerializeFn$,\n"
" $binaryMessageDeserializeFn$,\n",
"extendName",
JSExtensionsObjectName(options, field->file(), field->containing_type()),
"index", StrCat(field->number()), "class", extension_scope, "name",
extension_object_name, "binaryReaderFn",
JSBinaryReaderMethodName(options, field), "binaryWriterFn",
JSBinaryWriterMethodName(options, field), "binaryMessageSerializeFn",
"extendName", extension_object_name, "index", StrCat(field->number()),
"class", extension_scope_name, "name", extension_object_field_name,
"binaryReaderFn", JSBinaryReaderMethodName(options, field),
"binaryWriterFn", JSBinaryWriterMethodName(options, field),
"binaryMessageSerializeFn",
(field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE)
? (type_names.SubmessageTypeRef(field) + ".serializeBinaryToWriter")
: "undefined",
Expand All @@ -3735,10 +3729,8 @@ void Generator::GenerateExtension(const GeneratorOptions& options,
"// toObject() will function correctly.\n"
"$extendName$[$index$] = $class$.$name$;\n"
"\n",
"extendName",
JSExtensionsObjectName(options, field->file(), field->containing_type()),
"index", StrCat(field->number()), "class", extension_scope, "name",
extension_object_name);
"extendName", extension_object_name, "index", StrCat(field->number()),
"class", extension_scope_name, "name", extension_object_field_name);
}

bool GeneratorOptions::ParseFromOptions(
Expand Down