From 68b0d64fd2e80418c31a13a7f64aa3889bd54a02 Mon Sep 17 00:00:00 2001 From: Derek Bailey Date: Mon, 15 Aug 2022 16:11:45 -0700 Subject: [PATCH] Partial support for --ts-flat-files and --gen-all (#7446) * Partial support for --ts-flat-files and --gen-all * Add generated code changes * remove some debugging code left over * missed grpc files --- .../ts/greeter/src/models/hello-reply.ts | 2 +- .../ts/greeter/src/models/hello-request.ts | 2 +- src/flatc.cpp | 4 - src/idl_gen_ts.cpp | 106 +++++++------ tests/flatc/bar/baz/baz.fbs | 7 +- tests/flatc/flatc_test.py | 18 ++- tests/flatc/flatc_ts_tests.py | 139 +++++++++++++++++- tests/monster_test_generated.ts | 2 + tests/my-game/example/ability.ts | 2 +- .../my-game/example/any-ambiguous-aliases.ts | 2 +- tests/my-game/example/any-unique-aliases.ts | 2 +- tests/my-game/example/any.ts | 2 +- tests/my-game/example/color.ts | 2 +- tests/my-game/example/long-enum.ts | 2 +- tests/my-game/example/monster.ts | 2 +- tests/my-game/example/race.ts | 2 +- tests/my-game/example/referrable.ts | 2 +- tests/my-game/example/stat.ts | 2 +- .../example/struct-of-structs-of-structs.ts | 2 +- tests/my-game/example/struct-of-structs.ts | 2 +- .../example/test-simple-table-with-enum.ts | 2 +- tests/my-game/example/test.ts | 2 +- tests/my-game/example/type-aliases.ts | 2 +- tests/my-game/example/vec3.ts | 2 +- tests/my-game/example2/monster.ts | 2 +- tests/my-game/in-parent-namespace.ts | 2 +- tests/optional-scalars/optional-byte.ts | 2 +- tests/optional-scalars/scalar-stuff.ts | 2 +- tests/optional_scalars_generated.ts | 2 + tests/union_vector/attacker.ts | 2 +- tests/union_vector/book-reader.ts | 2 +- tests/union_vector/character.ts | 2 +- tests/union_vector/falling-tub.ts | 2 +- tests/union_vector/gadget.ts | 2 +- tests/union_vector/hand-fan.ts | 2 +- tests/union_vector/movie.ts | 2 +- tests/union_vector/rapunzel.ts | 2 +- tests/union_vector/union_vector_generated.ts | 2 + 38 files changed, 241 insertions(+), 99 deletions(-) diff --git a/grpc/examples/ts/greeter/src/models/hello-reply.ts b/grpc/examples/ts/greeter/src/models/hello-reply.ts index e68f7a4ceff..b041a7ec350 100644 --- a/grpc/examples/ts/greeter/src/models/hello-reply.ts +++ b/grpc/examples/ts/greeter/src/models/hello-reply.ts @@ -7,7 +7,7 @@ import * as flatbuffers from 'flatbuffers'; export class HelloReply { bb: flatbuffers.ByteBuffer|null = null; bb_pos = 0; -__init(i:number, bb:flatbuffers.ByteBuffer):HelloReply { + __init(i:number, bb:flatbuffers.ByteBuffer):HelloReply { this.bb_pos = i; this.bb = bb; return this; diff --git a/grpc/examples/ts/greeter/src/models/hello-request.ts b/grpc/examples/ts/greeter/src/models/hello-request.ts index 3718167c4e7..d943e45cba1 100644 --- a/grpc/examples/ts/greeter/src/models/hello-request.ts +++ b/grpc/examples/ts/greeter/src/models/hello-request.ts @@ -7,7 +7,7 @@ import * as flatbuffers from 'flatbuffers'; export class HelloRequest { bb: flatbuffers.ByteBuffer|null = null; bb_pos = 0; -__init(i:number, bb:flatbuffers.ByteBuffer):HelloRequest { + __init(i:number, bb:flatbuffers.ByteBuffer):HelloRequest { this.bb_pos = i; this.bb = bb; return this; diff --git a/src/flatc.cpp b/src/flatc.cpp index 543d62fd8dd..f71a1f8c5e6 100644 --- a/src/flatc.cpp +++ b/src/flatc.cpp @@ -643,10 +643,6 @@ int FlatCompiler::Compile(int argc, const char **argv) { "well."); } - if (opts.ts_flat_file && opts.generate_all) { - Error("Combining --ts-flat-file and --gen-all is not supported."); - } - flatbuffers::Parser conform_parser; if (!conform_to_schema.empty()) { std::string contents; diff --git a/src/idl_gen_ts.cpp b/src/idl_gen_ts.cpp index 1533825a960..cdfa5135ef2 100644 --- a/src/idl_gen_ts.cpp +++ b/src/idl_gen_ts.cpp @@ -38,7 +38,7 @@ struct ImportDefinition { }; enum AnnotationType { kParam = 0, kType = 1, kReturns = 2 }; -} +} // namespace namespace ts { // Iterate through all definitions we haven't generate code for (enums, structs, @@ -111,10 +111,6 @@ class TsGenerator : public BaseGenerator { for (auto kw = keywords; *kw; kw++) keywords_.insert(*kw); } bool generate() { - if (parser_.opts.ts_flat_file && parser_.opts.generate_all) { - // Not implemented; warning message should have been emitted by flatc. - return false; - } generateEnums(); generateStructs(); generateEntry(); @@ -227,39 +223,45 @@ class TsGenerator : public BaseGenerator { // Generate code for a single entry point module. void generateEntry() { - std::string code; + std::string code = + "// " + std::string(FlatBuffersGeneratedWarning()) + "\n\n"; if (parser_.opts.ts_flat_file) { if (import_flatbuffers_lib_) { code += "import * as flatbuffers from 'flatbuffers';\n"; + code += "\n"; } - for (const auto &it : flat_file_import_declarations_) { - // Note that we do end up generating an import for ourselves, which - // should generally be harmless. - // TODO: Make it so we don't generate a self-import; this will also - // require modifying AddImport to ensure that we don't use - // namespace-prefixed names anywhere... - std::string file = it.first; - if (file.empty()) { continue; } - std::string noext = flatbuffers::StripExtension(file); - std::string basename = flatbuffers::StripPath(noext); - std::string include_file = GeneratedFileName( - parser_.opts.include_prefix, - parser_.opts.keep_prefix ? noext : basename, parser_.opts); - // TODO: what is the right behavior when different include flags are - // specified here? Should we always be adding the "./" for a relative - // path or turn it off if --include-prefix is specified, or something - // else? - std::string include_name = - "./" + flatbuffers::StripExtension(include_file); - code += "import {"; - for (const auto &pair : it.second) { - code += EscapeKeyword(pair.first) + " as " + - EscapeKeyword(pair.second) + ", "; + // Only include import statements when not generating all. + if (!parser_.opts.generate_all) { + for (const auto &it : flat_file_import_declarations_) { + // Note that we do end up generating an import for ourselves, which + // should generally be harmless. + // TODO: Make it so we don't generate a self-import; this will also + // require modifying AddImport to ensure that we don't use + // namespace-prefixed names anywhere... + std::string file = it.first; + if (file.empty()) { continue; } + std::string noext = flatbuffers::StripExtension(file); + std::string basename = flatbuffers::StripPath(noext); + std::string include_file = GeneratedFileName( + parser_.opts.include_prefix, + parser_.opts.keep_prefix ? noext : basename, parser_.opts); + // TODO: what is the right behavior when different include flags are + // specified here? Should we always be adding the "./" for a relative + // path or turn it off if --include-prefix is specified, or something + // else? + std::string include_name = + "./" + flatbuffers::StripExtension(include_file); + code += "import {"; + for (const auto &pair : it.second) { + code += EscapeKeyword(pair.first) + " as " + + EscapeKeyword(pair.second) + ", "; + } + code.resize(code.size() - 2); + code += "} from '" + include_name + "';\n"; } - code.resize(code.size() - 2); - code += "} from '" + include_name + "';\n"; + code += "\n"; } - code += "\n\n"; + code += flat_file_; const std::string filename = GeneratedFileName(path_, file_name_, parser_.opts); @@ -305,7 +307,9 @@ class TsGenerator : public BaseGenerator { if (reverse) return; // FIXME. std::string &code = *code_ptr; GenDocComment(enum_def.doc_comment, code_ptr); - code += "export enum " + EscapeKeyword(enum_def.name) + "{\n"; + code += "export enum "; + // TODO(7445): figure out if the export needs a namespace for ts-flat-files + code += EscapeKeyword(enum_def.name) + " {\n"; for (auto it = enum_def.Vals().begin(); it != enum_def.Vals().end(); ++it) { auto &ev = **it; if (!ev.doc_comment.empty()) { @@ -659,19 +663,14 @@ class TsGenerator : public BaseGenerator { // above, but since we force all non-self-imports to use namespace-based // names in flat file generation, it's fine). if (dependent.file == dependency.file) { - // Should already be caught elsewhere, but if we ever try to get flat - // file generation and --gen-all working concurrently, then we'll need - // to update this import logic. - FLATBUFFERS_ASSERT(!parser_.opts.generate_all); long_import_name = import_name; } else { long_import_name = ns + import_name; - std::string file = dependency.declaration_file == nullptr - ? dependency.file - : dependency.declaration_file->substr(2); - file = RelativeToRootPath(StripFileName(AbsolutePath(dependent.file)), - dependency.file) - .substr(2); + std::string file = + RelativeToRootPath(StripFileName(AbsolutePath(dependent.file)), + dependency.file) + // Strip the leading // + .substr(2); flat_file_import_declarations_[file][import_name] = long_import_name; if (parser_.opts.generate_object_based_api) { flat_file_import_declarations_[file][import_name + "T"] = @@ -753,19 +752,14 @@ class TsGenerator : public BaseGenerator { // above, but since we force all non-self-imports to use namespace-based // names in flat file generation, it's fine). if (dependent.file == dependency.file) { - // Should already be caught elsewhere, but if we ever try to get flat - // file generation and --gen-all working concurrently, then we'll need - // to update this import logic. - FLATBUFFERS_ASSERT(!parser_.opts.generate_all); long_import_name = import_name; } else { long_import_name = ns + import_name; - std::string file = dependency.declaration_file == nullptr - ? dependency.file - : dependency.declaration_file->substr(2); - file = RelativeToRootPath(StripFileName(AbsolutePath(dependent.file)), - dependency.file) - .substr(2); + std::string file = + RelativeToRootPath(StripFileName(AbsolutePath(dependent.file)), + dependency.file) + // Strip the leading // + .substr(2); flat_file_import_declarations_[file][import_name] = long_import_name; } } @@ -1347,7 +1341,9 @@ class TsGenerator : public BaseGenerator { // Emit constructor object_name = EscapeKeyword(struct_def.name); GenDocComment(struct_def.doc_comment, code_ptr); - code += "export class " + object_name; + code += "export class "; + // TODO(7445): figure out if the export needs a namespace for ts-flat-files + code += object_name; code += " {\n"; code += " bb: flatbuffers.ByteBuffer|null = null;\n"; code += " bb_pos = 0;\n"; @@ -1355,7 +1351,7 @@ class TsGenerator : public BaseGenerator { // Generate the __init method that sets the field in a pre-existing // accessor object. This is to allow object reuse. code += - "__init(i:number, bb:flatbuffers.ByteBuffer):" + object_name + " {\n"; + " __init(i:number, bb:flatbuffers.ByteBuffer):" + object_name + " {\n"; code += " this.bb_pos = i;\n"; code += " this.bb = bb;\n"; code += " return this;\n"; diff --git a/tests/flatc/bar/baz/baz.fbs b/tests/flatc/bar/baz/baz.fbs index f5eca1c4ef5..254e980a09d 100644 --- a/tests/flatc/bar/baz/baz.fbs +++ b/tests/flatc/bar/baz/baz.fbs @@ -1,3 +1,6 @@ -table Baz { - a:int; +enum Baz : short { + None = 0, + Red, + Green, + Blue, } \ No newline at end of file diff --git a/tests/flatc/flatc_test.py b/tests/flatc/flatc_test.py index a86e432a2d0..41889384cb6 100755 --- a/tests/flatc/flatc_test.py +++ b/tests/flatc/flatc_test.py @@ -77,8 +77,22 @@ def assert_file_contains(file, needles): return file -def assert_file_and_contents(file, needle, path=script_path, unlink=True): +def assert_file_doesnt_contains(file, needles): + with open(file) as file: + contents = file.read() + for needle in [needles] if isinstance(needles, str) else needles: + assert needle not in contents, ( + "Found unexpected '" + needle + "' in file: " + str(file) + ) + return file + + +def assert_file_and_contents( + file, needle, doesnt_contain=None, path=script_path, unlink=True +): assert_file_contains(assert_file_exists(file, path), needle) + if doesnt_contain: + assert_file_doesnt_contains(assert_file_exists(file, path), doesnt_contain) if unlink: Path(path, file).unlink() @@ -102,7 +116,7 @@ def run_all(*modules): module_passing = module_passing + 1 except Exception as e: print(" [FAILED]: " + str(e)) - failingmodule_failing = failingmodule_failing + 1 + module_failing = module_failing + 1 print( "{0}: {1} of {2} passsed".format( module.__name__, module_passing, module_passing + module_failing diff --git a/tests/flatc/flatc_ts_tests.py b/tests/flatc/flatc_ts_tests.py index 3617c449c07..46123671107 100755 --- a/tests/flatc/flatc_ts_tests.py +++ b/tests/flatc/flatc_ts_tests.py @@ -14,6 +14,7 @@ from flatc_test import * + class TsTests(): def Base(self): @@ -24,7 +25,10 @@ def Base(self): # include, bar. assert_file_and_contents( "foo_generated.ts", - ["export { Bar } from './bar';", "export { Foo } from './foo';"], + [ + "export { Bar } from './bar';", + "export { Foo } from './foo';", + ], ) # Foo should be generated in place and exports the Foo table. @@ -33,6 +37,26 @@ def Base(self): # Included files, like bar, should not be generated. assert_file_doesnt_exists("bar.ts") + def BaseMultipleFiles(self): + # Generate both foo and bar with no extra arguments + flatc(["--ts", "foo.fbs", "bar/bar.fbs"]) + + # Should generate the module that exports both foo and its direct + # include, bar. + assert_file_and_contents( + "foo_generated.ts", + [ + "export { Bar } from './bar';", + "export { Foo } from './foo';", + ], + ) + + # Foo should be generated in place and exports the Foo table. + assert_file_and_contents("foo.ts", "export class Foo {") + + # Bar should also be generatd in place and exports the Bar table. + assert_file_and_contents("bar.ts", "export class Bar {") + def BaseWithNamespace(self): # Generate foo with namespacing, with no extra arguments flatc(["--ts", "foo_with_ns.fbs"]) @@ -41,29 +65,132 @@ def BaseWithNamespace(self): # directory and its direct include, bar. assert_file_and_contents( "foo_with_ns_generated.ts", - ["export { Bar } from './bar';", "export { Foo } from './something/foo';"], + [ + "export { Bar } from './bar';", + "export { Foo } from './something/foo';", + ], ) # Foo should be placed in the namespaced directory. It should export # Foo, and the import of Bar should be relative to its location. assert_file_and_contents( "something/foo.ts", - ["export class Foo {", "import { Bar } from '../bar';"], + [ + "export class Foo {", + "import { Bar } from '../bar';", + ], ) # Included files, like bar, should not be generated. assert_file_doesnt_exists("bar.ts") + def GenAll(self): + # Generate foo with generate all options + flatc(["--ts", "--gen-all", "foo.fbs"]) + + # Should generate a single file that exports all the generated types. + assert_file_and_contents( + "foo_generated.ts", + [ + "export { Bar } from './bar'", + "export { Baz } from './baz'", + "export { Foo } from './foo'", + ], + ) + + # Foo should be generated with an import to Bar and an export of itself. + assert_file_and_contents( + "foo.ts", + [ + "import { Bar } from './bar';", + "export class Foo {", + ], + ) + + # Bar should be generated with an import to Baz and an export of itself. + assert_file_and_contents( + "bar.ts", + [ + "import { Baz } from './baz';", + "export class Bar {", + ], + ) + + # Baz should be generated with an export of itself. + assert_file_and_contents( + "baz.ts", + [ + "export enum Baz {", + ], + ) + + def FlatFiles(self): - # Generate just foo the flat files option + # Generate just foo with the flat files option flatc(["--ts", "--ts-flat-files", "foo.fbs"]) - # Should generate a single file that imports bar as a single file, and] + # Should generate a single file that imports bar as a single file, and # exports the Foo table. assert_file_and_contents( "foo_generated.ts", - ["import {Bar as Bar} from './bar_generated';", "export class Foo {"], + [ + "import {Bar as Bar} from './bar_generated';", + "export class Foo {", + ], ) # The root type Foo should not be generated in its own file. assert_file_doesnt_exists("foo.ts") + + def FlatFilesMultipleFiles(self): + # Generate both foo and bar with the flat files option + flatc(["--ts", "--ts-flat-files", "foo.fbs", "bar/bar.fbs"]) + + # Should generate a single foo file that imports bar as a single file, + # and exports the Foo table. + assert_file_and_contents( + "foo_generated.ts", + [ + "import {Bar as Bar} from './bar_generated';", + "export class Foo {", + ], + ) + + # Should generate a single bar file that imports bar as a single file, + # and exports the Bar table. + assert_file_and_contents( + "bar_generated.ts", + [ + "import {Baz as Baz} from './baz_generated';", + "export class Bar {", + ], + ) + + # The types Foo and Bar should not be generated in their own files + assert_file_doesnt_exists("foo.ts") + assert_file_doesnt_exists("bar.ts") + + def FlatFilesGenAll(self): + # Generate foo with all of its dependents with the flat files option + flatc(["--ts", "--ts-flat-files", "--gen-all", "foo.fbs"]) + + # Should generate a single foo file + assert_file_and_contents( + "foo_generated.ts", + # Should export each of the types within the single file + [ + "export class Foo {", + "export class Bar {", + "export enum Baz {", + ], + # No includes for the dependent types should be present. + doesnt_contain=[ + "import {Bar as Bar}", + "import {Baz as Baz}", + ], + ) + + # The types Foo, Bar and Baz should not be generated in their own files. + assert_file_doesnt_exists("foo.ts") + assert_file_doesnt_exists("bar.ts") + assert_file_doesnt_exists("baz.ts") diff --git a/tests/monster_test_generated.ts b/tests/monster_test_generated.ts index 56b4cc14fd8..9e80d919951 100644 --- a/tests/monster_test_generated.ts +++ b/tests/monster_test_generated.ts @@ -1,3 +1,5 @@ +// automatically generated by the FlatBuffers compiler, do not modify + export { Monster } from './my-game/example/monster'; export { Monster as MyGameExample2Monster, MonsterT as MyGameExample2MonsterT } from './my-game/example2/monster'; export { Ability, AbilityT } from './my-game/example/ability'; diff --git a/tests/my-game/example/ability.ts b/tests/my-game/example/ability.ts index 26395fba7f2..805fe7b39fd 100644 --- a/tests/my-game/example/ability.ts +++ b/tests/my-game/example/ability.ts @@ -7,7 +7,7 @@ import * as flatbuffers from 'flatbuffers'; export class Ability { bb: flatbuffers.ByteBuffer|null = null; bb_pos = 0; -__init(i:number, bb:flatbuffers.ByteBuffer):Ability { + __init(i:number, bb:flatbuffers.ByteBuffer):Ability { this.bb_pos = i; this.bb = bb; return this; diff --git a/tests/my-game/example/any-ambiguous-aliases.ts b/tests/my-game/example/any-ambiguous-aliases.ts index 6687a419087..ff4ffa7f399 100644 --- a/tests/my-game/example/any-ambiguous-aliases.ts +++ b/tests/my-game/example/any-ambiguous-aliases.ts @@ -3,7 +3,7 @@ import { Monster, MonsterT } from '../../my-game/example/monster'; -export enum AnyAmbiguousAliases{ +export enum AnyAmbiguousAliases { NONE = 0, M1 = 1, M2 = 2, diff --git a/tests/my-game/example/any-unique-aliases.ts b/tests/my-game/example/any-unique-aliases.ts index 51061488e23..79cde0fadbe 100644 --- a/tests/my-game/example/any-unique-aliases.ts +++ b/tests/my-game/example/any-unique-aliases.ts @@ -5,7 +5,7 @@ import { Monster, MonsterT } from '../../my-game/example/monster'; import { TestSimpleTableWithEnum, TestSimpleTableWithEnumT } from '../../my-game/example/test-simple-table-with-enum'; -export enum AnyUniqueAliases{ +export enum AnyUniqueAliases { NONE = 0, M = 1, TS = 2, diff --git a/tests/my-game/example/any.ts b/tests/my-game/example/any.ts index 9d8b2a61b4a..19eceaeff1f 100644 --- a/tests/my-game/example/any.ts +++ b/tests/my-game/example/any.ts @@ -5,7 +5,7 @@ import { Monster, MonsterT } from '../../my-game/example/monster'; import { TestSimpleTableWithEnum, TestSimpleTableWithEnumT } from '../../my-game/example/test-simple-table-with-enum'; -export enum Any{ +export enum Any { NONE = 0, Monster = 1, TestSimpleTableWithEnum = 2, diff --git a/tests/my-game/example/color.ts b/tests/my-game/example/color.ts index ceb31f82cb4..b9520a2c009 100644 --- a/tests/my-game/example/color.ts +++ b/tests/my-game/example/color.ts @@ -3,7 +3,7 @@ /** * Composite components of Monster color. */ -export enum Color{ +export enum Color { Red = 1, /** diff --git a/tests/my-game/example/long-enum.ts b/tests/my-game/example/long-enum.ts index be418192dfe..76e3a77b660 100644 --- a/tests/my-game/example/long-enum.ts +++ b/tests/my-game/example/long-enum.ts @@ -1,6 +1,6 @@ // automatically generated by the FlatBuffers compiler, do not modify -export enum LongEnum{ +export enum LongEnum { LongOne = '2', LongTwo = '4', LongBig = '1099511627776' diff --git a/tests/my-game/example/monster.ts b/tests/my-game/example/monster.ts index c6cb33ee0dc..ddd99bcf023 100644 --- a/tests/my-game/example/monster.ts +++ b/tests/my-game/example/monster.ts @@ -23,7 +23,7 @@ import { InParentNamespace, InParentNamespaceT } from '../../my-game/in-parent-n export class Monster { bb: flatbuffers.ByteBuffer|null = null; bb_pos = 0; -__init(i:number, bb:flatbuffers.ByteBuffer):Monster { + __init(i:number, bb:flatbuffers.ByteBuffer):Monster { this.bb_pos = i; this.bb = bb; return this; diff --git a/tests/my-game/example/race.ts b/tests/my-game/example/race.ts index 06ca128b72c..9c66d7a7256 100644 --- a/tests/my-game/example/race.ts +++ b/tests/my-game/example/race.ts @@ -1,6 +1,6 @@ // automatically generated by the FlatBuffers compiler, do not modify -export enum Race{ +export enum Race { None = -1, Human = 0, Dwarf = 1, diff --git a/tests/my-game/example/referrable.ts b/tests/my-game/example/referrable.ts index fdac6c3db30..745800e7ed9 100644 --- a/tests/my-game/example/referrable.ts +++ b/tests/my-game/example/referrable.ts @@ -7,7 +7,7 @@ import * as flatbuffers from 'flatbuffers'; export class Referrable { bb: flatbuffers.ByteBuffer|null = null; bb_pos = 0; -__init(i:number, bb:flatbuffers.ByteBuffer):Referrable { + __init(i:number, bb:flatbuffers.ByteBuffer):Referrable { this.bb_pos = i; this.bb = bb; return this; diff --git a/tests/my-game/example/stat.ts b/tests/my-game/example/stat.ts index 0082ef8aa46..1ba85a4f4be 100644 --- a/tests/my-game/example/stat.ts +++ b/tests/my-game/example/stat.ts @@ -7,7 +7,7 @@ import * as flatbuffers from 'flatbuffers'; export class Stat { bb: flatbuffers.ByteBuffer|null = null; bb_pos = 0; -__init(i:number, bb:flatbuffers.ByteBuffer):Stat { + __init(i:number, bb:flatbuffers.ByteBuffer):Stat { this.bb_pos = i; this.bb = bb; return this; diff --git a/tests/my-game/example/struct-of-structs-of-structs.ts b/tests/my-game/example/struct-of-structs-of-structs.ts index e90c415e488..20d6c739cd0 100644 --- a/tests/my-game/example/struct-of-structs-of-structs.ts +++ b/tests/my-game/example/struct-of-structs-of-structs.ts @@ -8,7 +8,7 @@ import { StructOfStructs, StructOfStructsT } from '../../my-game/example/struct- export class StructOfStructsOfStructs { bb: flatbuffers.ByteBuffer|null = null; bb_pos = 0; -__init(i:number, bb:flatbuffers.ByteBuffer):StructOfStructsOfStructs { + __init(i:number, bb:flatbuffers.ByteBuffer):StructOfStructsOfStructs { this.bb_pos = i; this.bb = bb; return this; diff --git a/tests/my-game/example/struct-of-structs.ts b/tests/my-game/example/struct-of-structs.ts index 979bb50a86e..c4a7c48bd1c 100644 --- a/tests/my-game/example/struct-of-structs.ts +++ b/tests/my-game/example/struct-of-structs.ts @@ -9,7 +9,7 @@ import { Test, TestT } from '../../my-game/example/test'; export class StructOfStructs { bb: flatbuffers.ByteBuffer|null = null; bb_pos = 0; -__init(i:number, bb:flatbuffers.ByteBuffer):StructOfStructs { + __init(i:number, bb:flatbuffers.ByteBuffer):StructOfStructs { this.bb_pos = i; this.bb = bb; return this; diff --git a/tests/my-game/example/test-simple-table-with-enum.ts b/tests/my-game/example/test-simple-table-with-enum.ts index 99a541f93c5..a34beecd07a 100644 --- a/tests/my-game/example/test-simple-table-with-enum.ts +++ b/tests/my-game/example/test-simple-table-with-enum.ts @@ -8,7 +8,7 @@ import { Color } from '../../my-game/example/color'; export class TestSimpleTableWithEnum { bb: flatbuffers.ByteBuffer|null = null; bb_pos = 0; -__init(i:number, bb:flatbuffers.ByteBuffer):TestSimpleTableWithEnum { + __init(i:number, bb:flatbuffers.ByteBuffer):TestSimpleTableWithEnum { this.bb_pos = i; this.bb = bb; return this; diff --git a/tests/my-game/example/test.ts b/tests/my-game/example/test.ts index afed125ef0d..dc62c8cde51 100644 --- a/tests/my-game/example/test.ts +++ b/tests/my-game/example/test.ts @@ -7,7 +7,7 @@ import * as flatbuffers from 'flatbuffers'; export class Test { bb: flatbuffers.ByteBuffer|null = null; bb_pos = 0; -__init(i:number, bb:flatbuffers.ByteBuffer):Test { + __init(i:number, bb:flatbuffers.ByteBuffer):Test { this.bb_pos = i; this.bb = bb; return this; diff --git a/tests/my-game/example/type-aliases.ts b/tests/my-game/example/type-aliases.ts index edb45676402..1a2f45636f8 100644 --- a/tests/my-game/example/type-aliases.ts +++ b/tests/my-game/example/type-aliases.ts @@ -7,7 +7,7 @@ import * as flatbuffers from 'flatbuffers'; export class TypeAliases { bb: flatbuffers.ByteBuffer|null = null; bb_pos = 0; -__init(i:number, bb:flatbuffers.ByteBuffer):TypeAliases { + __init(i:number, bb:flatbuffers.ByteBuffer):TypeAliases { this.bb_pos = i; this.bb = bb; return this; diff --git a/tests/my-game/example/vec3.ts b/tests/my-game/example/vec3.ts index 5cdc2ca9929..7a2f25a1556 100644 --- a/tests/my-game/example/vec3.ts +++ b/tests/my-game/example/vec3.ts @@ -9,7 +9,7 @@ import { Test, TestT } from '../../my-game/example/test'; export class Vec3 { bb: flatbuffers.ByteBuffer|null = null; bb_pos = 0; -__init(i:number, bb:flatbuffers.ByteBuffer):Vec3 { + __init(i:number, bb:flatbuffers.ByteBuffer):Vec3 { this.bb_pos = i; this.bb = bb; return this; diff --git a/tests/my-game/example2/monster.ts b/tests/my-game/example2/monster.ts index 14d7685f432..2d52f6c601a 100644 --- a/tests/my-game/example2/monster.ts +++ b/tests/my-game/example2/monster.ts @@ -7,7 +7,7 @@ import * as flatbuffers from 'flatbuffers'; export class Monster { bb: flatbuffers.ByteBuffer|null = null; bb_pos = 0; -__init(i:number, bb:flatbuffers.ByteBuffer):Monster { + __init(i:number, bb:flatbuffers.ByteBuffer):Monster { this.bb_pos = i; this.bb = bb; return this; diff --git a/tests/my-game/in-parent-namespace.ts b/tests/my-game/in-parent-namespace.ts index 8cfe9b60c19..1822e4d34fa 100644 --- a/tests/my-game/in-parent-namespace.ts +++ b/tests/my-game/in-parent-namespace.ts @@ -7,7 +7,7 @@ import * as flatbuffers from 'flatbuffers'; export class InParentNamespace { bb: flatbuffers.ByteBuffer|null = null; bb_pos = 0; -__init(i:number, bb:flatbuffers.ByteBuffer):InParentNamespace { + __init(i:number, bb:flatbuffers.ByteBuffer):InParentNamespace { this.bb_pos = i; this.bb = bb; return this; diff --git a/tests/optional-scalars/optional-byte.ts b/tests/optional-scalars/optional-byte.ts index 1db479f1a5b..65e7105be47 100644 --- a/tests/optional-scalars/optional-byte.ts +++ b/tests/optional-scalars/optional-byte.ts @@ -1,6 +1,6 @@ // automatically generated by the FlatBuffers compiler, do not modify -export enum OptionalByte{ +export enum OptionalByte { None = 0, One = 1, Two = 2 diff --git a/tests/optional-scalars/scalar-stuff.ts b/tests/optional-scalars/scalar-stuff.ts index a748c224a11..7c8fd516d45 100644 --- a/tests/optional-scalars/scalar-stuff.ts +++ b/tests/optional-scalars/scalar-stuff.ts @@ -8,7 +8,7 @@ import { OptionalByte } from '../optional-scalars/optional-byte'; export class ScalarStuff { bb: flatbuffers.ByteBuffer|null = null; bb_pos = 0; -__init(i:number, bb:flatbuffers.ByteBuffer):ScalarStuff { + __init(i:number, bb:flatbuffers.ByteBuffer):ScalarStuff { this.bb_pos = i; this.bb = bb; return this; diff --git a/tests/optional_scalars_generated.ts b/tests/optional_scalars_generated.ts index 9a2d71e5877..9eb0b31a93b 100644 --- a/tests/optional_scalars_generated.ts +++ b/tests/optional_scalars_generated.ts @@ -1,2 +1,4 @@ +// automatically generated by the FlatBuffers compiler, do not modify + export { ScalarStuff } from './optional-scalars/scalar-stuff'; export { OptionalByte } from './optional-scalars/optional-byte'; diff --git a/tests/union_vector/attacker.ts b/tests/union_vector/attacker.ts index af3702052de..6b3fc0fc140 100644 --- a/tests/union_vector/attacker.ts +++ b/tests/union_vector/attacker.ts @@ -7,7 +7,7 @@ import * as flatbuffers from 'flatbuffers'; export class Attacker { bb: flatbuffers.ByteBuffer|null = null; bb_pos = 0; -__init(i:number, bb:flatbuffers.ByteBuffer):Attacker { + __init(i:number, bb:flatbuffers.ByteBuffer):Attacker { this.bb_pos = i; this.bb = bb; return this; diff --git a/tests/union_vector/book-reader.ts b/tests/union_vector/book-reader.ts index 231060061b0..7a31278125a 100644 --- a/tests/union_vector/book-reader.ts +++ b/tests/union_vector/book-reader.ts @@ -7,7 +7,7 @@ import * as flatbuffers from 'flatbuffers'; export class BookReader { bb: flatbuffers.ByteBuffer|null = null; bb_pos = 0; -__init(i:number, bb:flatbuffers.ByteBuffer):BookReader { + __init(i:number, bb:flatbuffers.ByteBuffer):BookReader { this.bb_pos = i; this.bb = bb; return this; diff --git a/tests/union_vector/character.ts b/tests/union_vector/character.ts index dbf8d51d4a1..57c658bd509 100644 --- a/tests/union_vector/character.ts +++ b/tests/union_vector/character.ts @@ -5,7 +5,7 @@ import { BookReader, BookReaderT } from './book-reader'; import { Rapunzel, RapunzelT } from './rapunzel'; -export enum Character{ +export enum Character { NONE = 0, MuLan = 1, Rapunzel = 2, diff --git a/tests/union_vector/falling-tub.ts b/tests/union_vector/falling-tub.ts index 3a836b36651..b32f99d0ff4 100644 --- a/tests/union_vector/falling-tub.ts +++ b/tests/union_vector/falling-tub.ts @@ -7,7 +7,7 @@ import * as flatbuffers from 'flatbuffers'; export class FallingTub { bb: flatbuffers.ByteBuffer|null = null; bb_pos = 0; -__init(i:number, bb:flatbuffers.ByteBuffer):FallingTub { + __init(i:number, bb:flatbuffers.ByteBuffer):FallingTub { this.bb_pos = i; this.bb = bb; return this; diff --git a/tests/union_vector/gadget.ts b/tests/union_vector/gadget.ts index 4d84b0afbcf..12a766610c8 100644 --- a/tests/union_vector/gadget.ts +++ b/tests/union_vector/gadget.ts @@ -4,7 +4,7 @@ import { FallingTub, FallingTubT } from './falling-tub'; import { HandFan, HandFanT } from './hand-fan'; -export enum Gadget{ +export enum Gadget { NONE = 0, FallingTub = 1, HandFan = 2 diff --git a/tests/union_vector/hand-fan.ts b/tests/union_vector/hand-fan.ts index 4a770bae19b..f90b4dd3195 100644 --- a/tests/union_vector/hand-fan.ts +++ b/tests/union_vector/hand-fan.ts @@ -7,7 +7,7 @@ import * as flatbuffers from 'flatbuffers'; export class HandFan { bb: flatbuffers.ByteBuffer|null = null; bb_pos = 0; -__init(i:number, bb:flatbuffers.ByteBuffer):HandFan { + __init(i:number, bb:flatbuffers.ByteBuffer):HandFan { this.bb_pos = i; this.bb = bb; return this; diff --git a/tests/union_vector/movie.ts b/tests/union_vector/movie.ts index b3e83819410..fceadaa2977 100644 --- a/tests/union_vector/movie.ts +++ b/tests/union_vector/movie.ts @@ -11,7 +11,7 @@ import { Rapunzel, RapunzelT } from './rapunzel'; export class Movie { bb: flatbuffers.ByteBuffer|null = null; bb_pos = 0; -__init(i:number, bb:flatbuffers.ByteBuffer):Movie { + __init(i:number, bb:flatbuffers.ByteBuffer):Movie { this.bb_pos = i; this.bb = bb; return this; diff --git a/tests/union_vector/rapunzel.ts b/tests/union_vector/rapunzel.ts index 28f6e99956e..e1dc63ddf54 100644 --- a/tests/union_vector/rapunzel.ts +++ b/tests/union_vector/rapunzel.ts @@ -7,7 +7,7 @@ import * as flatbuffers from 'flatbuffers'; export class Rapunzel { bb: flatbuffers.ByteBuffer|null = null; bb_pos = 0; -__init(i:number, bb:flatbuffers.ByteBuffer):Rapunzel { + __init(i:number, bb:flatbuffers.ByteBuffer):Rapunzel { this.bb_pos = i; this.bb = bb; return this; diff --git a/tests/union_vector/union_vector_generated.ts b/tests/union_vector/union_vector_generated.ts index f3a118b7de0..d3b41c49545 100644 --- a/tests/union_vector/union_vector_generated.ts +++ b/tests/union_vector/union_vector_generated.ts @@ -1,3 +1,5 @@ +// automatically generated by the FlatBuffers compiler, do not modify + export { Attacker, AttackerT } from './attacker'; export { BookReader, BookReaderT } from './book-reader'; export { Character, unionToCharacter, unionListToCharacter } from './character';