Skip to content

Commit

Permalink
Fix Protobuf .d.ts typings for .proto files without package
Browse files Browse the repository at this point in the history
Fixes #939
  • Loading branch information
Yannic committed Aug 28, 2020
1 parent 0c56ed1 commit b6111fb
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions javascript/net/grpc/web/grpc_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -319,15 +319,12 @@ string ModuleAlias(const string& filename) {
string JSMessageType(const Descriptor *desc, const FileDescriptor *file) {
string class_name;
class_name = StripPrefixString(desc->full_name(), desc->file()->package());
if (!class_name.empty() && class_name[0] == '.') {
class_name = class_name.substr(1);
}
if (desc->file() == file) {
// [for protobuf .d.ts files only] Do not add the module prefix for local
// messages.
return class_name;
return StripPrefixString(class_name, ".");
}
return ModuleAlias(desc->file()->name()) + "." + class_name;
return ModuleAlias(desc->file()->name()) + class_name;
}

string JSMessageType(const Descriptor *desc) {
Expand Down Expand Up @@ -367,11 +364,13 @@ string JSElementType(const FieldDescriptor *desc, const FileDescriptor *file) {

case FieldDescriptor::TYPE_ENUM:
if (desc->enum_type()->file() == file) {
// [for protobuf .d.ts files only] Do not add the module prefix for
// local messages.
string enum_name =
StripPrefixString(
desc->enum_type()->full_name(),
desc->enum_type()->file()->package());
return enum_name.substr(1);
return StripPrefixString(enum_name, ".");
}
return ModuleAlias(desc->enum_type()->file()->name())
+ StripPrefixString(
Expand Down

0 comments on commit b6111fb

Please sign in to comment.