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 30, 2020
1 parent 0c56ed1 commit 5a63476
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion javascript/net/grpc/web/grpc_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,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
10 changes: 10 additions & 0 deletions packages/grpc-web/test/protos/test01.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,15 @@ message MessageOuter {
int32 value = 1;
}

enum EnumInner {
DEFAULT = 0;
}

repeated MessageInner someProp = 1;
EnumOuter someEnum = 2;
EnumInner anotherEnum = 3;
}

enum EnumOuter {
DEFAULT = 0;
}

0 comments on commit 5a63476

Please sign in to comment.