From 363220823322bf606c600de59675862b7a806b54 Mon Sep 17 00:00:00 2001 From: Kamil Rojewski Date: Mon, 3 May 2021 19:40:59 +0200 Subject: [PATCH] removed unneeded type prefixing (#6601) --- src/idl_gen_ts.cpp | 18 +----------------- .../namespace-a/table-in-first-n-s.ts | 8 ++++---- 2 files changed, 5 insertions(+), 21 deletions(-) diff --git a/src/idl_gen_ts.cpp b/src/idl_gen_ts.cpp index b9e32f560..53e088fe1 100644 --- a/src/idl_gen_ts.cpp +++ b/src/idl_gen_ts.cpp @@ -304,21 +304,6 @@ class TsGenerator : public BaseGenerator { return value != 1 ? " * " + NumToString(value) : ""; } - static std::string GenFileNamespacePrefix(const std::string &file) { - return "NS" + NumToString(HashFnv1a(file.c_str())); - } - - // Adds a source-dependent prefix, for of import * statements. - std::string GenPrefixedTypeName(const std::string &typeName, - const std::string &file) { - const auto basename = - flatbuffers::StripPath(flatbuffers::StripExtension(file)); - if (basename == file_name_ || parser_.opts.generate_all) { - return typeName; - } - return GenFileNamespacePrefix(file) + "." + typeName; - } - void GenStructArgs(import_set &imports, const StructDef &struct_def, std::string *arguments, const std::string &nameprefix) { for (auto it = struct_def.fields.vec.begin(); @@ -1154,10 +1139,9 @@ class TsGenerator : public BaseGenerator { else { switch (field.value.type.base_type) { case BASE_TYPE_STRUCT: { - auto type = + const auto type = AddImport(imports, struct_def, *field.value.type.struct_def); GenDocComment(field.doc_comment, code_ptr); - type = GenPrefixedTypeName(type, field.value.type.struct_def->file); code += MakeCamel(field.name, false); code += "(obj?:" + type + "):" + type + "|null {\n"; diff --git a/tests/namespace_test/namespace-a/table-in-first-n-s.ts b/tests/namespace_test/namespace-a/table-in-first-n-s.ts index 774a2f16c..8e4d706bd 100644 --- a/tests/namespace_test/namespace-a/table-in-first-n-s.ts +++ b/tests/namespace_test/namespace-a/table-in-first-n-s.ts @@ -26,9 +26,9 @@ static getSizePrefixedRootAsTableInFirstNS(bb:flatbuffers.ByteBuffer, obj?:Table return (obj || new TableInFirstNS()).__init(bb.readInt32(bb.position()) + bb.position(), bb); } -fooTable(obj?:NS8755221360535654258.TableInNestedNS):NS8755221360535654258.TableInNestedNS|null { +fooTable(obj?:TableInNestedNS):TableInNestedNS|null { const offset = this.bb!.__offset(this.bb_pos, 4); - return offset ? (obj || new NS8755221360535654258.TableInNestedNS()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null; + return offset ? (obj || new TableInNestedNS()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null; } fooEnum():EnumInNestedNS { @@ -57,9 +57,9 @@ fooUnion(obj:any):any|null { return offset ? this.bb!.__union(obj, this.bb_pos + offset) : null; } -fooStruct(obj?:NS8755221360535654258.StructInNestedNS):NS8755221360535654258.StructInNestedNS|null { +fooStruct(obj?:StructInNestedNS):StructInNestedNS|null { const offset = this.bb!.__offset(this.bb_pos, 12); - return offset ? (obj || new NS8755221360535654258.StructInNestedNS()).__init(this.bb_pos + offset, this.bb!) : null; + return offset ? (obj || new StructInNestedNS()).__init(this.bb_pos + offset, this.bb!) : null; } static getFullyQualifiedName():string {