[TS/JS] New gen TS code gen (#6302)

* TS/ES6 modules spike iteration 1

* Initial modularized dasherized output

* Remove obsoleted parts and namespace wrapping

* Use _flatbuffers_ prefix

* First part of imports logic

* Second part of imports logic

* Fix TS/JS code removal mixup

* Alias imported symbols if same name from different namespaces and some fixes

* Use star import for bare imports

* Fix messed up string concat

* var to const and remove not needed semi

* Remove some cases of ns prefixing

* Add missing space

* Cleanups

* Completed initial import tracking logic

* Compilable output

* Adjust TypeScriptTest and dependents to work

* Use local flatbuffers package for tests

* Refactor away use of any

* Remove obsolete imported_fileset and reexport_map

* Still need any and fix JavaScriptTest.sh

* Fix test runs out of the box

* Temp add generated files

* TypeScriptTest replaces JavaScriptTest and cleanups

* Also remove reference to JavaScriptTest in TestAll.sh

* Remove old generated ts/js files

* Remove use of --js in generate_code scripts

* idl_gen_js_ts to idl_gen_ts and removal of js gen

* Remove obsoleted options

* Fix obsolete ts test detection

* Tweak ts compilation be as strict as possible

* Remove jsdoc type annotation generation

* Generated test ts files

* Fix search and replace messup

* Regenerated ts test output

* Use CharToLower

* Use normal for loop

* Rework namespacedir

* Revert "Rework namespacedir"

This reverts commit 6f4eb0104ceeb86011bb076ebca901138c48e068.

* Revert "Use normal for loop"

This reverts commit 676b2135bfaa1853dfbb06c92b5c16a0d81bb13a.

* Revert "Use CharToLower"

This reverts commit 2d08648d0d72d0af201fad80d54cdc76412b35e9.

* Again do rework but correct

* Avoid runtime cast

* Fix test runs

* Also add npm install to get tsc

* Bump node test versions

* for range to std for loop

* Clang format

* Missed one clang format

* Move accessor to later

* Attempt to make windows version of TypeScriptTest

* Want to see the output

* Try to get newer node at appveyor

* Style changes
This commit is contained in:
Björn Harrtell
2021-01-19 21:51:13 +01:00
committed by GitHub
parent 75c859e98f
commit 760c657551
56 changed files with 3870 additions and 4035 deletions

View File

@@ -94,7 +94,10 @@ class BaseGenerator {
virtual bool generate() = 0;
static std::string NamespaceDir(const Parser &parser, const std::string &path,
const Namespace &ns);
const Namespace &ns,
const bool dasherize = false);
static std::string ToDasherizedCase(const std::string pascal_case);
std::string GeneratedFileName(const std::string &path,
const std::string &file_name,
@@ -116,7 +119,8 @@ class BaseGenerator {
BaseGenerator &operator=(const BaseGenerator &);
BaseGenerator(const BaseGenerator &);
std::string NamespaceDir(const Namespace &ns) const;
std::string NamespaceDir(const Namespace &ns,
const bool dasherize = false) const;
static const char *FlatBuffersGeneratedWarning();

View File

@@ -521,9 +521,6 @@ struct IDLOptions {
// Use flexbuffers instead for binary and text generation
bool use_flexbuffers;
bool strict_json;
bool skip_js_exports;
bool use_goog_js_export_format;
bool use_ES6_js_export_format;
bool output_default_scalars_in_json;
int indent_step;
bool output_enum_identifiers;
@@ -556,11 +553,8 @@ struct IDLOptions {
bool binary_schema_comments;
bool binary_schema_builtins;
bool binary_schema_gen_embed;
bool skip_flatbuffers_import;
std::string go_import;
std::string go_namespace;
bool reexport_ts_modules;
bool js_ts_short_names;
bool protobuf_ascii_alike;
bool size_prefixed;
std::string root_type;
@@ -580,7 +574,6 @@ struct IDLOptions {
kCSharp = 1 << 1,
kGo = 1 << 2,
kCpp = 1 << 3,
kJs = 1 << 4,
kPython = 1 << 5,
kPhp = 1 << 6,
kJson = 1 << 7,
@@ -621,9 +614,6 @@ struct IDLOptions {
: gen_jvmstatic(false),
use_flexbuffers(false),
strict_json(false),
skip_js_exports(false),
use_goog_js_export_format(false),
use_ES6_js_export_format(false),
output_default_scalars_in_json(false),
indent_step(2),
output_enum_identifiers(true),
@@ -653,9 +643,6 @@ struct IDLOptions {
binary_schema_comments(false),
binary_schema_builtins(false),
binary_schema_gen_embed(false),
skip_flatbuffers_import(false),
reexport_ts_modules(true),
js_ts_short_names(false),
protobuf_ascii_alike(false),
size_prefixed(false),
force_defaults(false),
@@ -1054,8 +1041,8 @@ extern bool GenerateJava(const Parser &parser, const std::string &path,
// Generate JavaScript or TypeScript code from the definitions in the Parser
// object. See idl_gen_js.
extern bool GenerateJSTS(const Parser &parser, const std::string &path,
const std::string &file_name);
extern bool GenerateTS(const Parser &parser, const std::string &path,
const std::string &file_name);
// Generate Go files from the definitions in the Parser object.
// See idl_gen_go.cpp.
@@ -1107,10 +1094,10 @@ extern std::string GenerateFBS(const Parser &parser,
extern bool GenerateFBS(const Parser &parser, const std::string &path,
const std::string &file_name);
// Generate a make rule for the generated JavaScript or TypeScript code.
// See idl_gen_js.cpp.
extern std::string JSTSMakeRule(const Parser &parser, const std::string &path,
const std::string &file_name);
// Generate a make rule for the generated TypeScript code.
// See idl_gen_ts.cpp.
extern std::string TSMakeRule(const Parser &parser, const std::string &path,
const std::string &file_name);
// Generate a make rule for the generated C++ header.
// See idl_gen_cpp.cpp.
@@ -1169,7 +1156,7 @@ extern bool GenerateSwiftGRPC(const Parser &parser, const std::string &path,
const std::string &file_name);
extern bool GenerateTSGRPC(const Parser &parser, const std::string &path,
const std::string &file_name);
const std::string &file_name);
} // namespace flatbuffers
#endif // FLATBUFFERS_IDL_H_

View File

@@ -51,6 +51,9 @@ inline bool is_alpha(char c) {
return check_ascii_range(c & 0xDF, 'a' & 0xDF, 'z' & 0xDF);
}
// Check for uppercase alpha
inline bool is_alpha_upper(char c) { return check_ascii_range(c, 'A', 'Z'); }
// Check (case-insensitive) that `c` is equal to alpha.
inline bool is_alpha_char(char c, char alpha) {
FLATBUFFERS_ASSERT(is_alpha(alpha));