fix(Typings): Output public constructors in .d.ts files

Closes #3926.

Closes #3963
This commit is contained in:
Jason Teplitz
2015-09-09 11:24:59 -07:00
parent 12dd44f7f6
commit 1926335b85
24 changed files with 136 additions and 41 deletions

View File

@ -52,11 +52,9 @@ module.exports = new Package('angular-v2-docs', [jsdocPackage, nunjucksPackage,
id: 'angular2/angular2',
references: ['../es6-promise/es6-promise.d.ts', '../rx/rx.d.ts'],
modules: {
'angular2/angular2': {namespace: 'ng', id: 'angular2/angular2'}
/* TODO(jeffbcross): re-implement with @jteplitz as part of #3926,
'angular2/angular2': {namespace: 'ng', id: 'angular2/angular2'},
'angular2/web_worker/worker': {namespace: 'ngWorker', id: 'angular2/web_worker/worker'},
'angular2/web_worker/ui': {namespace: 'ngUi', id: 'angular2/web_worker/ui'}
*/
}
},
{

View File

@ -5,6 +5,7 @@ function DtsSerializer(remap) {
}
DtsSerializer.prototype = {
_initializerRegex: /\s*=[^>][^,}]*/g,
constructor: DtsSerializer,
@ -18,15 +19,21 @@ DtsSerializer.prototype = {
}
if (ast.parameters) {
buffer.push('(');
buffer.push(ast.parameters.join(', '));
var parameters = ast.parameters;
for (var i = 0; i < parameters.length; i++) {
parameters[i] = parameters[i].replace(this._initializerRegex, '');
}
buffer.push(parameters.join(', '));
buffer.push(')');
}
if (ast.returnType) {
buffer.push(': ', ast.returnType);
} else if (ast.parameters) {
buffer.push(': void');
} else {
buffer.push(': any');
if (!isConstructor(ast)) {
if (ast.returnType) {
buffer.push(': ', ast.returnType);
} else if (ast.parameters) {
buffer.push(': void');
} else {
buffer.push(': any');
}
}
buffer.push(';\n');
},
@ -58,6 +65,7 @@ DtsSerializer.prototype = {
buffer.indent();
if (ast.newMember) this.member(buffer, ast.newMember);
if (ast.callMember) this.member(buffer, ast.callMember);
if (ast.constructorDoc) this.member(buffer, ast.constructorDoc);
ast.statics.forEach(function(staticMember) {
this.member(buffer, staticMember);
@ -144,7 +152,6 @@ DtsSerializer.prototype = {
}
};
function Buffer() {
this._globalBuffer = [];
this._indentedBuffer = [];
@ -191,7 +198,11 @@ Buffer.prototype = {
}
};
function isConstructor(ast) {
return ast.parameters && ast.name === "constructor";
}
module.exports = {
DtsSerializer: DtsSerializer
};