Skip to content

Commit

Permalink
CLI: Keep $Properties with --strict-message but require actual instan…
Browse files Browse the repository at this point in the history
…ces within, see #741
  • Loading branch information
dcodeIO committed Apr 3, 2017
1 parent c812cef commit 6aae71f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
4 changes: 2 additions & 2 deletions cli/pbjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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] -",
""
Expand Down
20 changes: 7 additions & 13 deletions cli/targets/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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));

Expand Down Expand Up @@ -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) {");
Expand All @@ -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"
]);
Expand All @@ -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"
]);
Expand Down

0 comments on commit 6aae71f

Please sign in to comment.