From 4a49493e272f8481e5ef8cb4be83b7ba7150e579 Mon Sep 17 00:00:00 2001 From: James Gilles Date: Mon, 11 Jul 2016 01:13:47 -0400 Subject: [PATCH] js:add @namespace annotation to namespaces --- js/flatbuffers.js | 4 ++++ src/idl_gen_js.cpp | 2 +- tests/monster_test.bfbs | Bin 3152 -> 3224 bytes tests/monster_test_generated.js | 12 ++++++++---- .../namespace_test1_generated.js | 6 ++++-- .../namespace_test2_generated.js | 9 ++++++--- 6 files changed, 23 insertions(+), 10 deletions(-) diff --git a/js/flatbuffers.js b/js/flatbuffers.js index 6c3d15cc8..511c9a216 100644 --- a/js/flatbuffers.js +++ b/js/flatbuffers.js @@ -2,6 +2,10 @@ /// @addtogroup flatbuffers_javascript_api /// @{ /// @cond FLATBUFFERS_INTERNAL +/** + * @const + * @namespace + */ var flatbuffers = {}; /** diff --git a/src/idl_gen_js.cpp b/src/idl_gen_js.cpp index 32a06f1ef..d7c913e50 100644 --- a/src/idl_gen_js.cpp +++ b/src/idl_gen_js.cpp @@ -110,7 +110,7 @@ class JsGenerator : public BaseGenerator { std::string &exports = *exports_ptr; for (auto it = sorted_namespaces.begin(); it != sorted_namespaces.end(); it++) { - code += "/**\n * @const\n*/\n"; + code += "/**\n * @const\n * @namespace\n */\n"; if (it->find('.') == std::string::npos) { code += "var "; exports += "this." + *it + " = " + *it + ";\n"; diff --git a/tests/monster_test.bfbs b/tests/monster_test.bfbs index e131ac8c2ee97914bfc1c02ce683ac4f5ecb43d6..1e8a270d80bc66233cbd38f18dda3bfa19d2e67e 100644 GIT binary patch literal 3224 zcmaJ@O-Ni<6h5P)&Wz(v>@=Asw%8(NC=wDQK_rXRqDezE5^d_L@^s$Rk(oEc{D@{5 zLXlER7ZO5NC1g=b*TrQhp#;gQWYt9%!G&byqCciTzJA|5?>?VG`{a1vz4trke&^hC z&YOM_8J`@V#ek<4g{g{HZ@4w=q>Qg=Z~!fH<}P@F zZun4t&aF3Qi`1QS7EA8O#m4f4*DPZv1)Vr}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dId1>_J+Ykdja{Nep} z-*rlD(4U0f6ssZnzXH0~$Ui%SWzF#JNj>I^zECHp_tZLv^+f3yfS0X|o6pRn(;?dZ ZvtkN#{13eqV_b)o{C-fc>2D+E{{r&+C1U^p diff --git a/tests/monster_test_generated.js b/tests/monster_test_generated.js index f67e84802..7c4c28f82 100644 --- a/tests/monster_test_generated.js +++ b/tests/monster_test_generated.js @@ -2,22 +2,26 @@ /** * @const -*/ + * @namespace + */ var MyGame = MyGame || {}; /** * @const -*/ + * @namespace + */ MyGame.Example = MyGame.Example || {}; /** * @const -*/ + * @namespace + */ MyGame.Example2 = MyGame.Example2 || {}; /** * @const -*/ + * @namespace + */ MyGame.OtherNameSpace = MyGame.OtherNameSpace || {}; /** diff --git a/tests/namespace_test/namespace_test1_generated.js b/tests/namespace_test/namespace_test1_generated.js index 769b523e3..e6390567f 100644 --- a/tests/namespace_test/namespace_test1_generated.js +++ b/tests/namespace_test/namespace_test1_generated.js @@ -2,12 +2,14 @@ /** * @const -*/ + * @namespace + */ var NamespaceA = NamespaceA || {}; /** * @const -*/ + * @namespace + */ NamespaceA.NamespaceB = NamespaceA.NamespaceB || {}; /** diff --git a/tests/namespace_test/namespace_test2_generated.js b/tests/namespace_test/namespace_test2_generated.js index c1953705e..f76d5a95a 100644 --- a/tests/namespace_test/namespace_test2_generated.js +++ b/tests/namespace_test/namespace_test2_generated.js @@ -2,17 +2,20 @@ /** * @const -*/ + * @namespace + */ var NamespaceA = NamespaceA || {}; /** * @const -*/ + * @namespace + */ NamespaceA.NamespaceB = NamespaceA.NamespaceB || {}; /** * @const -*/ + * @namespace + */ var NamespaceC = NamespaceC || {}; /**