Skip to content

Commit

Permalink
Fix d.ts whitespace on empty lines, added tsd-jsdoc LICENSE [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Dec 15, 2016
1 parent 8f407a1 commit a834250
Show file tree
Hide file tree
Showing 3 changed files with 345 additions and 317 deletions.
21 changes: 21 additions & 0 deletions lib/tsd-jsdoc/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License

Copyright (c) 2016 Chad Engler

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
49 changes: 28 additions & 21 deletions lib/tsd-jsdoc/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ exports.publish = function publish(taffy, opts) {
while (queuedInterfaces.length) {
var element = queuedInterfaces.shift();
begin(element);
writeVirtualInterface(element);
writeInterface(element);
writeln(";");
}

Expand Down Expand Up @@ -120,7 +120,11 @@ function write() {

// writes one or multiple strings, followed by a new line
function writeln() {
write(Array.prototype.slice.call(arguments).join(""), "\n");
var s = Array.prototype.slice.call(arguments).join("");
if (s)
write(s, "\n");
else
out.write("\n");
indentWritten = false;
}

Expand Down Expand Up @@ -268,11 +272,22 @@ function writeFunctionSignature(element, isConstructor, isTypeDef) {
}
}

// writes (a typedef as) an interface
function writeInterface(element) {
writeln("interface ", element.name, " {");
++indent;
element.properties.forEach(function(property) {
writeln(property.name, ": ", getTypeOf(property), ";");
});
--indent;
writeln("}");
}

//
// Handlers
//

// handles a single element / any
// handles a single element of any understood type
function handleElement(element, parent) {
if (seen[element.longname])
return;
Expand Down Expand Up @@ -305,6 +320,12 @@ function handleNamespace(element, parent) {
writeln("}");
}

// a filter function to remove any module references
function notAModuleReference(ref) {
return ref.indexOf("module:") === -1;
}


// handles a class or class-like
function handleClass(element, parent) {
begin(element);
Expand All @@ -319,9 +340,7 @@ function handleClass(element, parent) {

// extended classes
if (element.augments) {
var augments = element.augments.filter(function(aug) {
return aug.indexOf("module:") === -1;
});
var augments = element.augments.filter(notAModuleReference);
if (augments.length)
write("extends ", augments[0], " ");
}
Expand All @@ -332,9 +351,7 @@ function handleClass(element, parent) {
Array.prototype.push.apply(impls, element.implements);
if (element.mixes)
Array.prototype.push.apply(impls, element.mixes);
impls = impls.filter(function(imp) {
return imp.indexOf("module:") === -1;
});
impls = impls.filter(notAModuleReference);
if (impls.length)
write("implements ", impls.join(", "), " ");

Expand All @@ -359,7 +376,7 @@ function handleClass(element, parent) {

if (innerClasses.length) {
writeln("");
writeln("module ", element.name, "{");
writeln("module ", element.name, " {");
++indent;
innerClasses.forEach(function(inner) {
handleClass(inner, element);
Expand Down Expand Up @@ -424,24 +441,14 @@ function handleFunction(element, parent, isConstructor) {
writeln(";");
}

function writeVirtualInterface(element) {
writeln("interface ", element.name, " {");
++indent;
element.properties.forEach(function(property) {
writeln(property.name, ": ", getTypeOf(property), ";");
});
--indent;
writeln("}");
}

// handles a type definition (not a real type)
function handleTypeDef(element, parent) {
if (isInterface(element)) {
if (isClass(parent))
queuedInterfaces.push(element);
else {
begin(element);
writeVirtualInterface(element);
writeInterface(element);
}
} else {
begin(element);
Expand Down
Loading

0 comments on commit a834250

Please sign in to comment.