mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-03 12:21:23 +00:00
Javascript: Add suppport for ES6 style exports (#4754)
* Add suppport for ES6 style exports Adds support for ECMAScript 6 module exports during Javascript generation. This is useful as many development projects are switching to this new standard and away from custom module solutions. By integrating support into flatbuffers, users do not need to perform additional post-processing of generated files in order to use flatbuffers output directly in their codebases. Reference to ECMAScript 6 modules: https://www.ecma-international.org/ecma-262/6.0/#sec-exports Changes: * Added `--es6-js-export` option to cli parser tool * Added conditional code to generate a ES6 style export line, replacing the normal NodeJS/RequireJS line. * Fixed missing export statements Added exports for definition and struct names that were not inside namespaces * Updated Compiler.md with new generator option Added entry to Compiler.md in docs for the `--es6-js-export` flag, including a brief description of the effects and usefulness.
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
0848f58cdd
commit
b4ca4d3cde
@@ -97,6 +97,7 @@ std::string FlatCompiler::GetUsageString(const char *program_name) const {
|
||||
" Default value is \"T\"\n"
|
||||
" --no-js-exports Removes Node.js style export lines in JS.\n"
|
||||
" --goog-js-export Uses goog.exports* for closure compiler exporting in JS.\n"
|
||||
" --es6-js-export Uses ECMAScript 6 export style lines in JS.\n"
|
||||
" --go-namespace Generate the overrided namespace in Golang.\n"
|
||||
" --go-import Generate the overrided import for flatbuffers in Golang.\n"
|
||||
" (default is \"github.com/google/flatbuffers/go\")\n"
|
||||
@@ -191,6 +192,10 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
||||
opts.skip_js_exports = true;
|
||||
} else if (arg == "--goog-js-export") {
|
||||
opts.use_goog_js_export_format = true;
|
||||
opts.use_ES6_js_export_format = false;
|
||||
} else if (arg == "--es6-js-export") {
|
||||
opts.use_goog_js_export_format = false;
|
||||
opts.use_ES6_js_export_format = true;
|
||||
} else if (arg == "--go-namespace") {
|
||||
if (++argi >= argc) Error("missing golang namespace" + arg, true);
|
||||
opts.go_namespace = argv[argi];
|
||||
|
||||
Reference in New Issue
Block a user