Skip to content

Commit 8de21e1

Browse files
committed
CLI: $Properties are just a type that's satisfied, not implemented, by classes, see #723
1 parent fff1eb2 commit 8de21e1

File tree

11 files changed

+413
-208
lines changed

11 files changed

+413
-208
lines changed

cli/targets/static.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ function buildType(ref, type) {
299299
var typeDef = [
300300
"Properties of " + aOrAn(type.name) + ".",
301301
"@typedef " + fullName + "$Properties",
302-
"@type Object"
302+
"@type {Object}"
303303
];
304304
type.fieldsArray.forEach(function(field) {
305305
var jsType = toJsType(field),
@@ -317,7 +317,6 @@ function buildType(ref, type) {
317317
"Constructs a new " + type.name + ".",
318318
type.comment ? "@classdesc " + type.comment : null,
319319
"@exports " + fullName,
320-
"@implements " + fullName + "$Properties",
321320
"@constructor",
322321
"@param {" + fullName + "$Properties=} [" + (config.beautify ? "properties" : "p") + "] Properties to set"
323322
]);
@@ -331,6 +330,7 @@ function buildType(ref, type) {
331330
if (config.comments) {
332331
push("");
333332
pushComment([
333+
field.comment || type.name + " " + field.name + ".",
334334
"@type {" + toJsType(field) + (field.optional ? "|undefined" : "") + "}"
335335
]);
336336
} else if (firstField) {

index.d.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ export class Method extends ReflectionObject {
848848

849849
/**
850850
* Converts this method to a method descriptor.
851-
* @returns {MethodDescriptor}
851+
* @returns {MethodDescriptor} Method descriptor
852852
*/
853853
public toJSON(): MethodDescriptor;
854854
}
@@ -2384,6 +2384,14 @@ export namespace util {
23842384
*/
23852385
function isObject(value: any): boolean;
23862386

2387+
/**
2388+
* Checks if a property on a message is considered to be present.
2389+
* @param {Object} obj Plain object or message instance
2390+
* @param {string} prop Property name
2391+
* @returns {boolean} `true` if considered to be present, otherwise `false`
2392+
*/
2393+
function isset(obj: Object, prop: string): boolean;
2394+
23872395
/**
23882396
* Node's Buffer class if available.
23892397
* @type {?function(new: Buffer)}

lib/tsd-jsdoc/publish.js

+14-7
Original file line numberDiff line numberDiff line change
@@ -304,16 +304,19 @@ function writeInterface(element) {
304304
function writeInterfaceBody(element) {
305305
writeln("{");
306306
++indent;
307-
element.properties.forEach(function(property) {
308-
write(property.name);
309-
if (property.optional)
310-
write("?");
311-
writeln(": ", getTypeOf(property), ";");
312-
});
307+
element.properties.forEach(writeProperty);
313308
--indent;
314309
write("}");
315310
}
316311

312+
function writeProperty(property) {
313+
writeComment(property.comment);
314+
write(property.name);
315+
if (property.optional)
316+
write("?");
317+
writeln(": ", getTypeOf(property), ";");
318+
}
319+
317320
//
318321
// Handlers
319322
//
@@ -418,9 +421,13 @@ function handleClass(element, parent) {
418421
++indent;
419422

420423
// constructor
421-
if (!is_interface && !element.virtual)
424+
if (!is_interface && !element.virtual)
422425
handleFunction(element, parent, true);
423426

427+
// properties
428+
if (is_interface && element.properties)
429+
element.properties.forEach(writeProperty);
430+
424431
// class-compatible members
425432
var incompatible = [];
426433
getChildrenOf(element).forEach(function(child) {

tests/data/comments.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ $root.Test1 = (function() {
1414
/**
1515
* Properties of a Test1.
1616
* @typedef Test1$Properties
17-
* @type Object
17+
* @type {Object}
1818
* @property {string} [field1] Field with a comment.
1919
* @property {number} [field2] Test1 field2.
2020
* @property {boolean} [field3] Field with a comment and a <a href="http://example.com/foo/">link</a>
@@ -27,7 +27,6 @@ $root.Test1 = (function() {
2727
* a
2828
* comment.
2929
* @exports Test1
30-
* @implements Test1$Properties
3130
* @constructor
3231
* @param {Test1$Properties=} [properties] Properties to set
3332
*/
@@ -38,16 +37,19 @@ $root.Test1 = (function() {
3837
}
3938

4039
/**
40+
* Field with a comment.
4141
* @type {string|undefined}
4242
*/
4343
Test1.prototype.field1 = "";
4444

4545
/**
46+
* Test1 field2.
4647
* @type {number|undefined}
4748
*/
4849
Test1.prototype.field2 = 0;
4950

5051
/**
52+
* Field with a comment and a <a href="http://example.com/foo/">link</a>
5153
* @type {boolean|undefined}
5254
*/
5355
Test1.prototype.field3 = false;
@@ -230,13 +232,12 @@ $root.Test2 = (function() {
230232
/**
231233
* Properties of a Test2.
232234
* @typedef Test2$Properties
233-
* @type Object
235+
* @type {Object}
234236
*/
235237

236238
/**
237239
* Constructs a new Test2.
238240
* @exports Test2
239-
* @implements Test2$Properties
240241
* @constructor
241242
* @param {Test2$Properties=} [properties] Properties to set
242243
*/

tests/data/convert.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ $root.Message = (function() {
1414
/**
1515
* Properties of a Message.
1616
* @typedef Message$Properties
17-
* @type Object
17+
* @type {Object}
1818
* @property {string} [stringVal] Message stringVal.
1919
* @property {Array.<string>} [stringRepeated] Message stringRepeated.
2020
* @property {number|Long} [uint64Val] Message uint64Val.
@@ -29,7 +29,6 @@ $root.Message = (function() {
2929
/**
3030
* Constructs a new Message.
3131
* @exports Message
32-
* @implements Message$Properties
3332
* @constructor
3433
* @param {Message$Properties=} [properties] Properties to set
3534
*/
@@ -45,46 +44,55 @@ $root.Message = (function() {
4544
}
4645

4746
/**
47+
* Message stringVal.
4848
* @type {string|undefined}
4949
*/
5050
Message.prototype.stringVal = "";
5151

5252
/**
53+
* Message stringRepeated.
5354
* @type {Array.<string>|undefined}
5455
*/
5556
Message.prototype.stringRepeated = $util.emptyArray;
5657

5758
/**
59+
* Message uint64Val.
5860
* @type {number|Long|undefined}
5961
*/
6062
Message.prototype.uint64Val = $util.Long ? $util.Long.fromBits(0,0,true) : 0;
6163

6264
/**
65+
* Message uint64Repeated.
6366
* @type {Array.<number|Long>|undefined}
6467
*/
6568
Message.prototype.uint64Repeated = $util.emptyArray;
6669

6770
/**
71+
* Message bytesVal.
6872
* @type {Uint8Array|undefined}
6973
*/
7074
Message.prototype.bytesVal = $util.newBuffer([]);
7175

7276
/**
77+
* Message bytesRepeated.
7378
* @type {Array.<Uint8Array>|undefined}
7479
*/
7580
Message.prototype.bytesRepeated = $util.emptyArray;
7681

7782
/**
83+
* Message enumVal.
7884
* @type {Message.SomeEnum|undefined}
7985
*/
8086
Message.prototype.enumVal = 1;
8187

8288
/**
89+
* Message enumRepeated.
8390
* @type {Array.<Message.SomeEnum>|undefined}
8491
*/
8592
Message.prototype.enumRepeated = $util.emptyArray;
8693

8794
/**
95+
* Message int64Map.
8896
* @type {Object.<string,number|Long>|undefined}
8997
*/
9098
Message.prototype.int64Map = $util.emptyObject;
@@ -212,7 +220,7 @@ $root.Message = (function() {
212220
message.int64Map = {};
213221
key = reader.string();
214222
reader.pos++;
215-
message.int64Map[typeof key === "object" ? $util.longToHash(key) : key] = reader.int64();
223+
message.int64Map[key] = reader.int64();
216224
break;
217225
default:
218226
reader.skipType(tag & 7);

0 commit comments

Comments
 (0)