Skip to content

Commit 8ab18b7

Browse files
Added toObject converters
1 parent 9dac81d commit 8ab18b7

14 files changed

+616
-13
lines changed

bin/typedoc.js

Lines changed: 262 additions & 6 deletions
Large diffs are not rendered by default.

src/td/models/Reflection.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ module td
496496
}
497497

498498
this.traverse((child, property) => {
499+
if (property == TraverseProperty.TypeLiteral) return;
499500
var name = TraverseProperty[property];
500501
name = name.substr(0, 1).toLowerCase() + name.substr(1);
501502
if (!result[name]) result[name] = [];

src/td/models/Type.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,36 @@
11
module td
22
{
3+
/**
4+
* Base class of all type definitions.
5+
*
6+
* Instances of this class are also used to represent the type `void`.
7+
*/
38
export class Type
49
{
10+
/**
11+
* Is this an array type?
12+
*/
513
isArray:boolean;
614

715

16+
/**
17+
* Return a raw object representation of this type.
18+
*/
19+
toObject():any {
20+
var result:any = {};
21+
result.type = 'void';
22+
23+
if (this.isArray) {
24+
result.isArray = this.isArray;
25+
}
26+
27+
return result;
28+
}
29+
30+
31+
/**
32+
* Return a string representation of this type.
33+
*/
834
toString():string {
935
return 'void';
1036
}

src/td/models/reflections/DeclarationReflection.ts

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,6 @@ module td
145145

146146

147147

148-
/**
149-
* Is this reflection representing a container like a module or class?
150-
isContainer() {
151-
return this.kindOf(TypeScript.PullElementKind.SomeContainer);
152-
}
153-
*/
154148
getAllSignatures():SignatureReflection[] {
155149
var result = [];
156150

@@ -205,6 +199,39 @@ module td
205199
*/
206200
toObject():any {
207201
var result = super.toObject();
202+
203+
if (this.type) {
204+
result.type = this.type.toObject();
205+
}
206+
207+
if (this.defaultValue) {
208+
result.defaultValue = this.defaultValue;
209+
}
210+
211+
if (this.overwrites) {
212+
result.overwrites = this.overwrites.toObject();
213+
}
214+
215+
if (this.inheritedFrom) {
216+
result.inheritedFrom = this.inheritedFrom.toObject();
217+
}
218+
219+
if (this.extendedTypes) {
220+
result.extendedTypes = this.extendedTypes.map((t) => t.toObject());
221+
}
222+
223+
if (this.extendedBy) {
224+
result.extendedBy = this.extendedBy.map((t) => t.toObject());
225+
}
226+
227+
if (this.implementedTypes) {
228+
result.implementedTypes = this.implementedTypes.map((t) => t.toObject());
229+
}
230+
231+
if (this.implementedBy) {
232+
result.implementedBy = this.implementedBy.map((t) => t.toObject());
233+
}
234+
208235
return result;
209236
}
210237

src/td/models/reflections/ParameterReflection.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,24 @@ module td
2626
}
2727

2828

29+
/**
30+
* Return a raw object representation of this reflection.
31+
*/
32+
toObject():any {
33+
var result = super.toObject();
34+
35+
if (this.type) {
36+
result.type = this.type.toObject();
37+
}
38+
39+
if (this.defaultValue) {
40+
result.defaultValue = this.defaultValue;
41+
}
42+
43+
return result;
44+
}
45+
46+
2947
/**
3048
* Return a string representation of this reflection.
3149
*/

src/td/models/reflections/SignatureReflection.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,36 @@ module td
5151
}
5252

5353

54+
/**
55+
* Return a raw object representation of this reflection.
56+
*/
57+
toObject():any {
58+
var result = super.toObject();
59+
60+
if (this.parameters && this.parameters.length) {
61+
result.parameters = this.parameters.map((n) => n.toObject());
62+
}
63+
64+
if (this.typeParameters && this.typeParameters.length) {
65+
result.typeParameters = this.typeParameters.map((n) => n.toObject());
66+
}
67+
68+
if (this.type) {
69+
result.type = this.type.toObject();
70+
}
71+
72+
if (this.overwrites) {
73+
result.overwrites = this.overwrites.toObject();
74+
}
75+
76+
if (this.inheritedFrom) {
77+
result.inheritedFrom = this.inheritedFrom.toObject();
78+
}
79+
80+
return result;
81+
}
82+
83+
5484
/**
5585
* Return a string representation of this reflection.
5686
*/

src/td/models/reflections/TypeParameterReflection.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,19 @@ module td
1414
super(parent, type.name, ReflectionKind.TypeParameter);
1515
this.type = type.constraint;
1616
}
17+
18+
19+
/**
20+
* Return a raw object representation of this reflection.
21+
*/
22+
toObject():any {
23+
var result = super.toObject();
24+
25+
if (this.type) {
26+
result.type = this.type.toObject();
27+
}
28+
29+
return result;
30+
}
1731
}
1832
}

src/td/models/types/IntrinsicType.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,46 @@
11
module td
22
{
3+
/**
4+
* Represents an intrinsic type like `string` or `boolean`.
5+
*
6+
* ~~~
7+
* var value:number;
8+
* ~~~
9+
*/
310
export class IntrinsicType extends Type
411
{
12+
/**
13+
* The name of the intrinsic type like `string` or `boolean`.
14+
*/
515
name:string;
616

717

18+
19+
/**
20+
* Create a new instance of IntrinsicType.
21+
*
22+
* @param name The name of the intrinsic type like `string` or `boolean`.
23+
*/
824
constructor(name:string) {
925
super();
1026
this.name = name;
1127
}
1228

1329

30+
/**
31+
* Return a raw object representation of this type.
32+
*/
33+
toObject():any {
34+
var result:any = super.toObject();
35+
result.type = 'instrinct';
36+
result.name = this.name;
37+
return result;
38+
}
39+
40+
41+
/**
42+
* Return a string representation of this type.
43+
*/
1444
toString() {
1545
return this.name + (this.isArray ? '[]' : '');
1646
}

src/td/models/types/ReferenceType.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,46 @@
11
module td
22
{
3+
/**
4+
* Represents a type that refers to another reflection like a class, interface or enum.
5+
*
6+
* ~~~
7+
* var value:MyClass;
8+
* ~~~
9+
*/
310
export class ReferenceType extends Type
411
{
12+
/**
13+
* The name of the referenced type.
14+
*
15+
* If the symbol cannot be found cause it's not part of the documentation this
16+
* can be used to represent the type.
17+
*/
518
name:string;
619

20+
/**
21+
* The symbol id of the referenced type as returned from the TypeScript compiler.
22+
*
23+
* After the all reflections have been generated this is can be used to lookup the
24+
* relevant reflection with [[ProjectReflection.symbolMapping]].
25+
*/
726
symbolID:number;
827

28+
/**
29+
* The resolved reflection.
30+
*
31+
* The [[TypePlugin]] will try to set this property in the resolving phase.
32+
*/
933
reflection:Reflection;
1034

1135

36+
37+
/**
38+
* Create a new instance of ReferenceType.
39+
*
40+
* @param name The name of the referenced type.
41+
* @param symbolID The symbol id of the referenced type as returned from the TypeScript compiler.
42+
* @param reflection The resolved reflection if already known.
43+
*/
1244
constructor(name:string, symbolID:number, reflection?:Reflection) {
1345
super();
1446
this.name = name;
@@ -17,6 +49,21 @@ module td
1749
}
1850

1951

52+
/**
53+
* Return a raw object representation of this type.
54+
*/
55+
toObject():any {
56+
var result:any = super.toObject();
57+
result.type = 'reference';
58+
result.name = this.name;
59+
result.symbolID = this.symbolID;
60+
return result;
61+
}
62+
63+
64+
/**
65+
* Return a string representation of this type.
66+
*/
2067
toString() {
2168
if (this.reflection) {
2269
return this.reflection.name + (this.isArray ? '[]' : '');

src/td/models/types/ReflectionType.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,50 @@
11
module td
22
{
3-
3+
/**
4+
* Represents a type which has it's own reflection like literal types.
5+
*
6+
* ~~~
7+
* var value:{subValueA;subValueB;subValueC;};
8+
* ~~~
9+
*/
410
export class ReflectionType extends Type
511
{
12+
/**
13+
* The reflection of the type.
14+
*/
615
declaration:DeclarationReflection;
716

817

18+
19+
/**
20+
* Create a new instance of ReflectionType.
21+
*
22+
* @param declaration The reflection of the type.
23+
*/
924
constructor(declaration:DeclarationReflection) {
1025
super();
1126
this.declaration = declaration;
1227
}
1328

1429

30+
/**
31+
* Return a raw object representation of this type.
32+
*/
33+
toObject():any {
34+
var result:any = super.toObject();
35+
result.type = 'reflection';
36+
37+
if (this.declaration) {
38+
result.declaration = this.declaration.toObject();
39+
}
40+
41+
return result;
42+
}
43+
44+
45+
/**
46+
* Return a string representation of this type.
47+
*/
1548
toString() {
1649
if (!this.declaration.children && this.declaration.signatures) {
1750
return 'function';

0 commit comments

Comments
 (0)