Skip to content

Commit e1f9d98

Browse files
committed
Also be more verbose when defining properties for ES6, fixes #820
1 parent cf36097 commit e1f9d98

File tree

11 files changed

+1691
-272
lines changed

11 files changed

+1691
-272
lines changed

cli/targets/static.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,9 @@ function buildType(ref, type) {
394394
jsType = "(" + jsType + "|null)";
395395
pushComment([
396396
field.comment || type.name + " " + field.name + ".",
397+
"@member {" + jsType + "}" + escapeName(field.name),
397398
"@memberof " + exportName(type),
398-
"@instance",
399-
"@type {" + jsType + "}"
399+
"@instance"
400400
]);
401401
} else if (firstField) {
402402
push("");
@@ -432,10 +432,9 @@ function buildType(ref, type) {
432432
push("");
433433
pushComment([
434434
oneof.comment || type.name + " " + oneof.name + ".",
435-
"@property " + escapeName(oneof.name),
435+
"@member {string|undefined} " + escapeName(oneof.name),
436436
"@memberof " + exportName(type),
437-
"@instance",
438-
"@type {string|undefined}"
437+
"@instance"
439438
]);
440439
push("Object.defineProperty(" + escapeName(type.name) + ".prototype, " + JSON.stringify(oneof.name) +", {");
441440
++indent;
@@ -449,6 +448,7 @@ function buildType(ref, type) {
449448
push("");
450449
pushComment([
451450
"Creates a new " + type.name + " instance using the specified properties.",
451+
"@function create",
452452
"@memberof " + exportName(type),
453453
"@static",
454454
"@param {" + exportName(type, true) + "=} [properties] Properties to set",
@@ -465,6 +465,7 @@ function buildType(ref, type) {
465465
push("");
466466
pushComment([
467467
"Encodes the specified " + type.name + " message. Does not implicitly {@link " + exportName(type) + ".verify|verify} messages.",
468+
"@function encode",
468469
"@memberof " + exportName(type),
469470
"@static",
470471
"@param {" + exportName(type, !config.forceMessage) + "} " + (config.beautify ? "message" : "m") + " " + type.name + " message or plain object to encode",
@@ -477,6 +478,7 @@ function buildType(ref, type) {
477478
push("");
478479
pushComment([
479480
"Encodes the specified " + type.name + " message, length delimited. Does not implicitly {@link " + exportName(type) + ".verify|verify} messages.",
481+
"@function encodeDelimited",
480482
"@memberof " + exportName(type),
481483
"@static",
482484
"@param {" + exportName(type, !config.forceMessage) + "} message " + type.name + " message or plain object to encode",
@@ -495,6 +497,7 @@ function buildType(ref, type) {
495497
push("");
496498
pushComment([
497499
"Decodes " + aOrAn(type.name) + " message from the specified reader or buffer.",
500+
"@function decode",
498501
"@memberof " + exportName(type),
499502
"@static",
500503
"@param {$protobuf.Reader|Uint8Array} " + (config.beautify ? "reader" : "r") + " Reader or buffer to decode from",
@@ -509,6 +512,7 @@ function buildType(ref, type) {
509512
push("");
510513
pushComment([
511514
"Decodes " + aOrAn(type.name) + " message from the specified reader or buffer, length delimited.",
515+
"@function decodeDelimited",
512516
"@memberof " + exportName(type),
513517
"@static",
514518
"@param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from",
@@ -532,6 +536,7 @@ function buildType(ref, type) {
532536
push("");
533537
pushComment([
534538
"Verifies " + aOrAn(type.name) + " message.",
539+
"@function verify",
535540
"@memberof " + exportName(type),
536541
"@static",
537542
"@param {Object.<string,*>} " + (config.beautify ? "message" : "m") + " Plain object to verify",
@@ -544,6 +549,7 @@ function buildType(ref, type) {
544549
push("");
545550
pushComment([
546551
"Creates " + aOrAn(type.name) + " message from a plain object. Also converts values to their respective internal types.",
552+
"@function fromObject",
547553
"@memberof " + exportName(type),
548554
"@static",
549555
"@param {Object.<string,*>} " + (config.beautify ? "object" : "d") + " Plain object",
@@ -554,6 +560,7 @@ function buildType(ref, type) {
554560
push("");
555561
pushComment([
556562
"Creates a plain object from " + aOrAn(type.name) + " message. Also converts values to other types if specified.",
563+
"@function toObject",
557564
"@memberof " + exportName(type),
558565
"@static",
559566
"@param {" + exportName(type) + "} " + (config.beautify ? "message" : "m") + " " + type.name,
@@ -565,6 +572,7 @@ function buildType(ref, type) {
565572
push("");
566573
pushComment([
567574
"Converts this " + type.name + " to JSON.",
575+
"@function toJSON",
568576
"@memberof " + exportName(type),
569577
"@instance",
570578
"@returns {Object.<string,*>} JSON object"
@@ -602,6 +610,7 @@ function buildService(ref, service) {
602610
push("");
603611
pushComment([
604612
"Creates new " + service.name + " service using the specified rpc implementation.",
613+
"@function create",
605614
"@memberof " + exportName(service),
606615
"@static",
607616
"@param {$protobuf.RPCImpl} rpcImpl RPC implementation",
@@ -633,6 +642,7 @@ function buildService(ref, service) {
633642
push("");
634643
pushComment([
635644
method.comment || "Calls " + method.name + ".",
645+
"@function " + util.safeProp(lcName),
636646
"@memberof " + exportName(service),
637647
"@instance",
638648
"@param {" + exportName(method.resolvedRequestType, !config.forceMessage) + "} request " + method.resolvedRequestType.name + " message or plain object",

tests/data/comments.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,30 +39,31 @@ $root.Test1 = (function() {
3939

4040
/**
4141
* Field with a comment.
42+
* @member {string}field1
4243
* @memberof Test1
4344
* @instance
44-
* @type {string}
4545
*/
4646
Test1.prototype.field1 = "";
4747

4848
/**
4949
* Test1 field2.
50+
* @member {number}field2
5051
* @memberof Test1
5152
* @instance
52-
* @type {number}
5353
*/
5454
Test1.prototype.field2 = 0;
5555

5656
/**
5757
* Field with a comment and a <a href="http://example.com/foo/">link</a>
58+
* @member {boolean}field3
5859
* @memberof Test1
5960
* @instance
60-
* @type {boolean}
6161
*/
6262
Test1.prototype.field3 = false;
6363

6464
/**
6565
* Creates a new Test1 instance using the specified properties.
66+
* @function create
6667
* @memberof Test1
6768
* @static
6869
* @param {ITest1=} [properties] Properties to set
@@ -74,6 +75,7 @@ $root.Test1 = (function() {
7475

7576
/**
7677
* Encodes the specified Test1 message. Does not implicitly {@link Test1.verify|verify} messages.
78+
* @function encode
7779
* @memberof Test1
7880
* @static
7981
* @param {ITest1} message Test1 message or plain object to encode
@@ -94,6 +96,7 @@ $root.Test1 = (function() {
9496

9597
/**
9698
* Encodes the specified Test1 message, length delimited. Does not implicitly {@link Test1.verify|verify} messages.
99+
* @function encodeDelimited
97100
* @memberof Test1
98101
* @static
99102
* @param {ITest1} message Test1 message or plain object to encode
@@ -106,6 +109,7 @@ $root.Test1 = (function() {
106109

107110
/**
108111
* Decodes a Test1 message from the specified reader or buffer.
112+
* @function decode
109113
* @memberof Test1
110114
* @static
111115
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
@@ -140,6 +144,7 @@ $root.Test1 = (function() {
140144

141145
/**
142146
* Decodes a Test1 message from the specified reader or buffer, length delimited.
147+
* @function decodeDelimited
143148
* @memberof Test1
144149
* @static
145150
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
@@ -155,6 +160,7 @@ $root.Test1 = (function() {
155160

156161
/**
157162
* Verifies a Test1 message.
163+
* @function verify
158164
* @memberof Test1
159165
* @static
160166
* @param {Object.<string,*>} message Plain object to verify
@@ -177,6 +183,7 @@ $root.Test1 = (function() {
177183

178184
/**
179185
* Creates a Test1 message from a plain object. Also converts values to their respective internal types.
186+
* @function fromObject
180187
* @memberof Test1
181188
* @static
182189
* @param {Object.<string,*>} object Plain object
@@ -197,6 +204,7 @@ $root.Test1 = (function() {
197204

198205
/**
199206
* Creates a plain object from a Test1 message. Also converts values to other types if specified.
207+
* @function toObject
200208
* @memberof Test1
201209
* @static
202210
* @param {Test1} message Test1
@@ -223,6 +231,7 @@ $root.Test1 = (function() {
223231

224232
/**
225233
* Converts this Test1 to JSON.
234+
* @function toJSON
226235
* @memberof Test1
227236
* @instance
228237
* @returns {Object.<string,*>} JSON object
@@ -258,6 +267,7 @@ $root.Test2 = (function() {
258267

259268
/**
260269
* Creates a new Test2 instance using the specified properties.
270+
* @function create
261271
* @memberof Test2
262272
* @static
263273
* @param {ITest2=} [properties] Properties to set
@@ -269,6 +279,7 @@ $root.Test2 = (function() {
269279

270280
/**
271281
* Encodes the specified Test2 message. Does not implicitly {@link Test2.verify|verify} messages.
282+
* @function encode
272283
* @memberof Test2
273284
* @static
274285
* @param {ITest2} message Test2 message or plain object to encode
@@ -283,6 +294,7 @@ $root.Test2 = (function() {
283294

284295
/**
285296
* Encodes the specified Test2 message, length delimited. Does not implicitly {@link Test2.verify|verify} messages.
297+
* @function encodeDelimited
286298
* @memberof Test2
287299
* @static
288300
* @param {ITest2} message Test2 message or plain object to encode
@@ -295,6 +307,7 @@ $root.Test2 = (function() {
295307

296308
/**
297309
* Decodes a Test2 message from the specified reader or buffer.
310+
* @function decode
298311
* @memberof Test2
299312
* @static
300313
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
@@ -320,6 +333,7 @@ $root.Test2 = (function() {
320333

321334
/**
322335
* Decodes a Test2 message from the specified reader or buffer, length delimited.
336+
* @function decodeDelimited
323337
* @memberof Test2
324338
* @static
325339
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
@@ -335,6 +349,7 @@ $root.Test2 = (function() {
335349

336350
/**
337351
* Verifies a Test2 message.
352+
* @function verify
338353
* @memberof Test2
339354
* @static
340355
* @param {Object.<string,*>} message Plain object to verify
@@ -348,6 +363,7 @@ $root.Test2 = (function() {
348363

349364
/**
350365
* Creates a Test2 message from a plain object. Also converts values to their respective internal types.
366+
* @function fromObject
351367
* @memberof Test2
352368
* @static
353369
* @param {Object.<string,*>} object Plain object
@@ -361,6 +377,7 @@ $root.Test2 = (function() {
361377

362378
/**
363379
* Creates a plain object from a Test2 message. Also converts values to other types if specified.
380+
* @function toObject
364381
* @memberof Test2
365382
* @static
366383
* @param {Test2} message Test2
@@ -373,6 +390,7 @@ $root.Test2 = (function() {
373390

374391
/**
375392
* Converts this Test2 to JSON.
393+
* @function toJSON
376394
* @memberof Test2
377395
* @instance
378396
* @returns {Object.<string,*>} JSON object

0 commit comments

Comments
 (0)