mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-11 07:27:27 +00:00
In Javascript, generate bidirectional mappings for enums, between Name: Value and between Value: Name. (#4960)
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
925c1d77fc
commit
d840856093
@@ -355,9 +355,22 @@ class JsGenerator : public BaseGenerator {
|
||||
if (it != enum_def.vals.vec.begin()) { code += '\n'; }
|
||||
GenDocComment(ev.doc_comment, code_ptr, "", " ");
|
||||
}
|
||||
|
||||
// Generate mapping between EnumName: EnumValue(int)
|
||||
code += " " + ev.name;
|
||||
code += lang_.language == IDLOptions::kTs ? "= " : ": ";
|
||||
code += NumToString(ev.value);
|
||||
|
||||
if (lang_.language == IDLOptions::kJs) {
|
||||
// In pure Javascript, generate mapping between EnumValue(int):
|
||||
// 'EnumName' so enums can be looked up by their ID.
|
||||
code += ", ";
|
||||
|
||||
code += NumToString(ev.value);
|
||||
code += lang_.language == IDLOptions::kTs ? "= " : ": ";
|
||||
code += "'" + ev.name + "'";
|
||||
}
|
||||
|
||||
code += (it + 1) != enum_def.vals.vec.end() ? ",\n" : "\n";
|
||||
|
||||
if (ev.union_type.struct_def) {
|
||||
|
||||
Reference in New Issue
Block a user