Permalink
Browse files

CLI: Added support for TypeScript enums to pbts

  • Loading branch information...
dcodeIO committed Jan 2, 2017
1 parent 0cda72a commit 3c775535517b8385a1d3c1bf056f3da3b4266f8c
Showing with 45 additions and 25 deletions.
  1. +45 −25 lib/tsd-jsdoc/publish.js
@@ -77,7 +77,9 @@ exports.publish = function publish(taffy, opts) {
}
// handle all
getChildrenOf(undefined).forEach(handleElement);
getChildrenOf(undefined).forEach(function(child) {
handleElement(child, null);
});
// process queued
while (queuedInterfaces.length) {
@@ -228,7 +230,7 @@ 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));
writeComment(element.comment, is_interface || isInterface(element) || isClassLike(element) || isNamespace(element) || element.isEnum);
if (element.scope !== "global" || options.module || is_interface || isInterface(element))
return;
write("export ");
@@ -308,28 +310,43 @@ function writeInterface(element) {
//
// handles a single element of any understood type
function handleElement(element, parent) {
function handleElement(element, parent, insideClass) {
if (seen[element.longname])
return;
seen[element.longname] = element;
if (isClassLike(element))
return handleClass(element, parent);
switch (element.kind) {
return true;
if (isClassLike(element)) {
if (insideClass)
return false;
handleClass(element, parent);
} else switch (element.kind) {
case "module":
case "namespace":
return handleNamespace(element, parent);
if (insideClass)
return false;
handleNamespace(element, parent);
break;
case "constant":
case "member":
return handleMember(element, parent);
if (insideClass && element.isEnum)
return false;
handleMember(element, parent);
break;
case "function":
return handleFunction(element, parent);
handleFunction(element, parent);
break;
case "typedef":
return handleTypeDef(element, parent);
if (insideClass)
return false;
handleTypeDef(element, parent);
break;
case "package":
break;
}
seen[element.longname] = element;
return true;
}
// handles (just) a namespace
function handleNamespace(element, parent) {
function handleNamespace(element/*, parent*/) {
begin(element);
writeln("namespace ", element.name, " {");
++indent;
@@ -383,24 +400,25 @@ function handleClass(element, parent) {
if (!is_interface && !element.virtual)
handleFunction(element, parent, true);
// members except inner classes
var innerClasses = [];
// class-compatible members
var inner = [];
getChildrenOf(element).forEach(function(child) {
if (isClassLike(child))
innerClasses.push(child);
else
handleElement(child, element);
if (!handleElement(child, element, true))
inner.push(child);
});
--indent;
writeln("}");
if (innerClasses.length) {
begin(element);
// class-incompatible members
if (inner.length) {
writeln();
if (element.scope === "global" && !options.module)
write("export ");
writeln("namespace ", element.name, " {");
++indent;
innerClasses.forEach(function(inner) {
handleClass(inner, element);
inner.forEach(function(child) {
handleElement(child, element);
});
--indent;
writeln("}");
@@ -413,11 +431,13 @@ function handleMember(element, parent) {
if (element.isEnum) {
writeln("enum ", element.name, "{");
writeln("enum ", element.name, " {");
++indent;
element.properties.forEach(function(property, i) {
writeComment(property);
write(p.name);
write(property.name);
if (property.defaultvalue !== undefined)
write(" = ", JSON.stringify(property.defaultvalue));
if (i < element.properties.length - 1)
writeln(",");
else

0 comments on commit 3c77553

Please sign in to comment.