Skip to content

Commit

Permalink
CLI: $Properties are just a type that's satisfied, not implemented, b…
Browse files Browse the repository at this point in the history
…y classes, see #723
  • Loading branch information
dcodeIO committed Mar 26, 2017
1 parent fff1eb2 commit 8de21e1
Show file tree
Hide file tree
Showing 11 changed files with 413 additions and 208 deletions.
4 changes: 2 additions & 2 deletions cli/targets/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ function buildType(ref, type) {
var typeDef = [
"Properties of " + aOrAn(type.name) + ".",
"@typedef " + fullName + "$Properties",
"@type Object"
"@type {Object}"
];
type.fieldsArray.forEach(function(field) {
var jsType = toJsType(field),
Expand All @@ -317,7 +317,6 @@ function buildType(ref, type) {
"Constructs a new " + type.name + ".",
type.comment ? "@classdesc " + type.comment : null,
"@exports " + fullName,
"@implements " + fullName + "$Properties",
"@constructor",
"@param {" + fullName + "$Properties=} [" + (config.beautify ? "properties" : "p") + "] Properties to set"
]);
Expand All @@ -331,6 +330,7 @@ function buildType(ref, type) {
if (config.comments) {
push("");
pushComment([
field.comment || type.name + " " + field.name + ".",
"@type {" + toJsType(field) + (field.optional ? "|undefined" : "") + "}"
]);
} else if (firstField) {
Expand Down
10 changes: 9 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ export class Method extends ReflectionObject {

/**
* Converts this method to a method descriptor.
* @returns {MethodDescriptor}
* @returns {MethodDescriptor} Method descriptor
*/
public toJSON(): MethodDescriptor;
}
Expand Down Expand Up @@ -2384,6 +2384,14 @@ export namespace util {
*/
function isObject(value: any): boolean;

/**
* Checks if a property on a message is considered to be present.
* @param {Object} obj Plain object or message instance
* @param {string} prop Property name
* @returns {boolean} `true` if considered to be present, otherwise `false`
*/
function isset(obj: Object, prop: string): boolean;

/**
* Node's Buffer class if available.
* @type {?function(new: Buffer)}
Expand Down
21 changes: 14 additions & 7 deletions lib/tsd-jsdoc/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,16 +304,19 @@ function writeInterface(element) {
function writeInterfaceBody(element) {
writeln("{");
++indent;
element.properties.forEach(function(property) {
write(property.name);
if (property.optional)
write("?");
writeln(": ", getTypeOf(property), ";");
});
element.properties.forEach(writeProperty);
--indent;
write("}");
}

function writeProperty(property) {
writeComment(property.comment);
write(property.name);
if (property.optional)
write("?");
writeln(": ", getTypeOf(property), ";");
}

//
// Handlers
//
Expand Down Expand Up @@ -418,9 +421,13 @@ function handleClass(element, parent) {
++indent;

// constructor
if (!is_interface && !element.virtual)
if (!is_interface && !element.virtual)
handleFunction(element, parent, true);

// properties
if (is_interface && element.properties)
element.properties.forEach(writeProperty);

// class-compatible members
var incompatible = [];
getChildrenOf(element).forEach(function(child) {
Expand Down
9 changes: 5 additions & 4 deletions tests/data/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ $root.Test1 = (function() {
/**
* Properties of a Test1.
* @typedef Test1$Properties
* @type Object
* @type {Object}
* @property {string} [field1] Field with a comment.
* @property {number} [field2] Test1 field2.
* @property {boolean} [field3] Field with a comment and a <a href="http://example.com/foo/">link</a>
Expand All @@ -27,7 +27,6 @@ $root.Test1 = (function() {
* a
* comment.
* @exports Test1
* @implements Test1$Properties
* @constructor
* @param {Test1$Properties=} [properties] Properties to set
*/
Expand All @@ -38,16 +37,19 @@ $root.Test1 = (function() {
}

/**
* Field with a comment.
* @type {string|undefined}
*/
Test1.prototype.field1 = "";

/**
* Test1 field2.
* @type {number|undefined}
*/
Test1.prototype.field2 = 0;

/**
* Field with a comment and a <a href="http://example.com/foo/">link</a>
* @type {boolean|undefined}
*/
Test1.prototype.field3 = false;
Expand Down Expand Up @@ -230,13 +232,12 @@ $root.Test2 = (function() {
/**
* Properties of a Test2.
* @typedef Test2$Properties
* @type Object
* @type {Object}
*/

/**
* Constructs a new Test2.
* @exports Test2
* @implements Test2$Properties
* @constructor
* @param {Test2$Properties=} [properties] Properties to set
*/
Expand Down
14 changes: 11 additions & 3 deletions tests/data/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ $root.Message = (function() {
/**
* Properties of a Message.
* @typedef Message$Properties
* @type Object
* @type {Object}
* @property {string} [stringVal] Message stringVal.
* @property {Array.<string>} [stringRepeated] Message stringRepeated.
* @property {number|Long} [uint64Val] Message uint64Val.
Expand All @@ -29,7 +29,6 @@ $root.Message = (function() {
/**
* Constructs a new Message.
* @exports Message
* @implements Message$Properties
* @constructor
* @param {Message$Properties=} [properties] Properties to set
*/
Expand All @@ -45,46 +44,55 @@ $root.Message = (function() {
}

/**
* Message stringVal.
* @type {string|undefined}
*/
Message.prototype.stringVal = "";

/**
* Message stringRepeated.
* @type {Array.<string>|undefined}
*/
Message.prototype.stringRepeated = $util.emptyArray;

/**
* Message uint64Val.
* @type {number|Long|undefined}
*/
Message.prototype.uint64Val = $util.Long ? $util.Long.fromBits(0,0,true) : 0;

/**
* Message uint64Repeated.
* @type {Array.<number|Long>|undefined}
*/
Message.prototype.uint64Repeated = $util.emptyArray;

/**
* Message bytesVal.
* @type {Uint8Array|undefined}
*/
Message.prototype.bytesVal = $util.newBuffer([]);

/**
* Message bytesRepeated.
* @type {Array.<Uint8Array>|undefined}
*/
Message.prototype.bytesRepeated = $util.emptyArray;

/**
* Message enumVal.
* @type {Message.SomeEnum|undefined}
*/
Message.prototype.enumVal = 1;

/**
* Message enumRepeated.
* @type {Array.<Message.SomeEnum>|undefined}
*/
Message.prototype.enumRepeated = $util.emptyArray;

/**
* Message int64Map.
* @type {Object.<string,number|Long>|undefined}
*/
Message.prototype.int64Map = $util.emptyObject;
Expand Down Expand Up @@ -212,7 +220,7 @@ $root.Message = (function() {
message.int64Map = {};
key = reader.string();
reader.pos++;
message.int64Map[typeof key === "object" ? $util.longToHash(key) : key] = reader.int64();
message.int64Map[key] = reader.int64();
break;
default:
reader.skipType(tag & 7);
Expand Down
Loading

0 comments on commit 8de21e1

Please sign in to comment.