Skip to content

Commit 157d896

Browse files
Bugfix: Duplicate properties on inheriting class when using constructor public, resolves #81
1 parent ce3930a commit 157d896

File tree

8 files changed

+426
-21
lines changed

8 files changed

+426
-21
lines changed

bin/typedoc.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,6 +1818,7 @@ declare module td.models {
18181818
Optional = 128,
18191819
DefaultValue = 256,
18201820
Rest = 512,
1821+
ConstructorProperty = 1024,
18211822
}
18221823
interface IReflectionFlags extends Array<string> {
18231824
flags?: ReflectionFlag;
@@ -1859,6 +1860,7 @@ declare module td.models {
18591860
*
18601861
*/
18611862
hasExportAssignment?: boolean;
1863+
isConstructorProperty?: boolean;
18621864
}
18631865
interface IDefaultValueContainer extends Reflection {
18641866
defaultValue: string;

bin/typedoc.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3232,9 +3232,15 @@ var td;
32323232
return null;
32333233
}
32343234
// Test whether the node is static, when merging a module to a class make the node static
3235+
var isConstructorProperty = false;
32353236
var isStatic = !!(node.flags & 128 /* Static */);
3236-
if (container.kind == 128 /* Class */ && (!node.parent || node.parent.kind != 185 /* ClassDeclaration */)) {
3237-
isStatic = true;
3237+
if (container.kind == 128 /* Class */) {
3238+
if (node.parent && node.parent.kind == 126 /* Constructor */) {
3239+
isConstructorProperty = true;
3240+
}
3241+
else if (!node.parent || node.parent.kind != 185 /* ClassDeclaration */) {
3242+
isStatic = true;
3243+
}
32383244
}
32393245
// Check if we already have a child with the same name and static flag
32403246
var child;
@@ -3248,6 +3254,7 @@ var td;
32483254
child = new td.models.DeclarationReflection(container, name, kind);
32493255
child.setFlag(8 /* Static */, isStatic);
32503256
child.setFlag(1 /* Private */, isPrivate);
3257+
child.setFlag(1024 /* ConstructorProperty */, isConstructorProperty);
32513258
child = setupDeclaration(context, child, node);
32523259
if (child) {
32533260
children.push(child);
@@ -3279,7 +3286,7 @@ var td;
32793286
reflection.setFlag(4 /* Public */, !!(node.flags & 16 /* Public */));
32803287
reflection.setFlag(128 /* Optional */, !!(node['questionToken']));
32813288
reflection.setFlag(16 /* Exported */, reflection.parent.flags.isExported || !!(node.flags & 1 /* Export */));
3282-
if (context.isInherit && node.parent == context.inheritParent) {
3289+
if (context.isInherit && (node.parent == context.inheritParent || reflection.flags.isConstructorProperty)) {
32833290
if (!reflection.inheritedFrom) {
32843291
reflection.inheritedFrom = createReferenceType(context, node.symbol, true);
32853292
reflection.getAllSignatures().forEach(function (signature) {
@@ -3307,7 +3314,7 @@ var td;
33073314
reflection.kind = kind;
33083315
}
33093316
}
3310-
if (context.isInherit && node.parent == context.inheritParent && context.inherited.indexOf(reflection.name) != -1) {
3317+
if (context.isInherit && context.inherited.indexOf(reflection.name) != -1 && (node.parent == context.inheritParent || reflection.flags.isConstructorProperty)) {
33113318
if (!reflection.overwrites) {
33123319
reflection.overwrites = createReferenceType(context, node.symbol, true);
33133320
reflection.getAllSignatures().forEach(function (signature) {
@@ -5047,6 +5054,7 @@ var td;
50475054
ReflectionFlag[ReflectionFlag["Optional"] = 128] = "Optional";
50485055
ReflectionFlag[ReflectionFlag["DefaultValue"] = 256] = "DefaultValue";
50495056
ReflectionFlag[ReflectionFlag["Rest"] = 512] = "Rest";
5057+
ReflectionFlag[ReflectionFlag["ConstructorProperty"] = 1024] = "ConstructorProperty";
50505058
})(models.ReflectionFlag || (models.ReflectionFlag = {}));
50515059
var ReflectionFlag = models.ReflectionFlag;
50525060
var relevantFlags = [
@@ -5141,7 +5149,7 @@ var td;
51415149
index = this.flags.indexOf(name);
51425150
}
51435151
if (value) {
5144-
this.flags.flags &= flag;
5152+
this.flags.flags |= flag;
51455153
if (name && index == -1) {
51465154
this.flags.push(name);
51475155
}
@@ -5192,6 +5200,9 @@ var td;
51925200
case 32 /* ExportAssignment */:
51935201
this.flags.hasExportAssignment = value;
51945202
break;
5203+
case 1024 /* ConstructorProperty */:
5204+
this.flags.isConstructorProperty = value;
5205+
break;
51955206
}
51965207
};
51975208
/**
@@ -5293,7 +5304,7 @@ var td;
52935304
result.comment = this.comment.toObject();
52945305
}
52955306
for (var key in this.flags) {
5296-
if (parseInt(key) == key)
5307+
if (parseInt(key) == key || key == 'flags')
52975308
continue;
52985309
if (this.flags[key])
52995310
result.flags[key] = true;

src/td/converter/converters/factories.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,14 @@ module td.converter
2929
}
3030

3131
// Test whether the node is static, when merging a module to a class make the node static
32+
var isConstructorProperty:boolean = false;
3233
var isStatic = !!(node.flags & ts.NodeFlags.Static);
33-
if (container.kind == models.ReflectionKind.Class && (!node.parent || node.parent.kind != ts.SyntaxKind.ClassDeclaration)) {
34-
isStatic = true;
34+
if (container.kind == models.ReflectionKind.Class) {
35+
if (node.parent && node.parent.kind == ts.SyntaxKind.Constructor) {
36+
isConstructorProperty = true;
37+
} else if (!node.parent || node.parent.kind != ts.SyntaxKind.ClassDeclaration) {
38+
isStatic = true;
39+
}
3540
}
3641

3742
// Check if we already have a child with the same name and static flag
@@ -46,6 +51,7 @@ module td.converter
4651
child = new models.DeclarationReflection(container, name, kind);
4752
child.setFlag(models.ReflectionFlag.Static, isStatic);
4853
child.setFlag(models.ReflectionFlag.Private, isPrivate);
54+
child.setFlag(models.ReflectionFlag.ConstructorProperty, isConstructorProperty);
4955
child = setupDeclaration(context, child, node);
5056

5157
if (child) {
@@ -81,7 +87,10 @@ module td.converter
8187
reflection.setFlag(models.ReflectionFlag.Optional, !!(node['questionToken']));
8288
reflection.setFlag(models.ReflectionFlag.Exported, reflection.parent.flags.isExported || !!(node.flags & ts.NodeFlags.Export));
8389

84-
if (context.isInherit && node.parent == context.inheritParent) {
90+
if (
91+
context.isInherit &&
92+
(node.parent == context.inheritParent || reflection.flags.isConstructorProperty)
93+
) {
8594
if (!reflection.inheritedFrom) {
8695
reflection.inheritedFrom = createReferenceType(context, node.symbol, true);
8796
reflection.getAllSignatures().forEach((signature) => {
@@ -113,7 +122,11 @@ module td.converter
113122
}
114123
}
115124

116-
if (context.isInherit && node.parent == context.inheritParent && context.inherited.indexOf(reflection.name) != -1) {
125+
if (
126+
context.isInherit &&
127+
context.inherited.indexOf(reflection.name) != -1 &&
128+
(node.parent == context.inheritParent || reflection.flags.isConstructorProperty)
129+
) {
117130
if (!reflection.overwrites) {
118131
reflection.overwrites = createReferenceType(context, node.symbol, true);
119132
reflection.getAllSignatures().forEach((signature) => {

src/td/models/Reflection.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ module td.models
7474
External = 64,
7575
Optional = 128,
7676
DefaultValue = 256,
77-
Rest = 512
77+
Rest = 512,
78+
ConstructorProperty = 1024
7879
}
7980

8081

@@ -140,6 +141,8 @@ module td.models
140141
*
141142
*/
142143
hasExportAssignment?:boolean;
144+
145+
isConstructorProperty?:boolean;
143146
}
144147

145148

@@ -336,7 +339,7 @@ module td.models
336339
}
337340

338341
if (value) {
339-
this.flags.flags &= flag;
342+
this.flags.flags |= flag;
340343
if (name && index == -1) {
341344
this.flags.push(name);
342345
}
@@ -387,6 +390,9 @@ module td.models
387390
case ReflectionFlag.ExportAssignment:
388391
this.flags.hasExportAssignment = value;
389392
break;
393+
case ReflectionFlag.ConstructorProperty:
394+
this.flags.isConstructorProperty = value;
395+
break;
390396
}
391397
}
392398

@@ -528,7 +534,7 @@ module td.models
528534
}
529535

530536
for (var key in this.flags) {
531-
if (parseInt(key) == key) continue;
537+
if (parseInt(key) == key || key == 'flags') continue;
532538
if (this.flags[key]) result.flags[key] = true;
533539
}
534540

test/converter/class/specs.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@
369369
"kindString": "Property",
370370
"flags": {
371371
"isPrivate": true,
372+
"isConstructorProperty": true,
372373
"isExported": true
373374
},
374375
"comment": {
@@ -385,6 +386,7 @@
385386
"kind": 1024,
386387
"kindString": "Property",
387388
"flags": {
389+
"isConstructorProperty": true,
388390
"isPublic": true,
389391
"isExported": true
390392
},
@@ -402,6 +404,7 @@
402404
"kind": 1024,
403405
"kindString": "Property",
404406
"flags": {
407+
"isConstructorProperty": true,
405408
"isPublic": true,
406409
"isExported": true
407410
},
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/// <reference path="../lib.core.d.ts" />
2+
3+
4+
/**
5+
* A class with constructor properties.
6+
*/
7+
class Vector2
8+
{
9+
/**
10+
* @param x X component of the Vector
11+
* @param y Y component of the Vector
12+
*/
13+
constructor(public x:number, public y:number) {
14+
}
15+
}
16+
17+
18+
/**
19+
* A class with inherited and overwritten constructor properties.
20+
*/
21+
class Vector3 extends Vector2
22+
{
23+
/**
24+
* @param x X component of the Vector
25+
* @param y Y component of the Vector
26+
* @param z Z component of the Vector
27+
*/
28+
constructor(x:number, public y:number, public z:number) {
29+
super(x, y);
30+
}
31+
}

0 commit comments

Comments
 (0)