10000 Fix generation of top-level enums. · reddaly/protobuf-javascript@d31e215 · GitHub
[go: up one dir, main page]

Skip to content

Commit d31e215

Browse files
committed
Fix generation of top-level enums.
1 parent 5802a07 commit d31e215

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

generator/js_generator.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3615,8 +3615,14 @@ void Generator::GenerateClassSerializeBinaryField(
36153615
void Generator::GenerateEnum(const GeneratorOptions& options,
36163616
io::Printer* printer,
36173617
const EnumDescriptor* enumdesc) const {
3618+
3619+
const bool is_toplevel = enumdesc->containing_type() == nullptr;
3620+
const std::string enumNamePrefix = is_toplevel ? "export const " : "";
3621+
3622+
// TODO(reddaly): If the enum is defined at top-level, we need
3623+
// 'const <EnumName> = ' instead of '<EnumType> = '
36183624
const std::string enumNameForDefinition = options.WantEs6() ? (
3619-
enumdesc->name()
3625+
enumNamePrefix + enumdesc->name()
36203626
) : (
36213627
GetEnumPathPrefix(options, enumdesc) + enumdesc->name()
36223628
);

0 commit comments

Comments
 (0)
0