chore(doc-gen): render "call" and "new" members of interfaces correctly

Partially Closes #2849
This commit is contained in:
Peter Bacon Darwin 2015-07-02 22:39:52 +01:00
parent ef3cc8e6eb
commit ad506a7aaa
4 changed files with 38 additions and 3 deletions

View File

@ -1,4 +1,5 @@
export interface MyInterface {
optionalProperty? : string,
optionalProperty? : string
(param: string) : string
new (param: number) : MyInterface
}

View File

@ -83,6 +83,12 @@ module.exports = function readTypeScriptModules(tsParser, readFilesProcessor, mo
} else if (!hidePrivateMembers || memberSymbol.name.charAt(0) !== '_') {
docs.push(memberDoc);
exportDoc.members.push(memberDoc);
} else if (memberSymbol.name === '__call' && memberSymbol.flags & ts.SymbolFlags.Signature) {
docs.push(memberDoc);
exportDoc.callMember = memberDoc;
} else if (memberSymbol.name === '__new' && memberSymbol.flags & ts.SymbolFlags.Signature) {
docs.push(memberDoc);
exportDoc.newMember = memberDoc;
}
}
@ -196,7 +202,7 @@ module.exports = function readTypeScriptModules(tsParser, readFilesProcessor, mo
location: getLocation(memberSymbol)
};
if (memberSymbol.flags & ts.SymbolFlags.Method) {
if (memberSymbol.flags & (ts.SymbolFlags.Method | ts.SymbolFlags.Signature)) {
// NOTE: we use the property name `parameters` here so we don't conflict
// with the `params` property that will be updated by dgeni reading the
// `@param` tags from the docs
@ -208,7 +214,7 @@ module.exports = function readTypeScriptModules(tsParser, readFilesProcessor, mo
memberDoc.name = 'constructor';
}
if(memberSymbol.flags & ts.SymbolFlags.Value) {
if(memberSymbol.flags & (ts.SymbolFlags.Value | ts.SymbolFlags.Signature) ) {
memberDoc.returnType = getReturnType(typeChecker, memberSymbol);
}

View File

@ -58,6 +58,22 @@ describe('readTypeScriptModules', function() {
expect(member.name).toEqual('optionalProperty');
expect(member.optional).toEqual(true);
});
it('should handle "call" type interfaces', function() {
processor.sourceFiles = [ 'interfaces.ts'];
var docs = [];
processor.$process(docs);
var moduleDoc = docs[0];
var exportedInterface = moduleDoc.exports[0];
expect(exportedInterface.callMember).toBeDefined();
expect(exportedInterface.callMember.parameters).toBeDefined();
expect(exportedInterface.callMember.returnType).toBeDefined();
expect(exportedInterface.newMember).toBeDefined();
expect(exportedInterface.newMember.parameters).toBeDefined();
expect(exportedInterface.newMember.returnType).toBeDefined();
});
});

View File

@ -26,6 +26,18 @@ declare module "{$ module.id $}" {
{%- endif %}
{$ export.docType $} {$ export.name $}{$ export.typeParams $}{$ export.heritage $}
{%- if export.docType == 'class' or export.docType == 'interface' %} {
{%- if export.newMember -%}
{$ commentBlock(export.newMember, 5) $}
new ({% for param in export.newMember.parameters %}{$ param $}{% if not loop.last %}, {% endif %}{% endfor %})
{%- if export.newMember.returnType %}: {$ export.newMember.returnType $}{%- else -%}: any{% endif -%}
;
{% endif %}
{%- if export.callMember -%}
{$ commentBlock(export.callMember, 5) $}
({% for param in export.callMember.parameters %}{$ param $}{% if not loop.last %}, {% endif %}{% endfor %})
{%- if export.callMember.returnType %}: {$ export.callMember.returnType $}{%- else -%}: any{% endif -%}
;
{% endif %}
{%- for member in export.members -%}
{$ commentBlock(member, 5) $}
{$ member.name $}