removed unneeded type prefixing (#6601)

This commit is contained in:
Kamil Rojewski
2021-05-03 19:40:59 +02:00
committed by GitHub
parent 6b44c605b8
commit 3632208233
2 changed files with 5 additions and 21 deletions

View File

@@ -304,21 +304,6 @@ class TsGenerator : public BaseGenerator {
return value != 1 ? " * " + NumToString(value) : ""; return value != 1 ? " * " + NumToString(value) : "";
} }
static std::string GenFileNamespacePrefix(const std::string &file) {
return "NS" + NumToString(HashFnv1a<uint64_t>(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, void GenStructArgs(import_set &imports, const StructDef &struct_def,
std::string *arguments, const std::string &nameprefix) { std::string *arguments, const std::string &nameprefix) {
for (auto it = struct_def.fields.vec.begin(); for (auto it = struct_def.fields.vec.begin();
@@ -1154,10 +1139,9 @@ class TsGenerator : public BaseGenerator {
else { else {
switch (field.value.type.base_type) { switch (field.value.type.base_type) {
case BASE_TYPE_STRUCT: { case BASE_TYPE_STRUCT: {
auto type = const auto type =
AddImport(imports, struct_def, *field.value.type.struct_def); AddImport(imports, struct_def, *field.value.type.struct_def);
GenDocComment(field.doc_comment, code_ptr); GenDocComment(field.doc_comment, code_ptr);
type = GenPrefixedTypeName(type, field.value.type.struct_def->file);
code += MakeCamel(field.name, false); code += MakeCamel(field.name, false);
code += "(obj?:" + type + "):" + type + "|null {\n"; code += "(obj?:" + type + "):" + type + "|null {\n";

View File

@@ -26,9 +26,9 @@ static getSizePrefixedRootAsTableInFirstNS(bb:flatbuffers.ByteBuffer, obj?:Table
return (obj || new TableInFirstNS()).__init(bb.readInt32(bb.position()) + bb.position(), bb); 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); 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 { fooEnum():EnumInNestedNS {
@@ -57,9 +57,9 @@ fooUnion<T extends flatbuffers.Table>(obj:any):any|null {
return offset ? this.bb!.__union(obj, this.bb_pos + offset) : 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); 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 { static getFullyQualifiedName():string {