Skip to content

Commit 28f821e

Browse files
Call signatures are not merged correctly, resolves #27
1 parent eef59bb commit 28f821e

File tree

7 files changed

+55
-25
lines changed

7 files changed

+55
-25
lines changed

bin/typedoc.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,7 @@ declare module TypeDoc.Factories {
786786
*/
787787
public createSignatureState(): DeclarationState;
788788
public createInheritanceState(declaration: TypeScript.PullDecl): DeclarationState;
789+
public getReflectionName(): string;
789790
}
790791
}
791792
declare module TypeDoc.Factories {

bin/typedoc.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2043,7 +2043,7 @@ var TypeDoc;
20432043

20442044
var parent = state.parentState.reflection;
20452045
var reflection = new TypeDoc.Models.DeclarationReflection();
2046-
reflection.name = (state.flattenedName ? state.flattenedName + '.' : '') + state.getName();
2046+
reflection.name = state.getReflectionName();
20472047
reflection.originalName = state.declaration.name;
20482048
reflection.parent = parent;
20492049

@@ -2114,7 +2114,7 @@ var TypeDoc;
21142114

21152115
Dispatcher.EVENT_CREATE_REFLECTION = 'createReflection';
21162116

2117-
Dispatcher.EVENT_MERGE_REFLECTION = Dispatcher.EVENT_MERGE_REFLECTION;
2117+
Dispatcher.EVENT_MERGE_REFLECTION = 'mergeReflection';
21182118

21192119
Dispatcher.EVENT_BEGIN_DECLARATION = 'beginDeclaration';
21202120

@@ -2290,7 +2290,7 @@ var TypeDoc;
22902290
var reflection = null;
22912291
var name = BaseState.getName(declaration);
22922292
this.reflection.children.some(function (child) {
2293-
if (child.name != name)
2293+
if (child.originalName != name)
22942294
return false;
22952295
if ((child.flags & TypeScript.PullElementFlags.Static) != (declaration.flags & TypeScript.PullElementFlags.Static))
22962296
return false;
@@ -2342,8 +2342,7 @@ var TypeDoc;
23422342
}
23432343

23442344
if (state.isFlattened) {
2345-
// state.parentState = this.parentState;
2346-
state.flattenedName = this.flattenedName + '.' + declaration.name;
2345+
state.flattenedName = this.flattenedName + '.' + state.getName();
23472346
}
23482347

23492348
return state;
@@ -2374,6 +2373,20 @@ var TypeDoc;
23742373
state.isInherited = true;
23752374
return state;
23762375
};
2376+
2377+
DeclarationState.prototype.getReflectionName = function () {
2378+
if (this.flattenedName) {
2379+
if (this.kindOf(TypeScript.PullElementKind.CallSignature)) {
2380+
return this.flattenedName + '()';
2381+
} else if (this.kindOf(TypeScript.PullElementKind.IndexSignature)) {
2382+
return this.flattenedName + '[]';
2383+
} else {
2384+
return this.flattenedName + '.' + this.getName();
2385+
}
2386+
} else {
2387+
return this.getName();
2388+
}
2389+
};
23772390
return DeclarationState;
23782391
})(Factories.BaseState);
23792392
Factories.DeclarationState = DeclarationState;
@@ -3990,22 +4003,14 @@ var TypeDoc;
39904003
state.reflection.kind = Factories.ReflectionHandler.mergeKinds(state.reflection.kind, TypeScript.PullElementKind.ObjectLiteral);
39914004
literal.getChildDecls().forEach(function (declaration) {
39924005
var childState = state.createChildState(declaration);
3993-
39944006
_this.dispatcher.processState(childState);
3995-
if (childState.reflection && childState.kindOf(TypeScript.PullElementKind.IndexSignature)) {
3996-
childState.reflection.name = state.reflection.name + ' index signature';
3997-
}
39984007
});
39994008
} else {
40004009
literal.getChildDecls().forEach(function (declaration) {
40014010
var childState = state.createChildState(declaration);
40024011
childState.isFlattened = true;
40034012
childState.flattenedName = state.flattenedName ? state.flattenedName + '.' + state.declaration.name : state.getName();
4004-
40054013
_this.dispatcher.processState(childState);
4006-
if (childState.reflection && childState.kindOf(TypeScript.PullElementKind.IndexSignature)) {
4007-
childState.reflection.name = state.reflection.name + ' index signature';
4008-
}
40094014
});
40104015
}
40114016

examples/basic/src/flattened.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,24 @@ class flattenedClass
3838
test:string;
3939
};
4040

41+
/**
42+
* An object with multiple call signatures.
43+
* @see https://github.com/sebastian-lenz/typedoc/issues/27
44+
*/
45+
public multipleCallSignatures: {
46+
/**
47+
* Simple call signature.
48+
* @returns The current value.
49+
*/
50+
(): number;
51+
/**
52+
* Call signature with parameters.
53+
* @param value The desired value.
54+
* @returns The calling Foo.
55+
*/
56+
(value:number):flattenedClass;
57+
};
58+
4159

4260
/**
4361
* A constructor that accepts an option object defined inline.

src/typedoc/factories/Dispatcher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ module TypeDoc.Factories
284284

285285
var parent = <Models.DeclarationReflection>state.parentState.reflection;
286286
var reflection = new Models.DeclarationReflection();
287-
reflection.name = (state.flattenedName ? state.flattenedName + '.' : '') + state.getName();
287+
reflection.name = state.getReflectionName();
288288
reflection.originalName = state.declaration.name;
289289
reflection.parent = parent;
290290

src/typedoc/factories/events/BaseState.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ module TypeDoc.Factories
144144
var reflection:Models.DeclarationReflection = null;
145145
var name = BaseState.getName(declaration);
146146
this.reflection.children.some((child) => {
147-
if (child.name != name) return false;
147+
if (child.originalName != name) return false;
148148
if ((child.flags & TypeScript.PullElementFlags.Static) !=
149149
(declaration.flags & TypeScript.PullElementFlags.Static)) return false;
150150

src/typedoc/factories/events/DeclarationState.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ module TypeDoc.Factories
2828
}
2929

3030
if (state.isFlattened) {
31-
// state.parentState = this.parentState;
32-
state.flattenedName = this.flattenedName + '.' + declaration.name;
31+
state.flattenedName = this.flattenedName + '.' + state.getName();
3332
}
3433

3534
return state;
@@ -62,5 +61,20 @@ module TypeDoc.Factories
6261
state.isInherited = true;
6362
return state;
6463
}
64+
65+
66+
getReflectionName():string {
67+
if (this.flattenedName) {
68+
if (this.kindOf(TypeScript.PullElementKind.CallSignature)) {
69+
return this.flattenedName + '()';
70+
} else if (this.kindOf(TypeScript.PullElementKind.IndexSignature)) {
71+
return this.flattenedName + '[]';
72+
} else {
73+
return this.flattenedName + '.' + this.getName();
74+
}
75+
} else {
76+
return this.getName();
77+
}
78+
}
6579
}
6680
}

src/typedoc/factories/handlers/ObjectLiteralHandler.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,14 @@ module TypeDoc.Factories
2929
state.reflection.kind = ReflectionHandler.mergeKinds(state.reflection.kind, TypeScript.PullElementKind.ObjectLiteral);
3030
literal.getChildDecls().forEach((declaration) => {
3131
var childState = state.createChildState(declaration);
32-
3332
this.dispatcher.processState(childState);
34-
if (childState.reflection && childState.kindOf(TypeScript.PullElementKind.IndexSignature)) {
35-
childState.reflection.name = state.reflection.name + ' index signature';
36-
}
3733
});
3834
} else {
3935
literal.getChildDecls().forEach((declaration) => {
4036
var childState = state.createChildState(declaration);
4137
childState.isFlattened = true;
4238
childState.flattenedName = state.flattenedName ? state.flattenedName + '.' + state.declaration.name : state.getName();
43-
4439
this.dispatcher.processState(childState);
45-
if (childState.reflection && childState.kindOf(TypeScript.PullElementKind.IndexSignature)) {
46-
childState.reflection.name = state.reflection.name + ' index signature';
47-
}
4840
});
4941
}
5042

0 commit comments

Comments
 (0)