summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/idl_gen_ts.cpp2
-rw-r--r--tests/my-game/example/monster.ts12
-rw-r--r--tests/namespace_test/namespace-a/second-table-in-a.ts4
-rw-r--r--tests/namespace_test/namespace-a/table-in-first-n-s.ts6
-rw-r--r--tests/namespace_test/namespace-c/table-in-c.ts7
5 files changed, 21 insertions, 10 deletions
diff --git a/src/idl_gen_ts.cpp b/src/idl_gen_ts.cpp
index 89dd8c5b..a6d4ef6c 100644
--- a/src/idl_gen_ts.cpp
+++ b/src/idl_gen_ts.cpp
@@ -856,7 +856,7 @@ class TsGenerator : public BaseGenerator {
const std::string field_accessor = "this." + field_name + "()";
field_val = GenNullCheckConditional(field_accessor,
field_accessor + "!.unpack()");
- field_offset_val = GenNullCheckConditional(
+ field_offset_decl = GenNullCheckConditional(
"this." + field_name, "this." + field_name + "!.pack(builder)",
"0");
diff --git a/tests/my-game/example/monster.ts b/tests/my-game/example/monster.ts
index 69bfa584..33e256f7 100644
--- a/tests/my-game/example/monster.ts
+++ b/tests/my-game/example/monster.ts
@@ -1284,13 +1284,16 @@ constructor(
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
+ const pos = (this.pos !== null ? this.pos!.pack(builder) : 0);
const name = (this.name !== null ? builder.createString(this.name!) : 0);
const inventory = Monster.createInventoryVector(builder, this.inventory);
const test = builder.createObjectOffset(this.test);
const test4 = builder.createStructOffsetList(this.test4, Monster.startTest4Vector);
const testarrayofstring = Monster.createTestarrayofstringVector(builder, builder.createObjectOffsetList(this.testarrayofstring));
const testarrayoftables = Monster.createTestarrayoftablesVector(builder, builder.createObjectOffsetList(this.testarrayoftables));
+ const enemy = (this.enemy !== null ? this.enemy!.pack(builder) : 0);
const testnestedflatbuffer = Monster.createTestnestedflatbufferVector(builder, this.testnestedflatbuffer);
+ const testempty = (this.testempty !== null ? this.testempty!.pack(builder) : 0);
const testarrayofbools = Monster.createTestarrayofboolsVector(builder, this.testarrayofbools);
const testarrayofstring2 = Monster.createTestarrayofstring2Vector(builder, builder.createObjectOffsetList(this.testarrayofstring2));
const testarrayofsortedstruct = builder.createStructOffsetList(this.testarrayofsortedstruct, Monster.startTestarrayofsortedstructVector);
@@ -1298,6 +1301,7 @@ pack(builder:flatbuffers.Builder): flatbuffers.Offset {
const test5 = builder.createStructOffsetList(this.test5, Monster.startTest5Vector);
const vectorOfLongs = Monster.createVectorOfLongsVector(builder, this.vectorOfLongs);
const vectorOfDoubles = Monster.createVectorOfDoublesVector(builder, this.vectorOfDoubles);
+ const parentNamespaceTest = (this.parentNamespaceTest !== null ? this.parentNamespaceTest!.pack(builder) : 0);
const vectorOfReferrables = Monster.createVectorOfReferrablesVector(builder, builder.createObjectOffsetList(this.vectorOfReferrables));
const vectorOfWeakReferences = Monster.createVectorOfWeakReferencesVector(builder, this.vectorOfWeakReferences);
const vectorOfStrongReferrables = Monster.createVectorOfStrongReferrablesVector(builder, builder.createObjectOffsetList(this.vectorOfStrongReferrables));
@@ -1310,7 +1314,7 @@ pack(builder:flatbuffers.Builder): flatbuffers.Offset {
const scalarKeySortedTables = Monster.createScalarKeySortedTablesVector(builder, builder.createObjectOffsetList(this.scalarKeySortedTables));
Monster.startMonster(builder);
- Monster.addPos(builder, (this.pos !== null ? this.pos!.pack(builder) : 0));
+ Monster.addPos(builder, pos);
Monster.addMana(builder, this.mana);
Monster.addHp(builder, this.hp);
Monster.addName(builder, name);
@@ -1321,9 +1325,9 @@ pack(builder:flatbuffers.Builder): flatbuffers.Offset {
Monster.addTest4(builder, test4);
Monster.addTestarrayofstring(builder, testarrayofstring);
Monster.addTestarrayoftables(builder, testarrayoftables);
- Monster.addEnemy(builder, (this.enemy !== null ? this.enemy!.pack(builder) : 0));
+ Monster.addEnemy(builder, enemy);
Monster.addTestnestedflatbuffer(builder, testnestedflatbuffer);
- Monster.addTestempty(builder, (this.testempty !== null ? this.testempty!.pack(builder) : 0));
+ Monster.addTestempty(builder, testempty);
Monster.addTestbool(builder, this.testbool);
Monster.addTesthashs32Fnv1(builder, this.testhashs32Fnv1);
Monster.addTesthashu32Fnv1(builder, this.testhashu32Fnv1);
@@ -1343,7 +1347,7 @@ pack(builder:flatbuffers.Builder): flatbuffers.Offset {
Monster.addTest5(builder, test5);
Monster.addVectorOfLongs(builder, vectorOfLongs);
Monster.addVectorOfDoubles(builder, vectorOfDoubles);
- Monster.addParentNamespaceTest(builder, (this.parentNamespaceTest !== null ? this.parentNamespaceTest!.pack(builder) : 0));
+ Monster.addParentNamespaceTest(builder, parentNamespaceTest);
Monster.addVectorOfReferrables(builder, vectorOfReferrables);
Monster.addSingleWeakReference(builder, this.singleWeakReference);
Monster.addVectorOfWeakReferences(builder, vectorOfWeakReferences);
diff --git a/tests/namespace_test/namespace-a/second-table-in-a.ts b/tests/namespace_test/namespace-a/second-table-in-a.ts
index 2d50a83b..9be34024 100644
--- a/tests/namespace_test/namespace-a/second-table-in-a.ts
+++ b/tests/namespace_test/namespace-a/second-table-in-a.ts
@@ -70,8 +70,10 @@ constructor(
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
+ const referToC = (this.referToC !== null ? this.referToC!.pack(builder) : 0);
+
return SecondTableInA.createSecondTableInA(builder,
- (this.referToC !== null ? this.referToC!.pack(builder) : 0)
+ referToC
);
}
}
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 7a8832ea..72563a75 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
@@ -135,14 +135,16 @@ constructor(
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
+ const fooTable = (this.fooTable !== null ? this.fooTable!.pack(builder) : 0);
const fooUnion = builder.createObjectOffset(this.fooUnion);
+ const fooStruct = (this.fooStruct !== null ? this.fooStruct!.pack(builder) : 0);
TableInFirstNS.startTableInFirstNS(builder);
- TableInFirstNS.addFooTable(builder, (this.fooTable !== null ? this.fooTable!.pack(builder) : 0));
+ TableInFirstNS.addFooTable(builder, fooTable);
TableInFirstNS.addFooEnum(builder, this.fooEnum);
TableInFirstNS.addFooUnionType(builder, this.fooUnionType);
TableInFirstNS.addFooUnion(builder, fooUnion);
- TableInFirstNS.addFooStruct(builder, (this.fooStruct !== null ? this.fooStruct!.pack(builder) : 0));
+ TableInFirstNS.addFooStruct(builder, fooStruct);
return TableInFirstNS.endTableInFirstNS(builder);
}
diff --git a/tests/namespace_test/namespace-c/table-in-c.ts b/tests/namespace_test/namespace-c/table-in-c.ts
index 7fd559bd..7b924b88 100644
--- a/tests/namespace_test/namespace-c/table-in-c.ts
+++ b/tests/namespace_test/namespace-c/table-in-c.ts
@@ -78,9 +78,12 @@ constructor(
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
+ const referToA1 = (this.referToA1 !== null ? this.referToA1!.pack(builder) : 0);
+ const referToA2 = (this.referToA2 !== null ? this.referToA2!.pack(builder) : 0);
+
TableInC.startTableInC(builder);
- TableInC.addReferToA1(builder, (this.referToA1 !== null ? this.referToA1!.pack(builder) : 0));
- TableInC.addReferToA2(builder, (this.referToA2 !== null ? this.referToA2!.pack(builder) : 0));
+ TableInC.addReferToA1(builder, referToA1);
+ TableInC.addReferToA2(builder, referToA2);
return TableInC.endTableInC(builder);
}