Skip to content

Commit c392b1a

Browse files
sebavanaciccarello
authored andcommitted
Fix interface merging flagged as static (#807)
* Fix interface merging flagged as static * update static interface merging spec
1 parent eace04a commit c392b1a

File tree

4 files changed

+186
-10
lines changed

4 files changed

+186
-10
lines changed

src/lib/converter/factories/declaration.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ const nonStaticKinds = [
1414
ReflectionKind.Module
1515
];
1616

17+
/**
18+
* List of ts kinds leading to none static merge.
19+
*/
20+
const nonStaticMergeKinds = [
21+
ts.SyntaxKind.ClassDeclaration,
22+
ts.SyntaxKind.InterfaceDeclaration
23+
];
24+
1725
/**
1826
* Create a declaration reflection from the given TypeScript node.
1927
*
@@ -78,7 +86,7 @@ export function createDeclaration(context: Context, node: ts.Declaration, kind:
7886
if (container.kind === ReflectionKind.Class) {
7987
if (node.parent && node.parent.kind === ts.SyntaxKind.Constructor) {
8088
isConstructorProperty = true;
81-
} else if (!node.parent || node.parent.kind !== ts.SyntaxKind.ClassDeclaration) {
89+
} else if (!node.parent || nonStaticMergeKinds.indexOf(node.parent.kind) === -1) {
8290
isStatic = true;
8391
}
8492
}

src/test/converter/class/class.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,20 @@ export class TestAbstractClassImplementation extends TestAbstractClass {
8484
protected myAbstractMethod(): void { }
8585
}
8686

87+
export interface TestSubClass {
88+
/**
89+
* mergedMethod short text.
90+
*/
91+
mergedMethod();
92+
}
93+
94+
export module TestSubClass {
95+
/**
96+
* staticMergedMethod short text.
97+
*/
98+
export function staticMergedMethod() { }
99+
}
100+
87101
/**
88102
* This class will not appear when `excludeNotExported=true`
89103
*/

src/test/converter/class/specs-without-exported.json

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,38 @@
768768
"id": 5
769769
}
770770
},
771+
{
772+
"id": 42,
773+
"name": "mergedMethod",
774+
"kind": 2048,
775+
"kindString": "Method",
776+
"flags": {
777+
"isExported": true
778+
},
779+
"signatures": [
780+
{
781+
"id": 43,
782+
"name": "mergedMethod",
783+
"kind": 4096,
784+
"kindString": "Call signature",
785+
"flags": {},
786+
"comment": {
787+
"shortText": "mergedMethod short text."
788+
},
789+
"type": {
790+
"type": "intrinsic",
791+
"name": "any"
792+
}
793+
}
794+
],
795+
"sources": [
796+
{
797+
"fileName": "class.ts",
798+
"line": 91,
799+
"character": 16
800+
}
801+
]
802+
},
771803
{
772804
"id": 19,
773805
"name": "protectedMethod",
@@ -854,6 +886,39 @@
854886
"id": 8
855887
}
856888
},
889+
{
890+
"id": 44,
891+
"name": "staticMergedMethod",
892+
"kind": 2048,
893+
"kindString": "Method",
894+
"flags": {
895+
"isStatic": true,
896+
"isExported": true
897+
},
898+
"signatures": [
899+
{
900+
"id": 45,
901+
"name": "staticMergedMethod",
902+
"kind": 4096,
903+
"kindString": "Call signature",
904+
"flags": {},
905+
"comment": {
906+
"shortText": "staticMergedMethod short text."
907+
},
908+
"type": {
909+
"type": "intrinsic",
910+
"name": "void"
911+
}
912+
}
913+
],
914+
"sources": [
915+
{
916+
"fileName": "class.ts",
917+
"line": 98,
918+
"character": 38
919+
}
920+
]
921+
},
857922
{
858923
"id": 32,
859924
"name": "staticMethod",
@@ -921,8 +986,10 @@
921986
"title": "Methods",
922987
"kind": 2048,
923988
"children": [
989+
42,
924990
19,
925991
17,
992+
44,
926993
32
927994
]
928995
}
@@ -932,6 +999,16 @@
932999
"fileName": "class.ts",
9331000
"line": 51,
9341001
"character": 25
1002+
},
1003+
{
1004+
"fileName": "class.ts",
1005+
"line": 87,
1006+
"character": 29
1007+
},
1008+
{
1009+
"fileName": "class.ts",
1010+
"line": 94,
1011+
"character": 26
9351012
}
9361013
],
9371014
"extendedTypes": [

src/test/converter/class/specs.json

Lines changed: 86 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"originalName": "%BASE%/class/class.ts",
1616
"children": [
1717
{
18-
"id": 42,
18+
"id": 44,
1919
"name": "NotExportedClass",
2020
"kind": 128,
2121
"kindString": "Class",
@@ -27,14 +27,14 @@
2727
},
2828
"children": [
2929
{
30-
"id": 43,
30+
"id": 45,
3131
"name": "add",
3232
"kind": 2048,
3333
"kindString": "Method",
3434
"flags": {},
3535
"signatures": [
3636
{
37-
"id": 44,
37+
"id": 46,
3838
"name": "add",
3939
"kind": 4096,
4040
"kindString": "Call signature",
@@ -44,7 +44,7 @@
4444
},
4545
"parameters": [
4646
{
47-
"id": 45,
47+
"id": 47,
4848
"name": "a",
4949
"kind": 32768,
5050
"kindString": "Parameter",
@@ -55,7 +55,7 @@
5555
}
5656
},
5757
{
58-
"id": 46,
58+
"id": 48,
5959
"name": "b",
6060
"kind": 32768,
6161
"kindString": "Parameter",
@@ -75,7 +75,7 @@
7575
"sources": [
7676
{
7777
"fileName": "class.ts",
78-
"line": 94,
78+
"line": 108,
7979
"character": 7
8080
}
8181
]
@@ -86,14 +86,14 @@
8686
"title": "Methods",
8787
"kind": 2048,
8888
"children": [
89-
43
89+
45
9090
]
9191
}
9292
],
9393
"sources": [
9494
{
9595
"fileName": "class.ts",
96-
"line": 90,
96+
"line": 104,
9797
"character": 31
9898
}
9999
]
@@ -852,6 +852,38 @@
852852
"id": 5
853853
}
854854
},
855+
{
856+
"id": 42,
857+
"name": "mergedMethod",
858+
"kind": 2048,
859+
"kindString": "Method",
860+
"flags": {
861+
"isExported": true
862+
},
863+
"signatures": [
864+
{
865+
"id": 43,
866+
"name": "mergedMethod",
867+
"kind": 4096,
868+
"kindString": "Call signature",
869+
"flags": {},
870+
"comment": {
871+
"shortText": "mergedMethod short text."
872+
},
873+
"type": {
874+
"type": "intrinsic",
875+
"name": "any"
876+
}
877+
}
878+
],
879+
"sources": [
880+
{
881+
"fileName": "class.ts",
882+
"line": 91,
883+
"character": 16
884+
}
885+
]
886+
},
855887
{
856888
"id": 19,
857889
"name": "protectedMethod",
@@ -938,6 +970,39 @@
938970
"id": 8
939971
}
940972
},
973+
{
974+
"id": 49,
975+
"name": "staticMergedMethod",
976+
"kind": 2048,
977+
"kindString": "Method",
978+
"flags": {
979+
"isStatic": true,
980+
"isExported": true
981+
},
982+
"signatures": [
983+
{
984+
"id": 50,
985+
"name": "staticMergedMethod",
986+
"kind": 4096,
987+
"kindString": "Call signature",
988+
"flags": {},
989+
"comment": {
990+
"shortText": "staticMergedMethod short text."
991+
},
992+
"type": {
993+
"type": "intrinsic",
994+
"name": "void"
995+
}
996+
}
997+
],
998+
"sources": [
999+
{
1000+
"fileName": "class.ts",
1001+
"line": 98,
1002+
"character": 38
1003+
}
1004+
]
1005+
},
9411006
{
9421007
"id": 32,
9431008
"name": "staticMethod",
@@ -1005,8 +1070,10 @@
10051070
"title": "Methods",
10061071
"kind": 2048,
10071072
"children": [
1073+
42,
10081074
19,
10091075
17,
1076+
49,
10101077
32
10111078
]
10121079
}
@@ -1016,6 +1083,16 @@
10161083
"fileName": "class.ts",
10171084
"line": 51,
10181085
"character": 25
1086+
},
1087+
{
1088+
"fileName": "class.ts",
1089+
"line": 87,
1090+
"character": 29
1091+
},
1092+
{
1093+
"fileName": "class.ts",
1094+
"line": 94,
1095+
"character": 26
10191096
}
10201097
],
10211098
"extendedTypes": [
@@ -1032,7 +1109,7 @@
10321109
"title": "Classes",
10331110
"kind": 128,
10341111
"children": [
1035-
42,
1112+
44,
10361113
34,
10371114
38,
10381115
2,

0 commit comments

Comments
 (0)