diff --git a/cli/pbjs.js b/cli/pbjs.js index 6e991ffe3..2e79b0b48 100644 --- a/cli/pbjs.js +++ b/cli/pbjs.js @@ -110,8 +110,8 @@ exports.main = function main(args, callback) { " --no-delimited Does not generate delimited encode/decode functions.", " --no-beautify Does not beautify generated code.", " --no-comments Does not output any JSDoc comments.", - " --strict-long Forces s-/u-/int64 and s-/fixed64 types to 'Long' only (no numbers).", - " --strict-message Forces message types to actual instances (no plain objects).", + " --strict-long Strictly references 'Long' for s-/u-/int64 and s-/fixed64 types.", + " --strict-message Strictly references message types instead of typedefs.", "", "usage: " + chalk.bold.green("pbjs") + " [options] file1.proto file2.json ..." + chalk.gray(" (or) ") + "other | " + chalk.bold.green("pbjs") + " [options] -", "" diff --git a/cli/targets/static.js b/cli/targets/static.js index bbb813b06..7d29f8f2e 100644 --- a/cli/targets/static.js +++ b/cli/targets/static.js @@ -328,7 +328,7 @@ function toJsType(field) { if (field.resolve().resolvedType instanceof Enum) type = field.resolvedType.fullName.substring(1); // reference the enum else if (field.resolvedType instanceof Type) - type = messageRef(field.resolvedType.fullName.substring(1)); // reference the interface + type = field.resolvedType.fullName.substring(1) + (config["strict-message"] ? "" : "$Properties"); // reference the typedef else type = "*"; // should not happen break; @@ -338,19 +338,13 @@ function toJsType(field) { : type; } -function messageRef(fullName) { - return config["strict-message"] || !config.comments - ? fullName - : fullName + "$Properties"; -} - function buildType(ref, type) { var fullName = type.fullName.substring(1); - if (config.comments && !config["strict-message"]) { + if (config.comments) { var typeDef = [ "Properties of " + aOrAn(type.name) + ".", - "@typedef " + messageRef(fullName), + "@typedef " + fullName + "$Properties", "@type {Object}" ]; type.fieldsArray.forEach(function(field) { @@ -369,7 +363,7 @@ function buildType(ref, type) { type.comment ? "@classdesc " + type.comment : null, "@exports " + fullName, "@constructor", - "@param {" + messageRef(fullName) + "=} [" + (config.beautify ? "properties" : "p") + "] Properties to set" + "@param {" + fullName + "$Properties=} [" + (config.beautify ? "properties" : "p") + "] Properties to set" ]); buildFunction(type, type.name, Class.generate(type)); @@ -433,7 +427,7 @@ function buildType(ref, type) { push(""); pushComment([ "Creates a new " + type.name + " instance using the specified properties.", - "@param {" + messageRef(fullName) + "=} [properties] Properties to set", + "@param {" + fullName + "$Properties=} [properties] Properties to set", "@returns {" + fullName + "} " + type.name + " instance" ]); push(name(type.name) + ".create = function create(properties) {"); @@ -447,7 +441,7 @@ function buildType(ref, type) { push(""); pushComment([ "Encodes the specified " + type.name + " message. Does not implicitly {@link " + fullName + ".verify|verify} messages.", - "@param {" + messageRef(fullName) + "} " + (config.beautify ? "message" : "m") + " " + type.name + " message or plain object to encode", + "@param {" + fullName + (config["strict-message"] ? "" : "$Properties") + "} " + (config.beautify ? "message" : "m") + " " + type.name + " message or plain object to encode", "@param {$protobuf.Writer} [" + (config.beautify ? "writer" : "w") + "] Writer to encode to", "@returns {$protobuf.Writer} Writer" ]); @@ -457,7 +451,7 @@ function buildType(ref, type) { push(""); pushComment([ "Encodes the specified " + type.name + " message, length delimited. Does not implicitly {@link " + fullName + ".verify|verify} messages.", - "@param {" + messageRef(fullName) + "} message " + type.name + " message or plain object to encode", + "@param {" + fullName + (config["strict-message"] ? "" : "$Properties") + "} message " + type.name + " message or plain object to encode", "@param {$protobuf.Writer} [writer] Writer to encode to", "@returns {$protobuf.Writer} Writer" ]);