Skip to content

Commit b8be4bf

Browse files
committed
fix(router): re-export of Type
Closes angular#3632 Closes angular#3704
1 parent 6c3c606 commit b8be4bf

File tree

6 files changed

+60
-97
lines changed

6 files changed

+60
-97
lines changed

docs/docs-package/templates/type-definition.template.html

Lines changed: 0 additions & 72 deletions
This file was deleted.

docs/typescript-definition-package/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ module.exports = new Package('angular-v2-docs', [jsdocPackage, nunjucksPackage,
6868
{
6969
id: 'angular2/router',
7070
references: ['./angular2.d.ts'],
71+
remapTypes: {Type: 'ng.Type'},
7172
modules: {
7273
'angular2/router': {
7374
namespace: 'ngRouter',
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
module.exports = {
2+
3+
signature: function(remap) {
4+
return function(ast) {
5+
try {
6+
var text = [];
7+
if (ast.isStatic) text.push('static ');
8+
text.push(ast.name);
9+
if (ast.optional) text.push('?');
10+
if (ast.typeParameters) {
11+
text.push('<');
12+
text.push(ast.typeParameters.join(', '));
13+
text.push('>');
14+
}
15+
if (ast.parameters) {
16+
text.push('(');
17+
text.push(ast.parameters.join(', '));
18+
text.push(')');
19+
}
20+
if (ast.returnType) {
21+
text.push(': ', ast.returnType);
22+
} else if (ast.parameters) {
23+
text.push(': void');
24+
} else {
25+
text.push(': any');
26+
}
27+
var string = text.join('');
28+
for (var key in remap) {
29+
if (remap.hasOwnProperty(key)) {
30+
string = string.replace(new RegExp('\\b' + key + '\\b', 'gm'), remap[key]);
31+
}
32+
}
33+
return string;
34+
} catch (e) {
35+
console.log(e.toString(), e.stack);
36+
return 'ERROR: ' + e.toString();
37+
}
38+
}
39+
}
40+
};

docs/typescript-definition-package/processors/createTypeDefinitionFile.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var _ = require('lodash');
22
var path = require('canonical-path');
3+
var codeGen = require('./code_gen.js');
34

45
module.exports = function createTypeDefinitionFile(log) {
56

@@ -31,15 +32,17 @@ module.exports = function createTypeDefinitionFile(log) {
3132
path: docPath,
3233
outputPath: docPath,
3334
// A type definition may include a number of top level modules
34-
// And those modules could be aliased (such as 'angular2/angular2.api' -> 'angular2/angular2')
35-
moduleDocs: _.transform(def.modules, function(moduleDocs, props, alias) {
36-
moduleDocs[props.id] = {
37-
id: alias,
38-
doc: null,
39-
namespace: props.namespace,
40-
references: def.references
41-
};
42-
})
35+
// And those modules could be aliased (such as 'angular2/angular2.api' ->
36+
// 'angular2/angular2')
37+
moduleDocs: _.transform(def.modules,
38+
function(moduleDocs, props, alias) {
39+
moduleDocs[props.id] = {
40+
id: alias,
41+
doc: null, namespace: props.namespace,
42+
references: def.references
43+
};
44+
}),
45+
signature: codeGen.signature(def.remapTypes)
4346
};
4447
});
4548

docs/typescript-definition-package/templates/type-definition.template.html

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,9 @@
88
{%- endmacro -%}
99

1010

11-
{%- macro memberInfo(member) -%}
11+
{%- macro memberInfo(signature, member) -%}
1212
{$ commentBlock(member, 5) $}
13-
{% if member.isStatic -%}static {% endif -%}{$ member.name $}{% if member.optional %}?{% endif -%}
14-
{% if member.typeParameters %}<{% for typeParam in member.typeParameters %}{$ typeParam $}{% if not loop.last %}, {% endif %}{% endfor %}>{% endif -%}
15-
{%- if member.parameters -%}({% for param in member.parameters %}{$ param $}{% if not loop.last %}, {% endif %}{% endfor %}){%- endif -%}
16-
{%- if member.returnType -%}
17-
: {$ member.returnType $}
18-
{%- elif member.parameters -%}
19-
: void
20-
{%- else -%}
21-
: any
22-
{%- endif -%};
13+
{$ signature(member) $};
2314
{%- endmacro -%}
2415

2516

@@ -53,16 +44,16 @@
5344
{$ export.docType $} {$ export.name $}{$ export.typeParams $}{%- if export.heritage == ' extends Directive' %} extends DirectiveAnnotation{% else %}{$ export.heritage $}{% endif %}
5445
{%- if export.docType == 'class' or export.docType == 'interface' %} {
5546
{%- if export.newMember %}
56-
{$ memberInfo(export.newMember) $}
47+
{$ memberInfo(doc.signature, export.newMember) $}
5748
{% endif %}
5849
{%- if export.callMember %}
59-
{$ memberInfo(export.callMember) $}
50+
{$ memberInfo(doc.signature, export.callMember) $}
6051
{% endif -%}
6152
{%- for static in export.statics %}
62-
{$ memberInfo(static) $}
53+
{$ memberInfo(doc.signature, static) $}
6354
{%- endfor -%}
6455
{%- for member in export.members %}
65-
{$ memberInfo(member) $}
56+
{$ memberInfo(doc.signature, member) $}
6657
{%- endfor %}
6758
}
6859

modules/angular2/router.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export {OnActivate, OnDeactivate, OnReuse, CanDeactivate, CanReuse} from './src/
2121
export {CanActivate} from './src/router/lifecycle_annotations';
2222
export {Instruction, ComponentInstruction} from './src/router/instruction';
2323
export {Url} from './src/router/url_parser';
24-
export {OpaqueToken, Type} from 'angular2/angular2';
24+
export {OpaqueToken} from 'angular2/angular2';
2525
export {ROUTE_DATA} from './src/router/route_data';
2626

2727
import {LocationStrategy} from './src/router/location_strategy';

0 commit comments

Comments
 (0)