Skip to content

Commit

Permalink
CLI: Relieved tsd files from unnecessary comments; CLI: Generate TS n…
Browse files Browse the repository at this point in the history
…amespaces for vars and functions with properties; Other: Regenerated dist files; Breaking: Removed Message#toObject in favor of having just the static version (unnecessary static code otherwise)
  • Loading branch information
dcodeIO committed Apr 16, 2017
1 parent c97b618 commit 22f907c
Show file tree
Hide file tree
Showing 32 changed files with 6,638 additions and 3,316 deletions.
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,48 @@
# [6.8.0](https://github.com/dcodeIO/protobuf.js/releases/tag/6.8.0)

## Breaking
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/c97b61811248df002f1fb93557b982bc0aa27309) Everything uses interfaces now instead of typedefs (SomethingProperties is now ISomething)<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/b9f179064f3ddf683f13e0d4e17840301be64010) ReflectionObject#toJSON properly omits explicit undefined values<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/7a6f98b5e74f9e9142f9be3ba0683caeaff916c4) Initial implementation of TypeScript decorators<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/7a6f98b5e74f9e9142f9be3ba0683caeaff916c4) Refactored protobuf.Class away<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/7a6f98b5e74f9e9142f9be3ba0683caeaff916c4) TypeScript definitions now have (a lot of) generics<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/7a6f98b5e74f9e9142f9be3ba0683caeaff916c4) Removed deprecated features<br />

## Fixed
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/0589ace4dc9e5c565ff996cf6e6bf94e63f43c4e) Types should not clear constructor with cache (fixes decorators)<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/056ecc3834a3b323aaaa676957efcbe3f52365a0) Namespace#lookup should also check in nested namespaces (wtf)<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/ed34b093839652db2ff7b84db87857fc57d96038) Reader#bytes should also support plain arrays<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/514afcfa890aa598e93254576c4fd6062e0eff3b) Fix markdown for pipe in code in table<br />

## New
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/57d7d35ddbb9e3a28c396b4ef1ae3b150eeb8035) ext/descriptor enables interoperability between reflection and descriptor.proto (experimental), see [#757](https://github.com/dcodeIO/protobuf.js/issues/757)<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/3939667ef1f37b025bd7f9476015890496d50e00) Added 'json' conversion option for proto3 JSON mapping compatibility of NaN and Infinity + additional documentation of util.toJSONOptions, see [#351](https://github.com/dcodeIO/protobuf.js/issues/351)<br />

## CLI
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/b355115e619c6595ac9d91897cfe628ef0e46054) Prefer @tstype over @type when generating typedefs (tsd-jsdoc)<br />

## Docs
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/6493f52013c92a34b8305a25068ec7b8c4c29d54) Added more info to ext/descriptor README, see [#757](https://github.com/dcodeIO/protobuf.js/issues/757)<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/ef92da3768d8746dbfe72e77232f78b879fc811d) Additional notes on ext/descriptor<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/b646cf7499791a41b75eef2de1a80fb558d4159e) Updated CHANGELOG so everyone knows what's going on (and soon, breaking)<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/35a663757efe188bea552aef017837bc6c6a481a) Additional docs on TS/decorators usage<br />

## Other
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/5bc3541d2da19e2857dc884f743d37c27e8e21f2) Even more documentation and typings for ext/descriptor<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/773e6347b57e4a5236b1ef0bb8d361e4b233caf7) ext/descriptor docs<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/773e6347b57e4a5236b1ef0bb8d361e4b233caf7) Decorators coverage<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/9a23ded94729ceeea2f87cb7e8460eaaaf1c8269) ext/descriptor support for various standard options, see [#757](https://github.com/dcodeIO/protobuf.js/issues/757)<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/2d8ce6ec0abd261f9b261a44a0a258fdf57ecec3) ext/descriptor passes descriptor.proto test with no differences, see [#757](https://github.com/dcodeIO/protobuf.js/issues/757)<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/3a20968c6d676312e4f2a510f7e079e0e0819daf) Properly remove unnecessary (packed) options from JSON descriptors<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/2a30df8bd5f20d91143a38c2232dafc3a6f3a7bd) Use typedefs in ext/descriptor (like everywhere else), see [#757](https://github.com/dcodeIO/protobuf.js/issues/757)<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/1fc911cef01e081c04fb82ead685f49dde1403bb) Fixed obvious issues with ext/descriptor, does not throw anymore when throwing descriptor.proto itself at it, see [#757](https://github.com/dcodeIO/protobuf.js/issues/757)<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/6c37dbd14f39dad687f2f89f1558a875f7dcc882) Added still missing root traversal to ext/descriptor, see [#757](https://github.com/dcodeIO/protobuf.js/issues/757)<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/7ab136daa5eb2769b616b6b7522e45a4e33a59f6) Initial map fields support for ext/descriptor, see [#757](https://github.com/dcodeIO/protobuf.js/issues/757)<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/708552bb84508364b6e6fdf73906aa69e83854e1) Added infrastructure for TypeScript support of extensions<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/23f26defa793b371c16b5f920fbacb3fb66bdf22) TypeScript generics improvements<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/e49bef863c0fb10257ec1001a3c5561755f2ec6b) More ext/descriptor progress, see [#757](https://github.com/dcodeIO/protobuf.js/issues/757)<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/6b94336c1e6eec0f2eb1bd5dca73a7a8e71a2153) Just export the relevant namespace in ext/descriptor<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/fbb99489ed0c095174feff8f53431d30fb6c34a0) Initial descriptor.proto extension for reflection interoperability, see [#757](https://github.com/dcodeIO/protobuf.js/issues/757)<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/48e66d975bf7b4e6bdbb68ec24386c98b16c54c5) Moved custom wrappers to its own module instead, also makes the API easier to use manually, see [#677](https://github.com/dcodeIO/protobuf.js/issues/677)<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/0c6e639d08fdf9be12677bf678563ea631bafb2c) Added infrastructure for custom wrapping/unwrapping of special types, see [#677](https://github.com/dcodeIO/protobuf.js/issues/677)<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/0425b584f49841d87a8249fef30c78cc31c1c742) More decorator progress (MapField.d, optional Type.d)<br />
Expand Down
93 changes: 60 additions & 33 deletions cli/lib/tsd-jsdoc/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,24 +134,36 @@ function writeln() {
indentWritten = false;
}

var skipTagsRe = /@(type|memberof|name|exports|interface|extends|implements|constructor|function|template|property|this|typedef|variation|example|returns \{undefined})[^@$]*/g,
skipTypeRe = /(@[^ ]+) \{[^\s$]+}/g;

// writes a comment
function writeComment(comment, otherwiseNewline) {
if (!comment || options.comments === false) {
if (otherwiseNewline)
writeln();
return;
}
var first = true;
comment.split(/\r?\n/g).forEach(function(line) {
line = line.trim().replace(/^\*/, " *");
if (line.length) {
if (first) {
writeln();
first = false;
comment = comment.replace(skipTagsRe, "").trim();
if (comment.charAt(comment.length - 1) !== "/")
comment += "/";
var lines = comment.split(/\r?\n/g);
if (lines.length === 3) {
writeln();
writeln("/*" + lines[1].trim() + " */");
} else {
var first = true;
lines.forEach(function(line) {
line = line.trim().replace(/^\*/, " *").replace(skipTypeRe, "$1");
if (line.length) {
if (first) {
writeln();
first = false;
}
writeln(line);
}
writeln(line);
}
});
});
}
}

// recursively replaces all occurencies of re's match
Expand Down Expand Up @@ -241,7 +253,11 @@ function getTypeOf(element) {

// begins writing the definition of the specified element
function begin(element, is_interface) {
writeComment(element.comment, is_interface || isInterface(element) || isClassLike(element) || isNamespace(element) || element.isEnum || element.scope === "global");
if (!seen[element.longname]) {
writeComment(element.comment, is_interface || isInterface(element) || isClassLike(element) || isNamespace(element) || element.isEnum || element.scope === "global");
seen[element.longname] = element;
} else
writeln();
if (element.scope !== "global" || options.module)
return;
write("export ");
Expand Down Expand Up @@ -332,7 +348,10 @@ function writeProperty(property) {
//

// handles a single element of any understood type
function handleElement(element, parent, insideClass) {
function handleElement(element, parent) {
if (element.scope === "inner")
return false;

if (element.optional !== true && element.type && element.type.names && element.type.names.length) {
for (var i = 0; i < element.type.names.length; i++) {
if (element.type.names[i].toLowerCase() === "undefined") {
Expand All @@ -347,29 +366,21 @@ function handleElement(element, parent, insideClass) {

if (seen[element.longname])
return true;
if (isClassLike(element)) {
if (insideClass)
return false;
if (isClassLike(element))
handleClass(element, parent);
} else switch (element.kind) {
else switch (element.kind) {
case "module":
case "namespace":
if (insideClass)
return false;
handleNamespace(element, parent);
break;
case "constant":
case "member":
if (insideClass && element.isEnum)
return false;
handleMember(element, parent);
break;
case "function":
handleFunction(element, parent);
break;
case "typedef":
if (insideClass)
return false;
handleTypeDef(element, parent);
break;
case "package":
Expand All @@ -381,14 +392,25 @@ function handleElement(element, parent, insideClass) {

// handles (just) a namespace
function handleNamespace(element/*, parent*/) {
begin(element);
writeln("namespace ", element.name, " {");
++indent;
getChildrenOf(element).forEach(function(child) {
var children = getChildrenOf(element);
if (!children.length)
return;
var first = true;
children.forEach(function(child) {
if (child.scope === "inner" || seen[child.longname])
return;
if (first) {
begin(element);
writeln("namespace ", element.name, " {");
++indent;
first = false;
}
handleElement(child, element);
});
--indent;
writeln("}");
if (!first) {
--indent;
writeln("}");
}
}

// a filter function to remove any module references
Expand Down Expand Up @@ -446,8 +468,11 @@ function handleClass(element, parent) {
// class-compatible members
var incompatible = [];
getChildrenOf(element).forEach(function(child) {
if (!handleElement(child, element, true))
if (isClassLike(child) || element.kind === "module" || element.kind === "typedef") {
incompatible.push(child);
return;
}
handleElement(child, element);
});

--indent;
Expand Down Expand Up @@ -519,12 +544,14 @@ function handleMember(element, parent) {

// handles a function or method
function handleFunction(element, parent, isConstructor) {
var insideClass = true;
if (isConstructor) {
writeComment(element.comment);
write("constructor");
} else {
begin(element);
if (isClassLike(parent)) {
insideClass = isClassLike(parent);
if (insideClass) {
write(element.access || "public", " ");
if (element.scope === "static")
write("static ");
Expand All @@ -536,6 +563,8 @@ function handleFunction(element, parent, isConstructor) {
}
writeFunctionSignature(element, isConstructor, false);
writeln(";");
if (!insideClass)
handleNamespace(element);
}

// handles a type definition (not a real type)
Expand All @@ -548,9 +577,7 @@ function handleTypeDef(element, parent) {
writeInterface(element);
}
} else {
// see: https://github.com/dcodeIO/protobuf.js/issues/737
// NO begin(element, true); - isn't exported
writeln();
writeComment(element.comment, true);
write("type ", element.name);
if (element.templates && element.templates.length)
write("<", element.templates.join(", "), ">");
Expand Down
12 changes: 0 additions & 12 deletions cli/targets/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,18 +536,6 @@ function buildType(ref, type) {
]);
buildFunction(type, "toObject", protobuf.converter.toObject(type));

push("");
pushComment([
"Creates a plain object from this " + type.name + " message. Also converts values to other types if specified.",
"@param {$protobuf.IConversionOptions} [options] Conversion options",
"@returns {Object.<string,*>} Plain object"
]);
push(escapeName(type.name) + ".prototype.toObject = function toObject(options) {");
++indent;
push("return this.constructor.toObject(this, options);");
--indent;
push("};");

push("");
pushComment([
"Converts this " + type.name + " to JSON.",
Expand Down
Loading

0 comments on commit 22f907c

Please sign in to comment.