Commit 52513076 authored by Wouter van Oortmerssen's avatar Wouter van Oortmerssen

Merge pull request #257 from evanw/javascript

Add support for JavaScript code generation with Google Closure Compiler type annotations
parents d890ef9e 4bef5e89
...@@ -44,6 +44,8 @@ snapshot.sh ...@@ -44,6 +44,8 @@ snapshot.sh
tests/go_gen tests/go_gen
tests/monsterdata_java_wire.mon tests/monsterdata_java_wire.mon
tests/monsterdata_go_wire.mon tests/monsterdata_go_wire.mon
tests/monsterdata_javascript_wire.mon
tests/unicode_test.mon
CMakeLists.txt.user CMakeLists.txt.user
CMakeScripts/** CMakeScripts/**
CTestTestfile.cmake CTestTestfile.cmake
...@@ -55,4 +57,4 @@ java/.idea ...@@ -55,4 +57,4 @@ java/.idea
java/*.iml java/*.iml
java/target java/target
**/*.pyc **/*.pyc
.idea .idea
\ No newline at end of file
...@@ -33,6 +33,7 @@ set(FlatBuffers_Compiler_SRCS ...@@ -33,6 +33,7 @@ set(FlatBuffers_Compiler_SRCS
src/idl_gen_cpp.cpp src/idl_gen_cpp.cpp
src/idl_gen_general.cpp src/idl_gen_general.cpp
src/idl_gen_go.cpp src/idl_gen_go.cpp
src/idl_gen_js.cpp
src/idl_gen_python.cpp src/idl_gen_python.cpp
src/idl_gen_fbs.cpp src/idl_gen_fbs.cpp
src/flatc.cpp src/flatc.cpp
......
...@@ -449,6 +449,7 @@ extern void GenComment(const std::vector<std::string> &dc, ...@@ -449,6 +449,7 @@ extern void GenComment(const std::vector<std::string> &dc,
// Container of options that may apply to any of the source/text generators. // Container of options that may apply to any of the source/text generators.
struct GeneratorOptions { struct GeneratorOptions {
bool strict_json; bool strict_json;
bool skip_js_exports;
bool output_default_scalars_in_json; bool output_default_scalars_in_json;
int indent_step; int indent_step;
bool output_enum_identifiers; bool output_enum_identifiers;
...@@ -464,6 +465,7 @@ struct GeneratorOptions { ...@@ -464,6 +465,7 @@ struct GeneratorOptions {
Language lang; Language lang;
GeneratorOptions() : strict_json(false), GeneratorOptions() : strict_json(false),
skip_js_exports(false),
output_default_scalars_in_json(false), output_default_scalars_in_json(false),
indent_step(2), indent_step(2),
output_enum_identifiers(true), prefixed_enums(true), scoped_enums(false), output_enum_identifiers(true), prefixed_enums(true), scoped_enums(false),
...@@ -506,6 +508,15 @@ extern bool GenerateCPP(const Parser &parser, ...@@ -506,6 +508,15 @@ extern bool GenerateCPP(const Parser &parser,
const std::string &file_name, const std::string &file_name,
const GeneratorOptions &opts); const GeneratorOptions &opts);
// Generate JavaScript code from the definitions in the Parser object.
// See idl_gen_js.
extern std::string GenerateJS(const Parser &parser,
const GeneratorOptions &opts);
extern bool GenerateJS(const Parser &parser,
const std::string &path,
const std::string &file_name,
const GeneratorOptions &opts);
// Generate Go files from the definitions in the Parser object. // Generate Go files from the definitions in the Parser object.
// See idl_gen_go.cpp. // See idl_gen_go.cpp.
extern bool GenerateGo(const Parser &parser, extern bool GenerateGo(const Parser &parser,
...@@ -551,6 +562,13 @@ extern bool GenerateFBS(const Parser &parser, ...@@ -551,6 +562,13 @@ extern bool GenerateFBS(const Parser &parser,
const std::string &file_name, const std::string &file_name,
const GeneratorOptions &opts); const GeneratorOptions &opts);
// Generate a make rule for the generated JavaScript code.
// See idl_gen_js.cpp.
extern std::string JSMakeRule(const Parser &parser,
const std::string &path,
const std::string &file_name,
const GeneratorOptions &opts);
// Generate a make rule for the generated C++ header. // Generate a make rule for the generated C++ header.
// See idl_gen_cpp.cpp. // See idl_gen_cpp.cpp.
extern std::string CPPMakeRule(const Parser &parser, extern std::string CPPMakeRule(const Parser &parser,
......
This diff is collapsed.
...@@ -60,6 +60,10 @@ const Generator generators[] = { ...@@ -60,6 +60,10 @@ const Generator generators[] = {
flatbuffers::GeneratorOptions::kJava, flatbuffers::GeneratorOptions::kJava,
"Generate Java classes for tables/structs", "Generate Java classes for tables/structs",
flatbuffers::GeneralMakeRule }, flatbuffers::GeneralMakeRule },
{ flatbuffers::GenerateJS, "-s", "JavaScript",
flatbuffers::GeneratorOptions::kMAX,
"Generate JavaScript code for tables/structs",
flatbuffers::JSMakeRule },
{ flatbuffers::GenerateGeneral, "-n", "C#", { flatbuffers::GenerateGeneral, "-n", "C#",
flatbuffers::GeneratorOptions::kCSharp, flatbuffers::GeneratorOptions::kCSharp,
"Generate C# classes for tables/structs", "Generate C# classes for tables/structs",
...@@ -140,6 +144,8 @@ int main(int argc, const char *argv[]) { ...@@ -140,6 +144,8 @@ int main(int argc, const char *argv[]) {
include_directories.push_back(argv[argi]); include_directories.push_back(argv[argi]);
} else if(arg == "--strict-json") { } else if(arg == "--strict-json") {
opts.strict_json = true; opts.strict_json = true;
} else if(arg == "--no-js-exports") {
opts.skip_js_exports = true;
} else if(arg == "--defaults-json") { } else if(arg == "--defaults-json") {
opts.output_default_scalars_in_json = true; opts.output_default_scalars_in_json = true;
} else if(arg == "--no-prefix") { } else if(arg == "--no-prefix") {
......
This diff is collapsed.
This diff is collapsed.
#!/bin/sh
pushd "$(dirname $0)" >/dev/null
../flatc -b monster_test.fbs unicode_test.json
node JavaScriptTest
../flatc -c -j -n -g -b -p --gen-mutable --no-includes monster_test.fbs monsterdata_test.json ../flatc -c -j -n -g -b -p -s --gen-mutable --no-includes monster_test.fbs monsterdata_test.json
../flatc -b --schema monster_test.fbs ../flatc -b --schema monster_test.fbs
No preview for this file type
This diff is collapsed.
{
"name": "unicode_test",
"testarrayoftables": [
{ "name": "Цлїςσδε" },
{ "name": "フムアムカモケモ" },
{ "name": "フムヤムカモケモ" },
{ "name": "㊀㊁㊂㊃㊄" },
{ "name": "☳☶☲" },
{ "name": "𡇙𝌆" }
],
"testarrayofstring": [
"Цлїςσδε",
"フムアムカモケモ",
"フムヤムカモケモ",
"㊀㊁㊂㊃㊄",
"☳☶☲",
"𡇙𝌆"
]
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment