Skip to content

Commit

Permalink
CLI: Use correct safeProp in json-module target, see #956
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Nov 29, 2017
1 parent d130b52 commit cc991a0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
14 changes: 11 additions & 3 deletions cli/targets/json-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,25 @@ var protobuf = require("../..");

json_module.description = "JSON representation as a module";

function jsonSafeProp(json) {
return json.replace(/^( +)"(\w+)":/mg, function($0, $1, $2) {
return protobuf.util.safeProp($2).charAt(0) === "."
? $1 + $2 + ":"
: $0;
});
}

function json_module(root, options, callback) {
try {
var rootProp = util.safeProp(options.root || "default");
var rootProp = protobuf.util.safeProp(options.root || "default");
var output = [
(options.es6 ? "const" : "var") + " $root = ($protobuf.roots" + rootProp + " || ($protobuf.roots" + rootProp + " = new $protobuf.Root()))\n"
];
if (root.options) {
var optionsJson = util.jsonSafeProp(JSON.stringify(root.options, null, 2));
var optionsJson = jsonSafeProp(JSON.stringify(root.options, null, 2));
output.push(".setOptions(" + optionsJson + ")\n");
}
var json = util.jsonSafeProp(JSON.stringify(root.nested, null, 2).trim());
var json = jsonSafeProp(JSON.stringify(root.nested, null, 2).trim());
output.push(".addJSON(" + json + ");");
output = util.wrap(output.join(""), protobuf.util.merge({ dependency: "protobufjs/light" }, options));
process.nextTick(function() {
Expand Down
7 changes: 0 additions & 7 deletions cli/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,3 @@ exports.pad = function(str, len, l) {
return str;
};

exports.jsonSafeProp = function(json) {
return json.replace(/^( +)"(\w+)":/mg, function($0, $1, $2) {
return exports.safeProp($2).charAt(0) === "."
? $1 + $2 + ":"
: $0;
});
};

0 comments on commit cc991a0

Please sign in to comment.