Skip to content

Commit

Permalink
CLI: Additional tsd-jsdoc handling of properties inside of namespaces…
Browse files Browse the repository at this point in the history
… and TS specific API exposure
  • Loading branch information
dcodeIO committed Apr 18, 2017
1 parent 5867f07 commit fb3f9c7
Show file tree
Hide file tree
Showing 6 changed files with 243 additions and 25 deletions.
30 changes: 24 additions & 6 deletions cli/lib/tsd-jsdoc/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ var keepTags = [

// parses a comment into text and tags
function parseComment(comment) {
var lines = comment.replace(/^ *\/\*\* *|^ *\*\/| *\*\/ *$|^ *\* */mg, "").trim().split(/\r?\n/g);
var lines = comment.replace(/^ *\/\*\* *|^ *\*\/| *\*\/ *$|^ *\* */mg, "").trim().split(/\r?\n|\r/g); // property.description has just "\r" ?!
var desc;
var text = [];
var tags = null;
Expand Down Expand Up @@ -174,7 +174,6 @@ function writeComment(comment, otherwiseNewline) {
writeln();
return;
}

if (typeof comment !== "object")
comment = parseComment(comment);
comment.tags = comment.tags.filter(function(tag) {
Expand All @@ -187,7 +186,10 @@ function writeComment(comment, otherwiseNewline) {
}
writeln("/**");
comment.text.forEach(function(line) {
writeln(" * ", line);
if (line.length)
writeln(" * ", line);
else
writeln(" *");
});
comment.tags.forEach(function(tag) {
var started = false;
Expand Down Expand Up @@ -393,8 +395,12 @@ function writeInterfaceBody(element) {
write("}");
}

function writeProperty(property) {
writeComment(property.comment);
function writeProperty(property, withLet) {
writeComment(property.description);
if (!/^[\w$]+$/.test(property.name)) // incompatible
write("// ");
if (withLet)
write("let ");
write(property.name);
if (property.optional)
write("?");
Expand Down Expand Up @@ -454,6 +460,16 @@ function handleNamespace(element/*, parent*/) {
if (!children.length)
return;
var first = true;
if (element.properties)
element.properties.forEach(function(property) {
if (first) {
begin(element);
writeln("namespace ", element.name, " {");
++indent;
first = false;
}
writeProperty(property, true);
});
children.forEach(function(child) {
if (child.scope === "inner" || seen[child.longname])
return;
Expand Down Expand Up @@ -521,7 +537,9 @@ function handleClass(element, parent) {

// properties
if (is_interface && element.properties)
element.properties.forEach(writeProperty);
element.properties.forEach(function(property) {
writeProperty(property);
});

// class-compatible members
var incompatible = [];
Expand Down
11 changes: 10 additions & 1 deletion config/tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
"member-ordering": [ false ],
"object-literal-sort-keys": false,
"no-string-literal": false,
"prefer-const": false
"prefer-const": false,
"ban-types": [
true,
["Object", "Avoid using the `Object` type. Did you mean `object`?"],
// ["Function", "Avoid using the `Function` type. Prefer a specific function type, like `() => void`."],
["Boolean", "Avoid using the `Boolean` type. Did you mean `boolean`?"],
["Number", "Avoid using the `Number` type. Did you mean `number`?"],
["String", "Avoid using the `String` type. Did you mean `string`?"],
["Symbol", "Avoid using the `Symbol` type. Did you mean `symbol`?"]
]
}
}
Loading

0 comments on commit fb3f9c7

Please sign in to comment.