From cc991a058b0636f3454166c76de7b664cf23a8f4 Mon Sep 17 00:00:00 2001 From: dcodeIO Date: Wed, 29 Nov 2017 02:16:51 +0100 Subject: [PATCH] CLI: Use correct safeProp in json-module target, see #956 --- cli/targets/json-module.js | 14 +++++++++++--- cli/util.js | 7 ------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/cli/targets/json-module.js b/cli/targets/json-module.js index eedf3cbeb..5255cd99c 100644 --- a/cli/targets/json-module.js +++ b/cli/targets/json-module.js @@ -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() { diff --git a/cli/util.js b/cli/util.js index dc6182eff..ffce1ed7e 100644 --- a/cli/util.js +++ b/cli/util.js @@ -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; - }); -};