diff --git a/.vscode/settings.json b/.vscode/settings.json index c7c1623bc..801997075 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,4 @@ { - "typescript.tsdk": "./node_modules/typescript/lib" + "typescript.tsdk": "./node_modules/typescript/lib", + "vsicons.presets.angular": false } \ No newline at end of file diff --git a/cli/targets/static.js b/cli/targets/static.js index 2855972d1..72e8150eb 100644 --- a/cli/targets/static.js +++ b/cli/targets/static.js @@ -39,7 +39,8 @@ function static_target(root, options, callback) { else push("// Exported root namespace"); } - push("var $root = {};"); + var rootName = config.root || "default"; + push("var $root = $protobuf.roots[" + JSON.stringify(rootName) + "] || ($protobuf.roots[" + JSON.stringify(rootName) + "] = {});"); buildNamespace(null, root); push(""); if (config.comments) diff --git a/cli/util.js b/cli/util.js index 3445da6e6..aac97ceda 100644 --- a/cli/util.js +++ b/cli/util.js @@ -124,7 +124,6 @@ exports.wrap = function(OUTPUT, options) { // otherwise fetch the custom one wrap = fs.readFileSync(path.resolve(process.cwd(), name)).toString("utf8"); } - wrap = wrap.replace(/%ROOT%/g, JSON.stringify(options.root || "default")); wrap = wrap.replace(/%DEPENDENCY%/g, JSON.stringify(options.dependency || "protobufjs")); wrap = wrap.replace(/( *)%OUTPUT%/, function($0, $1) { return $1.length ? OUTPUT.replace(/^/mg, $1) : OUTPUT; diff --git a/cli/wrappers/amd.js b/cli/wrappers/amd.js index d0bcccc54..8fec983e0 100644 --- a/cli/wrappers/amd.js +++ b/cli/wrappers/amd.js @@ -3,5 +3,5 @@ define(["protobuf"], function($protobuf) { %OUTPUT% - return $protobuf.roots[%ROOT%] = $root; + return $root; }); diff --git a/cli/wrappers/commonjs.js b/cli/wrappers/commonjs.js index 6b5060d8d..02493a693 100644 --- a/cli/wrappers/commonjs.js +++ b/cli/wrappers/commonjs.js @@ -4,4 +4,4 @@ var $protobuf = require(%DEPENDENCY%); %OUTPUT% -module.exports = $protobuf.roots[%ROOT%] = $root; +module.exports = $root; diff --git a/cli/wrappers/default.js b/cli/wrappers/default.js index bccf8228c..cf5117ecd 100644 --- a/cli/wrappers/default.js +++ b/cli/wrappers/default.js @@ -11,5 +11,5 @@ %OUTPUT% - return $protobuf.roots[%ROOT%] = $root; + return $root; }); diff --git a/cli/wrappers/es6.js b/cli/wrappers/es6.js index 326ade151..9ad9ca111 100644 --- a/cli/wrappers/es6.js +++ b/cli/wrappers/es6.js @@ -2,6 +2,4 @@ import * as $protobuf from "protobufjs"; %OUTPUT% -$protobuf.roots[%ROOT%] = $root; - export { $root as default }; diff --git a/tests/data/comments.js b/tests/data/comments.js index f604ce9a4..1aa551bab 100644 --- a/tests/data/comments.js +++ b/tests/data/comments.js @@ -12,7 +12,7 @@ var $Reader = $protobuf.Reader, var $lazyTypes = []; // Exported root namespace -var $root = {}; +var $root = $protobuf.roots["test_comments"] || ($protobuf.roots["test_comments"] = {}); $root.Test1 = (function() { @@ -47,7 +47,7 @@ $root.Test1 = (function() { Test1.prototype.field2 = 0; /** - * Field with a comment. + * Field with a comment and a link * @type {boolean} */ Test1.prototype.field3 = false; @@ -377,4 +377,4 @@ $root.Test3 = (function() { // Resolve lazy type references to actual types $util.lazyResolve($root, $lazyTypes); -module.exports = $protobuf.roots["test_comments"] = $root; +module.exports = $root; diff --git a/tests/data/convert.js b/tests/data/convert.js index 1dcd5da8c..0db78f155 100644 --- a/tests/data/convert.js +++ b/tests/data/convert.js @@ -12,7 +12,7 @@ var $Reader = $protobuf.Reader, var $lazyTypes = []; // Exported root namespace -var $root = {}; +var $root = $protobuf.roots["test_convert"] || ($protobuf.roots["test_convert"] = {}); $root.Message = (function() { @@ -520,4 +520,4 @@ $root.Message = (function() { // Resolve lazy type references to actual types $util.lazyResolve($root, $lazyTypes); -module.exports = $protobuf.roots["test_convert"] = $root; +module.exports = $root; diff --git a/tests/data/mapbox/vector_tile.js b/tests/data/mapbox/vector_tile.js index 24bdc921d..3922cb3ef 100644 --- a/tests/data/mapbox/vector_tile.js +++ b/tests/data/mapbox/vector_tile.js @@ -12,7 +12,7 @@ var $Reader = $protobuf.Reader, var $lazyTypes = []; // Exported root namespace -var $root = {}; +var $root = $protobuf.roots["test_vector_tile"] || ($protobuf.roots["test_vector_tile"] = {}); $root.vector_tile = (function() { @@ -1182,4 +1182,4 @@ $root.vector_tile = (function() { // Resolve lazy type references to actual types $util.lazyResolve($root, $lazyTypes); -module.exports = $protobuf.roots["test_vector_tile"] = $root; +module.exports = $root; diff --git a/tests/data/package.js b/tests/data/package.js index b7d2da595..2fc23b254 100644 --- a/tests/data/package.js +++ b/tests/data/package.js @@ -12,7 +12,7 @@ var $Reader = $protobuf.Reader, var $lazyTypes = []; // Exported root namespace -var $root = {}; +var $root = $protobuf.roots["test_package"] || ($protobuf.roots["test_package"] = {}); $root.Package = (function() { @@ -824,4 +824,4 @@ $root.Package = (function() { // Resolve lazy type references to actual types $util.lazyResolve($root, $lazyTypes); -module.exports = $protobuf.roots["test_package"] = $root; +module.exports = $root; diff --git a/tests/data/rpc.js b/tests/data/rpc.js index a00166a49..0c13c3b16 100644 --- a/tests/data/rpc.js +++ b/tests/data/rpc.js @@ -12,7 +12,7 @@ var $Reader = $protobuf.Reader, var $lazyTypes = []; // Exported root namespace -var $root = {}; +var $root = $protobuf.roots["test_rpc"] || ($protobuf.roots["test_rpc"] = {}); $root.MyService = (function() { @@ -399,4 +399,4 @@ $root.MyResponse = (function() { // Resolve lazy type references to actual types $util.lazyResolve($root, $lazyTypes); -module.exports = $protobuf.roots["test_rpc"] = $root; +module.exports = $root; diff --git a/tests/data/test.js b/tests/data/test.js index 3144bc519..74779d323 100644 --- a/tests/data/test.js +++ b/tests/data/test.js @@ -12,7 +12,7 @@ var $Reader = $protobuf.Reader, var $lazyTypes = []; // Exported root namespace -var $root = {}; +var $root = $protobuf.roots["test_test"] || ($protobuf.roots["test_test"] = {}); $root.jspb = (function() { @@ -14121,4 +14121,4 @@ $root.google = (function() { // Resolve lazy type references to actual types $util.lazyResolve($root, $lazyTypes); -module.exports = $protobuf.roots["test_test"] = $root; +module.exports = $root;