fix(router): re-export of Type

Closes #3632

Closes #3704
This commit is contained in:
Misko Hevery 2015-08-18 15:37:27 -07:00 committed by Miško Hevery
parent 6c3c6060a5
commit b8be4bfaaf
6 changed files with 60 additions and 97 deletions

View File

@ -1,72 +0,0 @@
{%- macro commentBlock(doc, level) -%}
{%- if doc.content | trim %}
{% if level > 1 %}{$ '/**' | indent(level-1, true) | replace(r/\n$/, "") $}{% else %}/**{% endif %}
{$ doc.content | trim | replace(r/^/gm, "* ") | indent(level, true) | replace(r/\n$/, "") $}
{$ '*/' | indent(level, true) | replace(r/\n$/, "") $}{% endif -%}
{%- endmacro -%}
{%- macro memberInfo(member) -%}
{$ commentBlock(member, 5) $}
{$ member.name $}{% if member.optional %}?{% endif -%}
{% if member.typeParameters %}<{% for typeParam in member.typeParameters %}{$ typeParam $}{% if not loop.last %}, {% endif %}{% endfor %}>{% endif -%}
{%- if member.parameters -%}({% for param in member.parameters %}{$ param $}{% if not loop.last %}, {% endif %}{% endfor %}){%- endif -%}
{%- if member.returnType == 'Directive' %}: DirectiveAnnotation{%- elif member.returnType -%}: {$ member.returnType $}{%- else -%}: void
{%- endif -%};
{%- endmacro -%}
// Type definitions for Angular v{$ versionInfo.currentVersion.full | replace(r/\+/, "_") $}
// Project: http://angular.io/
// Definitions by: angular team <https://github.com/angular/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
// ***********************************************************
// This file is generated by the Angular build process.
// Please do not create manual edits or send pull requests
// modifying this file.
// ***********************************************************
{% block staticDeclarations %}{% endblock %}
{% for alias, module in doc.moduleDocs %}
{$ commentBlock(module.doc, 1) $}
declare module ng {
{%- for export in module.doc.exports -%}
{%- if export.content -%}
{$ commentBlock(export, 3) $}
{%- endif %}
{$ export.docType $} {$ export.name $}{$ export.typeParams $}{%- if export.heritage == ' extends Directive' %} extends DirectiveAnnotation{% else %}{$ export.heritage $}{% endif %}
{%- if export.docType == 'class' or export.docType == 'interface' %} {
{%- if export.newMember %}
{$ memberInfo(export.newMember) $}
{% endif %}
{%- if export.callMember %}
{$ memberInfo(export.callMember) $}
{% endif -%}
{%- for member in export.members %}
{$ memberInfo(member) $}
{%- endfor %}
}
{%- elif export.docType == 'enum' %} {
{%- for member in export.members %}
{$ member $}{% if not loop.last %},
{%- endif -%}
{%- endfor %}
}
{%- else -%}
{% if export.parameters %}({% for param in export.parameters %}{$ param $}{% if not loop.last %}, {% endif %}{% endfor %}){%- endif %}
{%- if export.returnType %} : {$ export.returnType $} {% endif -%}
;
{%- endif %}
{% endfor %}
}
{% endfor %}
declare module "angular2/angular2" {
export = ng;
}

View File

@ -68,6 +68,7 @@ module.exports = new Package('angular-v2-docs', [jsdocPackage, nunjucksPackage,
{
id: 'angular2/router',
references: ['./angular2.d.ts'],
remapTypes: {Type: 'ng.Type'},
modules: {
'angular2/router': {
namespace: 'ngRouter',

View File

@ -0,0 +1,40 @@
module.exports = {
signature: function(remap) {
return function(ast) {
try {
var text = [];
if (ast.isStatic) text.push('static ');
text.push(ast.name);
if (ast.optional) text.push('?');
if (ast.typeParameters) {
text.push('<');
text.push(ast.typeParameters.join(', '));
text.push('>');
}
if (ast.parameters) {
text.push('(');
text.push(ast.parameters.join(', '));
text.push(')');
}
if (ast.returnType) {
text.push(': ', ast.returnType);
} else if (ast.parameters) {
text.push(': void');
} else {
text.push(': any');
}
var string = text.join('');
for (var key in remap) {
if (remap.hasOwnProperty(key)) {
string = string.replace(new RegExp('\\b' + key + '\\b', 'gm'), remap[key]);
}
}
return string;
} catch (e) {
console.log(e.toString(), e.stack);
return 'ERROR: ' + e.toString();
}
}
}
};

View File

@ -1,5 +1,6 @@
var _ = require('lodash');
var path = require('canonical-path');
var codeGen = require('./code_gen.js');
module.exports = function createTypeDefinitionFile(log) {
@ -31,15 +32,17 @@ module.exports = function createTypeDefinitionFile(log) {
path: docPath,
outputPath: docPath,
// A type definition may include a number of top level modules
// And those modules could be aliased (such as 'angular2/angular2.api' -> 'angular2/angular2')
moduleDocs: _.transform(def.modules, function(moduleDocs, props, alias) {
moduleDocs[props.id] = {
id: alias,
doc: null,
namespace: props.namespace,
references: def.references
};
})
// And those modules could be aliased (such as 'angular2/angular2.api' ->
// 'angular2/angular2')
moduleDocs: _.transform(def.modules,
function(moduleDocs, props, alias) {
moduleDocs[props.id] = {
id: alias,
doc: null, namespace: props.namespace,
references: def.references
};
}),
signature: codeGen.signature(def.remapTypes)
};
});

View File

@ -8,18 +8,9 @@
{%- endmacro -%}
{%- macro memberInfo(member) -%}
{%- macro memberInfo(signature, member) -%}
{$ commentBlock(member, 5) $}
{% if member.isStatic -%}static {% endif -%}{$ member.name $}{% if member.optional %}?{% endif -%}
{% if member.typeParameters %}<{% for typeParam in member.typeParameters %}{$ typeParam $}{% if not loop.last %}, {% endif %}{% endfor %}>{% endif -%}
{%- if member.parameters -%}({% for param in member.parameters %}{$ param $}{% if not loop.last %}, {% endif %}{% endfor %}){%- endif -%}
{%- if member.returnType -%}
: {$ member.returnType $}
{%- elif member.parameters -%}
: void
{%- else -%}
: any
{%- endif -%};
{$ signature(member) $};
{%- endmacro -%}
@ -53,16 +44,16 @@ declare module {$ module.namespace $} {
{$ export.docType $} {$ export.name $}{$ export.typeParams $}{%- if export.heritage == ' extends Directive' %} extends DirectiveAnnotation{% else %}{$ export.heritage $}{% endif %}
{%- if export.docType == 'class' or export.docType == 'interface' %} {
{%- if export.newMember %}
{$ memberInfo(export.newMember) $}
{$ memberInfo(doc.signature, export.newMember) $}
{% endif %}
{%- if export.callMember %}
{$ memberInfo(export.callMember) $}
{$ memberInfo(doc.signature, export.callMember) $}
{% endif -%}
{%- for static in export.statics %}
{$ memberInfo(static) $}
{$ memberInfo(doc.signature, static) $}
{%- endfor -%}
{%- for member in export.members %}
{$ memberInfo(member) $}
{$ memberInfo(doc.signature, member) $}
{%- endfor %}
}

View File

@ -21,7 +21,7 @@ export {OnActivate, OnDeactivate, OnReuse, CanDeactivate, CanReuse} from './src/
export {CanActivate} from './src/router/lifecycle_annotations';
export {Instruction, ComponentInstruction} from './src/router/instruction';
export {Url} from './src/router/url_parser';
export {OpaqueToken, Type} from 'angular2/angular2';
export {OpaqueToken} from 'angular2/angular2';
export {ROUTE_DATA} from './src/router/route_data';
import {LocationStrategy} from './src/router/location_strategy';