Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 10 additions & 5 deletions src/idl_gen_ts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,12 @@ class TsGenerator : public BaseGenerator {
std::string enum_name =
AddImport(imports, *value.type.enum_def, *value.type.enum_def)
.name;
std::string enum_value = namer_.Variant(
*value.type.enum_def->FindByValue(value.constant));
const EnumVal* val =
value.type.enum_def->FindByValue(value.constant);
if (val == nullptr) {
val = value.type.enum_def->MinValue();
}
std::string enum_value = namer_.Variant(*val);
ret += enum_name + "." + enum_value +
(i < value.type.fixed_length - 1 ? ", " : "");
}
Expand All @@ -521,9 +525,10 @@ class TsGenerator : public BaseGenerator {
return "BigInt('" + value.constant + "')";
}
default: {
EnumVal* val = value.type.enum_def->FindByValue(value.constant);
if (val == nullptr)
val = const_cast<EnumVal*>(value.type.enum_def->MinValue());
const EnumVal* val = value.type.enum_def->FindByValue(value.constant);
if (val == nullptr) {
val = value.type.enum_def->MinValue();
}
return AddImport(imports, *value.type.enum_def, *value.type.enum_def)
.name +
"." + namer_.Variant(*val);
Expand Down
12 changes: 12 additions & 0 deletions tests/non_zero_enum.fbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
enum NonZero: ubyte {
VAL = 1,
}

struct NonZeroArrayStruct {
data: [NonZero:4];
}

table NonZeroVectorTable {
values: [NonZero];
value: NonZero = VAL;
}
5 changes: 5 additions & 0 deletions tests/ts/TypeScriptTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ def esbuild(input, output):
data="../unicode_test.json",
)

flatc(
options=["--ts", "--gen-object-api"],
schema="../non_zero_enum.fbs",
)

flatc(
options=[
"--ts",
Expand Down
Loading