From 9d483a3f0b4517ceadbb736ab8b9a279dca36748 Mon Sep 17 00:00:00 2001 From: Christopher Cifra Date: Thu, 14 Feb 2019 18:00:33 -0600 Subject: [PATCH] Changed the JavaScript generation to emit createX helper functions just like the TypeScript code generation. I also added code so that the create methods have documentation in both JavaScript and TypeScript. (#5168) --- src/idl_gen_js_ts.cpp | 136 +++++++++------ tests/monster_test_generated.js | 191 ++++++++++++++++++++++ tests/namespace_test/namespace_test1_generated.js | 11 ++ tests/namespace_test/namespace_test2_generated.js | 39 +++++ tests/union_vector/union_vector_generated.js | 28 ++++ 5 files changed, 358 insertions(+), 47 deletions(-) diff --git a/src/idl_gen_js_ts.cpp b/src/idl_gen_js_ts.cpp index 518b398..a2e75fd 100644 --- a/src/idl_gen_js_ts.cpp +++ b/src/idl_gen_js_ts.cpp @@ -77,7 +77,7 @@ class JsTsGenerator : public BaseGenerator { reexport_map; JsTsGenerator(const Parser &parser, const std::string &path, - const std::string &file_name) + const std::string &file_name) : BaseGenerator(parser, path, file_name, "", "."), lang_(GetJsLangParams(parser_.opts.lang)){}; // Iterate through all definitions we haven't generate code for (enums, @@ -105,10 +105,10 @@ class JsTsGenerator : public BaseGenerator { if (lang_.language == IDLOptions::kJs && !exports_code.empty() && !parser_.opts.skip_js_exports) { - if( parser_.opts.use_ES6_js_export_format ) - code += "// Exports for ECMAScript6 Modules\n"; - else - code += "// Exports for Node.js and RequireJS\n"; + if (parser_.opts.use_ES6_js_export_format) + code += "// Exports for ECMAScript6 Modules\n"; + else + code += "// Exports for Node.js and RequireJS\n"; code += exports_code; } @@ -127,8 +127,8 @@ class JsTsGenerator : public BaseGenerator { const auto &file = *it; const auto basename = flatbuffers::StripPath(flatbuffers::StripExtension(file)); - if (basename != file_name_) { - code += GenPrefixedImport(file, basename); + if (basename != file_name_) { + code += GenPrefixedImport(file, basename); } } } @@ -225,7 +225,7 @@ class JsTsGenerator : public BaseGenerator { code += "var "; if (parser_.opts.use_goog_js_export_format) { exports += "goog.exportSymbol('" + *it + "', " + *it + ");\n"; - } else if( parser_.opts.use_ES6_js_export_format){ + } else if (parser_.opts.use_ES6_js_export_format) { exports += "export {" + *it + "};\n"; } else { exports += "this." + *it + " = " + *it + ";\n"; @@ -310,8 +310,8 @@ class JsTsGenerator : public BaseGenerator { } default: { result += " {" + type_name + "}"; } } - if (!arg_name.empty()) { - result += " " + arg_name; + if (!arg_name.empty()) { + result += " " + arg_name; } if (include_newline) { result += "\n"; @@ -548,7 +548,9 @@ class JsTsGenerator : public BaseGenerator { const std::string &file) { const auto basename = flatbuffers::StripPath(flatbuffers::StripExtension(file)); - if (basename == file_name_ || parser_.opts.generate_all) { return typeName; } + if (basename == file_name_ || parser_.opts.generate_all) { + return typeName; + } return GenFileNamespacePrefix(file) + "." + typeName; } @@ -695,7 +697,7 @@ class JsTsGenerator : public BaseGenerator { GenTypeAnnotation(kParam, object_name + "=", "obj") + GenTypeAnnotation(kReturns, object_name, "", false)); if (lang_.language == IDLOptions::kTs) { - code += "static getRoot" + Verbose(struct_def,"As"); + code += "static getRoot" + Verbose(struct_def, "As"); code += "(bb:flatbuffers.ByteBuffer, obj?:" + object_name + "):" + object_name + " {\n"; } else { @@ -880,7 +882,7 @@ class JsTsGenerator : public BaseGenerator { code += prefix + ", obj?:" + vectortypename; if (!parser_.opts.generate_all) { - imported_files.insert(vectortype.struct_def->file); + imported_files.insert(vectortype.struct_def->file); } } else if (vectortype.base_type == BASE_TYPE_STRING) { code += prefix + "):string\n"; @@ -1087,7 +1089,8 @@ class JsTsGenerator : public BaseGenerator { "", false)); if (lang_.language == IDLOptions::kTs) { - code += "static create" + Verbose(struct_def) + "(builder:flatbuffers.Builder"; + code += "static create" + Verbose(struct_def) + + "(builder:flatbuffers.Builder"; code += arguments + "):flatbuffers.Offset {\n"; } else { code += object_name + ".create" + Verbose(struct_def); @@ -1103,7 +1106,8 @@ class JsTsGenerator : public BaseGenerator { "builder", false)); if (lang_.language == IDLOptions::kTs) { - code += "static start" + Verbose(struct_def) + "(builder:flatbuffers.Builder) {\n"; + code += "static start" + Verbose(struct_def) + + "(builder:flatbuffers.Builder) {\n"; } else { code += object_name + ".start" + Verbose(struct_def); code += " = function(builder) {\n"; @@ -1129,8 +1133,8 @@ class JsTsGenerator : public BaseGenerator { if (lang_.language == IDLOptions::kTs) { code += "static add" + MakeCamel(field.name); - code += "(builder:flatbuffers.Builder, " + argname + ":" + GetArgType(field) + - ") {\n"; + code += "(builder:flatbuffers.Builder, " + argname + ":" + + GetArgType(field) + ") {\n"; } else { code += object_name + ".add" + MakeCamel(field.name); code += " = function(builder, " + argname + ") {\n"; @@ -1245,7 +1249,8 @@ class JsTsGenerator : public BaseGenerator { if (lang_.language == IDLOptions::kTs) { code += "static finish" + Verbose(struct_def) + "Buffer"; - code += "(builder:flatbuffers.Builder, offset:flatbuffers.Offset) {\n"; + code += + "(builder:flatbuffers.Builder, offset:flatbuffers.Offset) {\n"; } else { code += object_name + ".finish" + Verbose(struct_def) + "Buffer"; code += " = function(builder, offset) {\n"; @@ -1259,40 +1264,77 @@ class JsTsGenerator : public BaseGenerator { code += "};\n\n"; } - if (lang_.language == IDLOptions::kTs) { - // Generate a convenient CreateX function - code += "static create" + Verbose(struct_def); - code += "(builder:flatbuffers.Builder"; + // Generate a convenient CreateX function + if (lang_.language == IDLOptions::kJs) { + std::string paramDoc = + GenTypeAnnotation(kParam, "flatbuffers.Builder", "builder"); + for (auto it = struct_def.fields.vec.begin(); + it != struct_def.fields.vec.end(); ++it) { + const auto &field = **it; + if (field.deprecated) + continue; + paramDoc += + GenTypeAnnotation(kParam, GetArgType(field), GetArgName(field)); + } + paramDoc += + GenTypeAnnotation(kReturns, "flatbuffers.Offset", "", false); - for (auto it = struct_def.fields.vec.begin(); - it != struct_def.fields.vec.end(); ++it) { - const auto &field = **it; - if (field.deprecated) - continue; + GenDocComment(code_ptr, paramDoc); + } - code += ", " + GetArgName(field) + ":" + GetArgType(field); - } + if (lang_.language == IDLOptions::kTs) { + code += "static create" + Verbose(struct_def); + code += "(builder:flatbuffers.Builder"; + } else { + code += object_name + ".create" + Verbose(struct_def); + code += " = function(builder"; + } + for (auto it = struct_def.fields.vec.begin(); + it != struct_def.fields.vec.end(); ++it) { + const auto &field = **it; + if (field.deprecated) + continue; - code += "):flatbuffers.Offset {\n"; - code += " " + struct_def.name + ".start" + Verbose(struct_def) + "(builder);\n"; + if (lang_.language == IDLOptions::kTs) { + code += ", " + GetArgName(field) + ":" + GetArgType(field); + } else { + code += ", " + GetArgName(field); + } + } - for (auto it = struct_def.fields.vec.begin(); - it != struct_def.fields.vec.end(); ++it) { - const auto &field = **it; - if (field.deprecated) - continue; + if (lang_.language == IDLOptions::kTs) { + code += "):flatbuffers.Offset {\n"; + code += " " + struct_def.name + ".start" + Verbose(struct_def) + + "(builder);\n"; + } else { + code += ") {\n"; + code += " " + object_name + ".start" + Verbose(struct_def) + + "(builder);\n"; + } - code += " " + struct_def.name + ".add" + MakeCamel(field.name) +"("; - code += "builder, " + GetArgName(field) + ");\n"; - } + std::string methodPrefix = + lang_.language == IDLOptions::kTs ? struct_def.name : object_name; + for (auto it = struct_def.fields.vec.begin(); + it != struct_def.fields.vec.end(); ++it) { + const auto &field = **it; + if (field.deprecated) + continue; - code += " return " + struct_def.name + ".end" + Verbose(struct_def) + "(builder);\n"; - code += "}\n"; + code += " " + methodPrefix + ".add" + MakeCamel(field.name) + "("; + code += "builder, " + GetArgName(field) + ");\n"; } + + code += " return " + methodPrefix + ".end" + Verbose(struct_def) + + "(builder);\n"; + code += "}\n"; + if (lang_.language == IDLOptions::kJs) + code += "\n"; } if (lang_.language == IDLOptions::kTs) { - if (!object_namespace.empty()) { code += "}\n"; } + if (!object_namespace.empty()) { + code += "}\n"; + } code += "}\n"; } } @@ -1305,10 +1347,10 @@ class JsTsGenerator : public BaseGenerator { } static std::string GetArgName(const FieldDef &field) { - auto argname = MakeCamel(field.name, false); - if (!IsScalar(field.value.type.base_type)) { argname += "Offset"; } + auto argname = MakeCamel(field.name, false); + if (!IsScalar(field.value.type.base_type)) { argname += "Offset"; } - return argname; + return argname; } std::string Verbose(const StructDef &struct_def, @@ -1320,13 +1362,13 @@ class JsTsGenerator : public BaseGenerator { } // namespace jsts bool GenerateJSTS(const Parser &parser, const std::string &path, - const std::string &file_name) { + const std::string &file_name) { jsts::JsTsGenerator generator(parser, path, file_name); return generator.generate(); } std::string JSTSMakeRule(const Parser &parser, const std::string &path, - const std::string &file_name) { + const std::string &file_name) { FLATBUFFERS_ASSERT(parser.opts.lang <= IDLOptions::kMAX); const auto &lang = GetJsLangParams(parser.opts.lang); diff --git a/tests/monster_test_generated.js b/tests/monster_test_generated.js index 7a9069a..730bb21 100644 --- a/tests/monster_test_generated.js +++ b/tests/monster_test_generated.js @@ -115,6 +115,15 @@ MyGame.InParentNamespace.endInParentNamespace = function(builder) { }; /** + * @param {flatbuffers.Builder} builder + * @returns {flatbuffers.Offset} + */ +MyGame.InParentNamespace.createInParentNamespace = function(builder) { + MyGame.InParentNamespace.startInParentNamespace(builder); + return MyGame.InParentNamespace.endInParentNamespace(builder); +} + +/** * @constructor */ MyGame.Example2.Monster = function() { @@ -166,6 +175,15 @@ MyGame.Example2.Monster.endMonster = function(builder) { }; /** + * @param {flatbuffers.Builder} builder + * @returns {flatbuffers.Offset} + */ +MyGame.Example2.Monster.createMonster = function(builder) { + MyGame.Example2.Monster.startMonster(builder); + return MyGame.Example2.Monster.endMonster(builder); +} + +/** * @constructor */ MyGame.Example.Test = function() { @@ -332,6 +350,17 @@ MyGame.Example.TestSimpleTableWithEnum.endTestSimpleTableWithEnum = function(bui }; /** + * @param {flatbuffers.Builder} builder + * @param {MyGame.Example.Color} color + * @returns {flatbuffers.Offset} + */ +MyGame.Example.TestSimpleTableWithEnum.createTestSimpleTableWithEnum = function(builder, color) { + MyGame.Example.TestSimpleTableWithEnum.startTestSimpleTableWithEnum(builder); + MyGame.Example.TestSimpleTableWithEnum.addColor(builder, color); + return MyGame.Example.TestSimpleTableWithEnum.endTestSimpleTableWithEnum(builder); +} + +/** * @constructor */ MyGame.Example.Vec3 = function() { @@ -717,6 +746,21 @@ MyGame.Example.Stat.endStat = function(builder) { }; /** + * @param {flatbuffers.Builder} builder + * @param {flatbuffers.Offset} idOffset + * @param {flatbuffers.Long} val + * @param {number} count + * @returns {flatbuffers.Offset} + */ +MyGame.Example.Stat.createStat = function(builder, idOffset, val, count) { + MyGame.Example.Stat.startStat(builder); + MyGame.Example.Stat.addId(builder, idOffset); + MyGame.Example.Stat.addVal(builder, val); + MyGame.Example.Stat.addCount(builder, count); + return MyGame.Example.Stat.endStat(builder); +} + +/** * @constructor */ MyGame.Example.Referrable = function() { @@ -799,6 +843,17 @@ MyGame.Example.Referrable.endReferrable = function(builder) { }; /** + * @param {flatbuffers.Builder} builder + * @param {flatbuffers.Long} id + * @returns {flatbuffers.Offset} + */ +MyGame.Example.Referrable.createReferrable = function(builder, id) { + MyGame.Example.Referrable.startReferrable(builder); + MyGame.Example.Referrable.addId(builder, id); + return MyGame.Example.Referrable.endReferrable(builder); +} + +/** * an example documentation comment: monster object * * @constructor @@ -2504,6 +2559,109 @@ MyGame.Example.Monster.finishMonsterBuffer = function(builder, offset) { }; /** + * @param {flatbuffers.Builder} builder + * @param {flatbuffers.Offset} posOffset + * @param {number} mana + * @param {number} hp + * @param {flatbuffers.Offset} nameOffset + * @param {flatbuffers.Offset} inventoryOffset + * @param {MyGame.Example.Color} color + * @param {MyGame.Example.Any} testType + * @param {flatbuffers.Offset} testOffset + * @param {flatbuffers.Offset} test4Offset + * @param {flatbuffers.Offset} testarrayofstringOffset + * @param {flatbuffers.Offset} testarrayoftablesOffset + * @param {flatbuffers.Offset} enemyOffset + * @param {flatbuffers.Offset} testnestedflatbufferOffset + * @param {flatbuffers.Offset} testemptyOffset + * @param {boolean} testbool + * @param {number} testhashs32Fnv1 + * @param {number} testhashu32Fnv1 + * @param {flatbuffers.Long} testhashs64Fnv1 + * @param {flatbuffers.Long} testhashu64Fnv1 + * @param {number} testhashs32Fnv1a + * @param {number} testhashu32Fnv1a + * @param {flatbuffers.Long} testhashs64Fnv1a + * @param {flatbuffers.Long} testhashu64Fnv1a + * @param {flatbuffers.Offset} testarrayofboolsOffset + * @param {number} testf + * @param {number} testf2 + * @param {number} testf3 + * @param {flatbuffers.Offset} testarrayofstring2Offset + * @param {flatbuffers.Offset} testarrayofsortedstructOffset + * @param {flatbuffers.Offset} flexOffset + * @param {flatbuffers.Offset} test5Offset + * @param {flatbuffers.Offset} vectorOfLongsOffset + * @param {flatbuffers.Offset} vectorOfDoublesOffset + * @param {flatbuffers.Offset} parentNamespaceTestOffset + * @param {flatbuffers.Offset} vectorOfReferrablesOffset + * @param {flatbuffers.Long} singleWeakReference + * @param {flatbuffers.Offset} vectorOfWeakReferencesOffset + * @param {flatbuffers.Offset} vectorOfStrongReferrablesOffset + * @param {flatbuffers.Long} coOwningReference + * @param {flatbuffers.Offset} vectorOfCoOwningReferencesOffset + * @param {flatbuffers.Long} nonOwningReference + * @param {flatbuffers.Offset} vectorOfNonOwningReferencesOffset + * @param {MyGame.Example.AnyUniqueAliases} anyUniqueType + * @param {flatbuffers.Offset} anyUniqueOffset + * @param {MyGame.Example.AnyAmbiguousAliases} anyAmbiguousType + * @param {flatbuffers.Offset} anyAmbiguousOffset + * @param {flatbuffers.Offset} vectorOfEnumsOffset + * @returns {flatbuffers.Offset} + */ +MyGame.Example.Monster.createMonster = function(builder, posOffset, mana, hp, nameOffset, inventoryOffset, color, testType, testOffset, test4Offset, testarrayofstringOffset, testarrayoftablesOffset, enemyOffset, testnestedflatbufferOffset, testemptyOffset, testbool, testhashs32Fnv1, testhashu32Fnv1, testhashs64Fnv1, testhashu64Fnv1, testhashs32Fnv1a, testhashu32Fnv1a, testhashs64Fnv1a, testhashu64Fnv1a, testarrayofboolsOffset, testf, testf2, testf3, testarrayofstring2Offset, testarrayofsortedstructOffset, flexOffset, test5Offset, vectorOfLongsOffset, vectorOfDoublesOffset, parentNamespaceTestOffset, vectorOfReferrablesOffset, singleWeakReference, vectorOfWeakReferencesOffset, vectorOfStrongReferrablesOffset, coOwningReference, vectorOfCoOwningReferencesOffset, nonOwningReference, vectorOfNonOwningReferencesOffset, anyUniqueType, anyUniqueOffset, anyAmbiguousType, anyAmbiguousOffset, vectorOfEnumsOffset) { + MyGame.Example.Monster.startMonster(builder); + MyGame.Example.Monster.addPos(builder, posOffset); + MyGame.Example.Monster.addMana(builder, mana); + MyGame.Example.Monster.addHp(builder, hp); + MyGame.Example.Monster.addName(builder, nameOffset); + MyGame.Example.Monster.addInventory(builder, inventoryOffset); + MyGame.Example.Monster.addColor(builder, color); + MyGame.Example.Monster.addTestType(builder, testType); + MyGame.Example.Monster.addTest(builder, testOffset); + MyGame.Example.Monster.addTest4(builder, test4Offset); + MyGame.Example.Monster.addTestarrayofstring(builder, testarrayofstringOffset); + MyGame.Example.Monster.addTestarrayoftables(builder, testarrayoftablesOffset); + MyGame.Example.Monster.addEnemy(builder, enemyOffset); + MyGame.Example.Monster.addTestnestedflatbuffer(builder, testnestedflatbufferOffset); + MyGame.Example.Monster.addTestempty(builder, testemptyOffset); + MyGame.Example.Monster.addTestbool(builder, testbool); + MyGame.Example.Monster.addTesthashs32Fnv1(builder, testhashs32Fnv1); + MyGame.Example.Monster.addTesthashu32Fnv1(builder, testhashu32Fnv1); + MyGame.Example.Monster.addTesthashs64Fnv1(builder, testhashs64Fnv1); + MyGame.Example.Monster.addTesthashu64Fnv1(builder, testhashu64Fnv1); + MyGame.Example.Monster.addTesthashs32Fnv1a(builder, testhashs32Fnv1a); + MyGame.Example.Monster.addTesthashu32Fnv1a(builder, testhashu32Fnv1a); + MyGame.Example.Monster.addTesthashs64Fnv1a(builder, testhashs64Fnv1a); + MyGame.Example.Monster.addTesthashu64Fnv1a(builder, testhashu64Fnv1a); + MyGame.Example.Monster.addTestarrayofbools(builder, testarrayofboolsOffset); + MyGame.Example.Monster.addTestf(builder, testf); + MyGame.Example.Monster.addTestf2(builder, testf2); + MyGame.Example.Monster.addTestf3(builder, testf3); + MyGame.Example.Monster.addTestarrayofstring2(builder, testarrayofstring2Offset); + MyGame.Example.Monster.addTestarrayofsortedstruct(builder, testarrayofsortedstructOffset); + MyGame.Example.Monster.addFlex(builder, flexOffset); + MyGame.Example.Monster.addTest5(builder, test5Offset); + MyGame.Example.Monster.addVectorOfLongs(builder, vectorOfLongsOffset); + MyGame.Example.Monster.addVectorOfDoubles(builder, vectorOfDoublesOffset); + MyGame.Example.Monster.addParentNamespaceTest(builder, parentNamespaceTestOffset); + MyGame.Example.Monster.addVectorOfReferrables(builder, vectorOfReferrablesOffset); + MyGame.Example.Monster.addSingleWeakReference(builder, singleWeakReference); + MyGame.Example.Monster.addVectorOfWeakReferences(builder, vectorOfWeakReferencesOffset); + MyGame.Example.Monster.addVectorOfStrongReferrables(builder, vectorOfStrongReferrablesOffset); + MyGame.Example.Monster.addCoOwningReference(builder, coOwningReference); + MyGame.Example.Monster.addVectorOfCoOwningReferences(builder, vectorOfCoOwningReferencesOffset); + MyGame.Example.Monster.addNonOwningReference(builder, nonOwningReference); + MyGame.Example.Monster.addVectorOfNonOwningReferences(builder, vectorOfNonOwningReferencesOffset); + MyGame.Example.Monster.addAnyUniqueType(builder, anyUniqueType); + MyGame.Example.Monster.addAnyUnique(builder, anyUniqueOffset); + MyGame.Example.Monster.addAnyAmbiguousType(builder, anyAmbiguousType); + MyGame.Example.Monster.addAnyAmbiguous(builder, anyAmbiguousOffset); + MyGame.Example.Monster.addVectorOfEnums(builder, vectorOfEnumsOffset); + return MyGame.Example.Monster.endMonster(builder); +} + +/** * @constructor */ MyGame.Example.TypeAliases = function() { @@ -2972,5 +3130,38 @@ MyGame.Example.TypeAliases.endTypeAliases = function(builder) { return offset; }; +/** + * @param {flatbuffers.Builder} builder + * @param {number} i8 + * @param {number} u8 + * @param {number} i16 + * @param {number} u16 + * @param {number} i32 + * @param {number} u32 + * @param {flatbuffers.Long} i64 + * @param {flatbuffers.Long} u64 + * @param {number} f32 + * @param {number} f64 + * @param {flatbuffers.Offset} v8Offset + * @param {flatbuffers.Offset} vf64Offset + * @returns {flatbuffers.Offset} + */ +MyGame.Example.TypeAliases.createTypeAliases = function(builder, i8, u8, i16, u16, i32, u32, i64, u64, f32, f64, v8Offset, vf64Offset) { + MyGame.Example.TypeAliases.startTypeAliases(builder); + MyGame.Example.TypeAliases.addI8(builder, i8); + MyGame.Example.TypeAliases.addU8(builder, u8); + MyGame.Example.TypeAliases.addI16(builder, i16); + MyGame.Example.TypeAliases.addU16(builder, u16); + MyGame.Example.TypeAliases.addI32(builder, i32); + MyGame.Example.TypeAliases.addU32(builder, u32); + MyGame.Example.TypeAliases.addI64(builder, i64); + MyGame.Example.TypeAliases.addU64(builder, u64); + MyGame.Example.TypeAliases.addF32(builder, f32); + MyGame.Example.TypeAliases.addF64(builder, f64); + MyGame.Example.TypeAliases.addV8(builder, v8Offset); + MyGame.Example.TypeAliases.addVf64(builder, vf64Offset); + return MyGame.Example.TypeAliases.endTypeAliases(builder); +} + // Exports for Node.js and RequireJS this.MyGame = MyGame; diff --git a/tests/namespace_test/namespace_test1_generated.js b/tests/namespace_test/namespace_test1_generated.js index c7a3561..d318f22 100644 --- a/tests/namespace_test/namespace_test1_generated.js +++ b/tests/namespace_test/namespace_test1_generated.js @@ -104,6 +104,17 @@ NamespaceA.NamespaceB.TableInNestedNS.endTableInNestedNS = function(builder) { }; /** + * @param {flatbuffers.Builder} builder + * @param {number} foo + * @returns {flatbuffers.Offset} + */ +NamespaceA.NamespaceB.TableInNestedNS.createTableInNestedNS = function(builder, foo) { + NamespaceA.NamespaceB.TableInNestedNS.startTableInNestedNS(builder); + NamespaceA.NamespaceB.TableInNestedNS.addFoo(builder, foo); + return NamespaceA.NamespaceB.TableInNestedNS.endTableInNestedNS(builder); +} + +/** * @constructor */ NamespaceA.NamespaceB.StructInNestedNS = function() { diff --git a/tests/namespace_test/namespace_test2_generated.js b/tests/namespace_test/namespace_test2_generated.js index 25db73f..a06e05e 100644 --- a/tests/namespace_test/namespace_test2_generated.js +++ b/tests/namespace_test/namespace_test2_generated.js @@ -135,6 +135,21 @@ NamespaceA.TableInFirstNS.endTableInFirstNS = function(builder) { }; /** + * @param {flatbuffers.Builder} builder + * @param {flatbuffers.Offset} fooTableOffset + * @param {NS8755221360535654258.NamespaceA.NamespaceB.EnumInNestedNS} fooEnum + * @param {flatbuffers.Offset} fooStructOffset + * @returns {flatbuffers.Offset} + */ +NamespaceA.TableInFirstNS.createTableInFirstNS = function(builder, fooTableOffset, fooEnum, fooStructOffset) { + NamespaceA.TableInFirstNS.startTableInFirstNS(builder); + NamespaceA.TableInFirstNS.addFooTable(builder, fooTableOffset); + NamespaceA.TableInFirstNS.addFooEnum(builder, fooEnum); + NamespaceA.TableInFirstNS.addFooStruct(builder, fooStructOffset); + return NamespaceA.TableInFirstNS.endTableInFirstNS(builder); +} + +/** * @constructor */ NamespaceC.TableInC = function() { @@ -220,6 +235,19 @@ NamespaceC.TableInC.endTableInC = function(builder) { }; /** + * @param {flatbuffers.Builder} builder + * @param {flatbuffers.Offset} referToA1Offset + * @param {flatbuffers.Offset} referToA2Offset + * @returns {flatbuffers.Offset} + */ +NamespaceC.TableInC.createTableInC = function(builder, referToA1Offset, referToA2Offset) { + NamespaceC.TableInC.startTableInC(builder); + NamespaceC.TableInC.addReferToA1(builder, referToA1Offset); + NamespaceC.TableInC.addReferToA2(builder, referToA2Offset); + return NamespaceC.TableInC.endTableInC(builder); +} + +/** * @constructor */ NamespaceA.SecondTableInA = function() { @@ -287,6 +315,17 @@ NamespaceA.SecondTableInA.endSecondTableInA = function(builder) { return offset; }; +/** + * @param {flatbuffers.Builder} builder + * @param {flatbuffers.Offset} referToCOffset + * @returns {flatbuffers.Offset} + */ +NamespaceA.SecondTableInA.createSecondTableInA = function(builder, referToCOffset) { + NamespaceA.SecondTableInA.startSecondTableInA(builder); + NamespaceA.SecondTableInA.addReferToC(builder, referToCOffset); + return NamespaceA.SecondTableInA.endSecondTableInA(builder); +} + // Exports for Node.js and RequireJS this.NamespaceA = NamespaceA; this.NamespaceC = NamespaceC; diff --git a/tests/union_vector/union_vector_generated.js b/tests/union_vector/union_vector_generated.js index b208e9c..5c1a579 100644 --- a/tests/union_vector/union_vector_generated.js +++ b/tests/union_vector/union_vector_generated.js @@ -96,6 +96,17 @@ Attacker.endAttacker = function(builder) { }; /** + * @param {flatbuffers.Builder} builder + * @param {number} swordAttackDamage + * @returns {flatbuffers.Offset} + */ +Attacker.createAttacker = function(builder, swordAttackDamage) { + Attacker.startAttacker(builder); + Attacker.addSwordAttackDamage(builder, swordAttackDamage); + return Attacker.endAttacker(builder); +} + +/** * @constructor */ function Rapunzel() { @@ -429,6 +440,23 @@ Movie.finishMovieBuffer = function(builder, offset) { builder.finish(offset, 'MOVI'); }; +/** + * @param {flatbuffers.Builder} builder + * @param {Character} mainCharacterType + * @param {flatbuffers.Offset} mainCharacterOffset + * @param {flatbuffers.Offset} charactersTypeOffset + * @param {flatbuffers.Offset} charactersOffset + * @returns {flatbuffers.Offset} + */ +Movie.createMovie = function(builder, mainCharacterType, mainCharacterOffset, charactersTypeOffset, charactersOffset) { + Movie.startMovie(builder); + Movie.addMainCharacterType(builder, mainCharacterType); + Movie.addMainCharacter(builder, mainCharacterOffset); + Movie.addCharactersType(builder, charactersTypeOffset); + Movie.addCharacters(builder, charactersOffset); + return Movie.endMovie(builder); +} + // Exports for Node.js and RequireJS this.Character = Character; this.Attacker = Attacker; -- 2.7.4