Skip to content

Commit 6aae71f

Browse files
committed
CLI: Keep $Properties with --strict-message but require actual instances within, see protobufjs#741
1 parent c812cef commit 6aae71f

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

cli/pbjs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ exports.main = function main(args, callback) {
110110
" --no-delimited Does not generate delimited encode/decode functions.",
111111
" --no-beautify Does not beautify generated code.",
112112
" --no-comments Does not output any JSDoc comments.",
113-
" --strict-long Forces s-/u-/int64 and s-/fixed64 types to 'Long' only (no numbers).",
114-
" --strict-message Forces message types to actual instances (no plain objects).",
113+
" --strict-long Strictly references 'Long' for s-/u-/int64 and s-/fixed64 types.",
114+
" --strict-message Strictly references message types instead of typedefs.",
115115
"",
116116
"usage: " + chalk.bold.green("pbjs") + " [options] file1.proto file2.json ..." + chalk.gray(" (or) ") + "other | " + chalk.bold.green("pbjs") + " [options] -",
117117
""

cli/targets/static.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ function toJsType(field) {
328328
if (field.resolve().resolvedType instanceof Enum)
329329
type = field.resolvedType.fullName.substring(1); // reference the enum
330330
else if (field.resolvedType instanceof Type)
331-
type = messageRef(field.resolvedType.fullName.substring(1)); // reference the interface
331+
type = field.resolvedType.fullName.substring(1) + (config["strict-message"] ? "" : "$Properties"); // reference the typedef
332332
else
333333
type = "*"; // should not happen
334334
break;
@@ -338,19 +338,13 @@ function toJsType(field) {
338338
: type;
339339
}
340340

341-
function messageRef(fullName) {
342-
return config["strict-message"] || !config.comments
343-
? fullName
344-
: fullName + "$Properties";
345-
}
346-
347341
function buildType(ref, type) {
348342
var fullName = type.fullName.substring(1);
349343

350-
if (config.comments && !config["strict-message"]) {
344+
if (config.comments) {
351345
var typeDef = [
352346
"Properties of " + aOrAn(type.name) + ".",
353-
"@typedef " + messageRef(fullName),
347+
"@typedef " + fullName + "$Properties",
354348
"@type {Object}"
355349
];
356350
type.fieldsArray.forEach(function(field) {
@@ -369,7 +363,7 @@ function buildType(ref, type) {
369363
type.comment ? "@classdesc " + type.comment : null,
370364
"@exports " + fullName,
371365
"@constructor",
372-
"@param {" + messageRef(fullName) + "=} [" + (config.beautify ? "properties" : "p") + "] Properties to set"
366+
"@param {" + fullName + "$Properties=} [" + (config.beautify ? "properties" : "p") + "] Properties to set"
373367
]);
374368
buildFunction(type, type.name, Class.generate(type));
375369

@@ -433,7 +427,7 @@ function buildType(ref, type) {
433427
push("");
434428
pushComment([
435429
"Creates a new " + type.name + " instance using the specified properties.",
436-
"@param {" + messageRef(fullName) + "=} [properties] Properties to set",
430+
"@param {" + fullName + "$Properties=} [properties] Properties to set",
437431
"@returns {" + fullName + "} " + type.name + " instance"
438432
]);
439433
push(name(type.name) + ".create = function create(properties) {");
@@ -447,7 +441,7 @@ function buildType(ref, type) {
447441
push("");
448442
pushComment([
449443
"Encodes the specified " + type.name + " message. Does not implicitly {@link " + fullName + ".verify|verify} messages.",
450-
"@param {" + messageRef(fullName) + "} " + (config.beautify ? "message" : "m") + " " + type.name + " message or plain object to encode",
444+
"@param {" + fullName + (config["strict-message"] ? "" : "$Properties") + "} " + (config.beautify ? "message" : "m") + " " + type.name + " message or plain object to encode",
451445
"@param {$protobuf.Writer} [" + (config.beautify ? "writer" : "w") + "] Writer to encode to",
452446
"@returns {$protobuf.Writer} Writer"
453447
]);
@@ -457,7 +451,7 @@ function buildType(ref, type) {
457451
push("");
458452
pushComment([
459453
"Encodes the specified " + type.name + " message, length delimited. Does not implicitly {@link " + fullName + ".verify|verify} messages.",
460-
"@param {" + messageRef(fullName) + "} message " + type.name + " message or plain object to encode",
454+
"@param {" + fullName + (config["strict-message"] ? "" : "$Properties") + "} message " + type.name + " message or plain object to encode",
461455
"@param {$protobuf.Writer} [writer] Writer to encode to",
462456
"@returns {$protobuf.Writer} Writer"
463457
]);

0 commit comments

Comments
 (0)