From f1f23d08edd3c3dc4923e21e246f03929bce322f Mon Sep 17 00:00:00 2001 From: Kamil Rojewski Date: Fri, 31 Jul 2020 00:55:11 +0200 Subject: [PATCH] adding fb import when no other imports are present (#6030) Co-authored-by: Kamil Rojewski Co-authored-by: Wouter van Oortmerssen --- .gitignore | 4 +++- src/idl_gen_js_ts.cpp | 6 +++++- tests/union_vector/union_vector_generated.ts | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index fad67debb..ab99dfa58 100644 --- a/.gitignore +++ b/.gitignore @@ -127,4 +127,6 @@ grpc/google/ **/Package.resolved .clangd/** package-lock.json -.clwb \ No newline at end of file +/*.ilk +/*.pdb +.clwb diff --git a/src/idl_gen_js_ts.cpp b/src/idl_gen_js_ts.cpp index 1a64c481b..7afec7bb8 100644 --- a/src/idl_gen_js_ts.cpp +++ b/src/idl_gen_js_ts.cpp @@ -214,11 +214,15 @@ class JsTsGenerator : public BaseGenerator { // Emit namespaces in a form that Closure Compiler can optimize std::string &code = *code_ptr; std::string &exports = *exports_ptr; + + if (lang_.language == IDLOptions::kTs) { + code += "import * as flatbuffers from 'flatbuffers';\n"; + } + for (auto it = sorted_namespaces.begin(); it != sorted_namespaces.end(); ++it) { if (lang_.language == IDLOptions::kTs) { if (it->find('.') == std::string::npos) { - code += "import * as flatbuffers from 'flatbuffers';\n"; break; } } else { diff --git a/tests/union_vector/union_vector_generated.ts b/tests/union_vector/union_vector_generated.ts index 402f04fc5..c00f3d144 100644 --- a/tests/union_vector/union_vector_generated.ts +++ b/tests/union_vector/union_vector_generated.ts @@ -1,5 +1,6 @@ // automatically generated by the FlatBuffers compiler, do not modify +import * as flatbuffers from 'flatbuffers'; /** * @enum {number} */