Skip to content

Commit fb3f9c7

Browse files
committed
CLI: Additional tsd-jsdoc handling of properties inside of namespaces and TS specific API exposure
1 parent 5867f07 commit fb3f9c7

File tree

6 files changed

+243
-25
lines changed

6 files changed

+243
-25
lines changed

cli/lib/tsd-jsdoc/publish.js

+24-6
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ var keepTags = [
143143

144144
// parses a comment into text and tags
145145
function parseComment(comment) {
146-
var lines = comment.replace(/^ *\/\*\* *|^ *\*\/| *\*\/ *$|^ *\* */mg, "").trim().split(/\r?\n/g);
146+
var lines = comment.replace(/^ *\/\*\* *|^ *\*\/| *\*\/ *$|^ *\* */mg, "").trim().split(/\r?\n|\r/g); // property.description has just "\r" ?!
147147
var desc;
148148
var text = [];
149149
var tags = null;
@@ -174,7 +174,6 @@ function writeComment(comment, otherwiseNewline) {
174174
writeln();
175175
return;
176176
}
177-
178177
if (typeof comment !== "object")
179178
comment = parseComment(comment);
180179
comment.tags = comment.tags.filter(function(tag) {
@@ -187,7 +186,10 @@ function writeComment(comment, otherwiseNewline) {
187186
}
188187
writeln("/**");
189188
comment.text.forEach(function(line) {
190-
writeln(" * ", line);
189+
if (line.length)
190+
writeln(" * ", line);
191+
else
192+
writeln(" *");
191193
});
192194
comment.tags.forEach(function(tag) {
193195
var started = false;
@@ -393,8 +395,12 @@ function writeInterfaceBody(element) {
393395
write("}");
394396
}
395397

396-
function writeProperty(property) {
397-
writeComment(property.comment);
398+
function writeProperty(property, withLet) {
399+
writeComment(property.description);
400+
if (!/^[\w$]+$/.test(property.name)) // incompatible
401+
write("// ");
402+
if (withLet)
403+
write("let ");
398404
write(property.name);
399405
if (property.optional)
400406
write("?");
@@ -454,6 +460,16 @@ function handleNamespace(element/*, parent*/) {
454460
if (!children.length)
455461
return;
456462
var first = true;
463+
if (element.properties)
464+
element.properties.forEach(function(property) {
465+
if (first) {
466+
begin(element);
467+
writeln("namespace ", element.name, " {");
468+
++indent;
469+
first = false;
470+
}
471+
writeProperty(property, true);
472+
});
457473
children.forEach(function(child) {
458474
if (child.scope === "inner" || seen[child.longname])
459475
return;
@@ -521,7 +537,9 @@ function handleClass(element, parent) {
521537

522538
// properties
523539
if (is_interface && element.properties)
524-
element.properties.forEach(writeProperty);
540+
element.properties.forEach(function(property) {
541+
writeProperty(property);
542+
});
525543

526544
// class-compatible members
527545
var incompatible = [];

config/tslint.json

+10-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@
1313
"member-ordering": [ false ],
1414
"object-literal-sort-keys": false,
1515
"no-string-literal": false,
16-
"prefer-const": false
16+
"prefer-const": false,
17+
"ban-types": [
18+
true,
19+
["Object", "Avoid using the `Object` type. Did you mean `object`?"],
20+
// ["Function", "Avoid using the `Function` type. Prefer a specific function type, like `() => void`."],
21+
["Boolean", "Avoid using the `Boolean` type. Did you mean `boolean`?"],
22+
["Number", "Avoid using the `Number` type. Did you mean `number`?"],
23+
["String", "Avoid using the `String` type. Did you mean `string`?"],
24+
["Symbol", "Avoid using the `Symbol` type. Did you mean `symbol`?"]
25+
]
1726
}
1827
}

0 commit comments

Comments
 (0)