Skip to content

Commit 22f907c

Browse files
committed
CLI: Relieved tsd files from unnecessary comments; CLI: Generate TS namespaces 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)
1 parent c97b618 commit 22f907c

32 files changed

+6638
-3316
lines changed

Diff for: CHANGELOG.md

+26
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,48 @@
11
# [6.8.0](https://github.com/dcodeIO/protobuf.js/releases/tag/6.8.0)
22

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

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

1317
## New
18+
[: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 />
1419
[: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 />
1520

21+
## CLI
22+
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/b355115e619c6595ac9d91897cfe628ef0e46054) Prefer @tstype over @type when generating typedefs (tsd-jsdoc)<br />
23+
1624
## Docs
25+
[: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 />
26+
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/ef92da3768d8746dbfe72e77232f78b879fc811d) Additional notes on ext/descriptor<br />
27+
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/b646cf7499791a41b75eef2de1a80fb558d4159e) Updated CHANGELOG so everyone knows what's going on (and soon, breaking)<br />
1728
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/35a663757efe188bea552aef017837bc6c6a481a) Additional docs on TS/decorators usage<br />
1829

1930
## Other
31+
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/5bc3541d2da19e2857dc884f743d37c27e8e21f2) Even more documentation and typings for ext/descriptor<br />
32+
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/773e6347b57e4a5236b1ef0bb8d361e4b233caf7) ext/descriptor docs<br />
33+
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/773e6347b57e4a5236b1ef0bb8d361e4b233caf7) Decorators coverage<br />
34+
[: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 />
35+
[: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 />
36+
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/3a20968c6d676312e4f2a510f7e079e0e0819daf) Properly remove unnecessary (packed) options from JSON descriptors<br />
37+
[: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 />
38+
[: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 />
39+
[: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 />
40+
[: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 />
41+
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/708552bb84508364b6e6fdf73906aa69e83854e1) Added infrastructure for TypeScript support of extensions<br />
42+
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/23f26defa793b371c16b5f920fbacb3fb66bdf22) TypeScript generics improvements<br />
43+
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/e49bef863c0fb10257ec1001a3c5561755f2ec6b) More ext/descriptor progress, see [#757](https://github.com/dcodeIO/protobuf.js/issues/757)<br />
44+
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/6b94336c1e6eec0f2eb1bd5dca73a7a8e71a2153) Just export the relevant namespace in ext/descriptor<br />
45+
[: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 />
2046
[: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 />
2147
[: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 />
2248
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/0425b584f49841d87a8249fef30c78cc31c1c742) More decorator progress (MapField.d, optional Type.d)<br />

Diff for: cli/lib/tsd-jsdoc/publish.js

+60-33
Original file line numberDiff line numberDiff line change
@@ -134,24 +134,36 @@ function writeln() {
134134
indentWritten = false;
135135
}
136136

137+
var skipTagsRe = /@(type|memberof|name|exports|interface|extends|implements|constructor|function|template|property|this|typedef|variation|example|returns \{undefined})[^@$]*/g,
138+
skipTypeRe = /(@[^ ]+) \{[^\s$]+}/g;
139+
137140
// writes a comment
138141
function writeComment(comment, otherwiseNewline) {
139142
if (!comment || options.comments === false) {
140143
if (otherwiseNewline)
141144
writeln();
142145
return;
143146
}
144-
var first = true;
145-
comment.split(/\r?\n/g).forEach(function(line) {
146-
line = line.trim().replace(/^\*/, " *");
147-
if (line.length) {
148-
if (first) {
149-
writeln();
150-
first = false;
147+
comment = comment.replace(skipTagsRe, "").trim();
148+
if (comment.charAt(comment.length - 1) !== "/")
149+
comment += "/";
150+
var lines = comment.split(/\r?\n/g);
151+
if (lines.length === 3) {
152+
writeln();
153+
writeln("/*" + lines[1].trim() + " */");
154+
} else {
155+
var first = true;
156+
lines.forEach(function(line) {
157+
line = line.trim().replace(/^\*/, " *").replace(skipTypeRe, "$1");
158+
if (line.length) {
159+
if (first) {
160+
writeln();
161+
first = false;
162+
}
163+
writeln(line);
151164
}
152-
writeln(line);
153-
}
154-
});
165+
});
166+
}
155167
}
156168

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

242254
// begins writing the definition of the specified element
243255
function begin(element, is_interface) {
244-
writeComment(element.comment, is_interface || isInterface(element) || isClassLike(element) || isNamespace(element) || element.isEnum || element.scope === "global");
256+
if (!seen[element.longname]) {
257+
writeComment(element.comment, is_interface || isInterface(element) || isClassLike(element) || isNamespace(element) || element.isEnum || element.scope === "global");
258+
seen[element.longname] = element;
259+
} else
260+
writeln();
245261
if (element.scope !== "global" || options.module)
246262
return;
247263
write("export ");
@@ -332,7 +348,10 @@ function writeProperty(property) {
332348
//
333349

334350
// handles a single element of any understood type
335-
function handleElement(element, parent, insideClass) {
351+
function handleElement(element, parent) {
352+
if (element.scope === "inner")
353+
return false;
354+
336355
if (element.optional !== true && element.type && element.type.names && element.type.names.length) {
337356
for (var i = 0; i < element.type.names.length; i++) {
338357
if (element.type.names[i].toLowerCase() === "undefined") {
@@ -347,29 +366,21 @@ function handleElement(element, parent, insideClass) {
347366

348367
if (seen[element.longname])
349368
return true;
350-
if (isClassLike(element)) {
351-
if (insideClass)
352-
return false;
369+
if (isClassLike(element))
353370
handleClass(element, parent);
354-
} else switch (element.kind) {
371+
else switch (element.kind) {
355372
case "module":
356373
case "namespace":
357-
if (insideClass)
358-
return false;
359374
handleNamespace(element, parent);
360375
break;
361376
case "constant":
362377
case "member":
363-
if (insideClass && element.isEnum)
364-
return false;
365378
handleMember(element, parent);
366379
break;
367380
case "function":
368381
handleFunction(element, parent);
369382
break;
370383
case "typedef":
371-
if (insideClass)
372-
return false;
373384
handleTypeDef(element, parent);
374385
break;
375386
case "package":
@@ -381,14 +392,25 @@ function handleElement(element, parent, insideClass) {
381392

382393
// handles (just) a namespace
383394
function handleNamespace(element/*, parent*/) {
384-
begin(element);
385-
writeln("namespace ", element.name, " {");
386-
++indent;
387-
getChildrenOf(element).forEach(function(child) {
395+
var children = getChildrenOf(element);
396+
if (!children.length)
397+
return;
398+
var first = true;
399+
children.forEach(function(child) {
400+
if (child.scope === "inner" || seen[child.longname])
401+
return;
402+
if (first) {
403+
begin(element);
404+
writeln("namespace ", element.name, " {");
405+
++indent;
406+
first = false;
407+
}
388408
handleElement(child, element);
389409
});
390-
--indent;
391-
writeln("}");
410+
if (!first) {
411+
--indent;
412+
writeln("}");
413+
}
392414
}
393415

394416
// a filter function to remove any module references
@@ -446,8 +468,11 @@ function handleClass(element, parent) {
446468
// class-compatible members
447469
var incompatible = [];
448470
getChildrenOf(element).forEach(function(child) {
449-
if (!handleElement(child, element, true))
471+
if (isClassLike(child) || element.kind === "module" || element.kind === "typedef") {
450472
incompatible.push(child);
473+
return;
474+
}
475+
handleElement(child, element);
451476
});
452477

453478
--indent;
@@ -519,12 +544,14 @@ function handleMember(element, parent) {
519544

520545
// handles a function or method
521546
function handleFunction(element, parent, isConstructor) {
547+
var insideClass = true;
522548
if (isConstructor) {
523549
writeComment(element.comment);
524550
write("constructor");
525551
} else {
526552
begin(element);
527-
if (isClassLike(parent)) {
553+
insideClass = isClassLike(parent);
554+
if (insideClass) {
528555
write(element.access || "public", " ");
529556
if (element.scope === "static")
530557
write("static ");
@@ -536,6 +563,8 @@ function handleFunction(element, parent, isConstructor) {
536563
}
537564
writeFunctionSignature(element, isConstructor, false);
538565
writeln(";");
566+
if (!insideClass)
567+
handleNamespace(element);
539568
}
540569

541570
// handles a type definition (not a real type)
@@ -548,9 +577,7 @@ function handleTypeDef(element, parent) {
548577
writeInterface(element);
549578
}
550579
} else {
551-
// see: https://github.com/dcodeIO/protobuf.js/issues/737
552-
// NO begin(element, true); - isn't exported
553-
writeln();
580+
writeComment(element.comment, true);
554581
write("type ", element.name);
555582
if (element.templates && element.templates.length)
556583
write("<", element.templates.join(", "), ">");

Diff for: cli/targets/static.js

-12
Original file line numberDiff line numberDiff line change
@@ -536,18 +536,6 @@ function buildType(ref, type) {
536536
]);
537537
buildFunction(type, "toObject", protobuf.converter.toObject(type));
538538

539-
push("");
540-
pushComment([
541-
"Creates a plain object from this " + type.name + " message. Also converts values to other types if specified.",
542-
"@param {$protobuf.IConversionOptions} [options] Conversion options",
543-
"@returns {Object.<string,*>} Plain object"
544-
]);
545-
push(escapeName(type.name) + ".prototype.toObject = function toObject(options) {");
546-
++indent;
547-
push("return this.constructor.toObject(this, options);");
548-
--indent;
549-
push("};");
550-
551539
push("");
552540
pushComment([
553541
"Converts this " + type.name + " to JSON.",

0 commit comments

Comments
 (0)