From 224f7527e3a06fe487adf99f68c92c60b8ac15de Mon Sep 17 00:00:00 2001 From: Kamil Rojewski Date: Thu, 14 Feb 2019 22:08:55 +0100 Subject: [PATCH] Generting imports for external enums in TS (#5175) --- src/idl_gen_js_ts.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/idl_gen_js_ts.cpp b/src/idl_gen_js_ts.cpp index f80a03298..518b3986d 100644 --- a/src/idl_gen_js_ts.cpp +++ b/src/idl_gen_js_ts.cpp @@ -763,6 +763,10 @@ class JsTsGenerator : public BaseGenerator { GenPrefixedTypeName(GenTypeName(field.value.type, false, true), field.value.type.enum_def->file) + " {\n"; + + if (!parser_.opts.generate_all) { + imported_files.insert(field.value.type.enum_def->file); + } } else { code += "):" + GenTypeName(field.value.type, false, true) + " {\n"; } @@ -1259,7 +1263,7 @@ class JsTsGenerator : public BaseGenerator { // Generate a convenient CreateX function code += "static create" + Verbose(struct_def); code += "(builder:flatbuffers.Builder"; - + for (auto it = struct_def.fields.vec.begin(); it != struct_def.fields.vec.end(); ++it) { const auto &field = **it; @@ -1307,7 +1311,7 @@ class JsTsGenerator : public BaseGenerator { return argname; } - std::string Verbose(const StructDef &struct_def, + std::string Verbose(const StructDef &struct_def, const char* prefix = "") { return parser_.opts.js_ts_short_names ? "" : prefix + struct_def.name;