mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-28 20:40:01 +00:00
[TS] fix ts import path issue (#7298)
This commit is contained in:
@@ -777,7 +777,9 @@ class TsGenerator : public BaseGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Generate a TS union type based on a union's enum
|
// Generate a TS union type based on a union's enum
|
||||||
std::string GenObjApiUnionTypeTS(import_set &imports, const IDLOptions &opts,
|
std::string GenObjApiUnionTypeTS(import_set &imports,
|
||||||
|
const StructDef &dependent,
|
||||||
|
const IDLOptions &opts,
|
||||||
const EnumDef &union_enum) {
|
const EnumDef &union_enum) {
|
||||||
std::string ret = "";
|
std::string ret = "";
|
||||||
std::set<std::string> type_list;
|
std::set<std::string> type_list;
|
||||||
@@ -792,7 +794,7 @@ class TsGenerator : public BaseGenerator {
|
|||||||
type = "string"; // no need to wrap string type in namespace
|
type = "string"; // no need to wrap string type in namespace
|
||||||
} else if (ev.union_type.base_type == BASE_TYPE_STRUCT) {
|
} else if (ev.union_type.base_type == BASE_TYPE_STRUCT) {
|
||||||
type = GetObjApiClassName(
|
type = GetObjApiClassName(
|
||||||
AddImport(imports, union_enum, *ev.union_type.struct_def), opts);
|
AddImport(imports, dependent, *ev.union_type.struct_def), opts);
|
||||||
} else {
|
} else {
|
||||||
FLATBUFFERS_ASSERT(false);
|
FLATBUFFERS_ASSERT(false);
|
||||||
}
|
}
|
||||||
@@ -879,12 +881,13 @@ class TsGenerator : public BaseGenerator {
|
|||||||
// Used for generating a short function that returns the correct class
|
// Used for generating a short function that returns the correct class
|
||||||
// based on union enum type. Assume the context is inside the non object api
|
// based on union enum type. Assume the context is inside the non object api
|
||||||
// type
|
// type
|
||||||
std::string GenUnionValTS(import_set &imports, const std::string &field_name,
|
std::string GenUnionValTS(import_set &imports, const StructDef &dependent,
|
||||||
|
const std::string &field_name,
|
||||||
const Type &union_type,
|
const Type &union_type,
|
||||||
const bool is_array = false) {
|
const bool is_array = false) {
|
||||||
if (union_type.enum_def) {
|
if (union_type.enum_def) {
|
||||||
const auto &enum_def = *union_type.enum_def;
|
const auto &enum_def = *union_type.enum_def;
|
||||||
const auto enum_type = AddImport(imports, enum_def, enum_def);
|
const auto enum_type = AddImport(imports, dependent, enum_def);
|
||||||
const std::string union_accessor = "this." + field_name;
|
const std::string union_accessor = "this." + field_name;
|
||||||
|
|
||||||
const auto union_has_string = UnionHasStringType(enum_def);
|
const auto union_has_string = UnionHasStringType(enum_def);
|
||||||
@@ -1143,11 +1146,11 @@ class TsGenerator : public BaseGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case BASE_TYPE_UNION: {
|
case BASE_TYPE_UNION: {
|
||||||
field_type += GenObjApiUnionTypeTS(imports, parser.opts,
|
field_type += GenObjApiUnionTypeTS(
|
||||||
*(vectortype.enum_def));
|
imports, struct_def, parser.opts, *(vectortype.enum_def));
|
||||||
field_type += ")[]";
|
field_type += ")[]";
|
||||||
field_val =
|
field_val = GenUnionValTS(imports, struct_def, field_name,
|
||||||
GenUnionValTS(imports, field_name, vectortype, true);
|
vectortype, true);
|
||||||
|
|
||||||
field_offset_decl =
|
field_offset_decl =
|
||||||
EscapeKeyword(AddImport(imports, struct_def, struct_def)) +
|
EscapeKeyword(AddImport(imports, struct_def, struct_def)) +
|
||||||
@@ -1182,10 +1185,11 @@ class TsGenerator : public BaseGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case BASE_TYPE_UNION: {
|
case BASE_TYPE_UNION: {
|
||||||
field_type += GenObjApiUnionTypeTS(imports, parser.opts,
|
field_type += GenObjApiUnionTypeTS(imports, struct_def, parser.opts,
|
||||||
*(field.value.type.enum_def));
|
*(field.value.type.enum_def));
|
||||||
|
|
||||||
field_val = GenUnionValTS(imports, field_name, field.value.type);
|
field_val = GenUnionValTS(imports, struct_def, field_name,
|
||||||
|
field.value.type);
|
||||||
field_offset_decl =
|
field_offset_decl =
|
||||||
"builder.createObjectOffset(this." + field_name_escaped + ")";
|
"builder.createObjectOffset(this." + field_name_escaped + ")";
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user