@@ -9,7 +9,12 @@ import {
9
9
TypeParameterReflection ,
10
10
} from "../models" ;
11
11
import { flatMap , uniqueByEquals } from "../utils/array" ;
12
- import { getEnumFlags , hasAllFlags , removeFlag } from "../utils/enum" ;
12
+ import {
13
+ getEnumFlags ,
14
+ hasAllFlags ,
15
+ hasAnyFlag ,
16
+ removeFlag ,
17
+ } from "../utils/enum" ;
13
18
import { Context } from "./context" ;
14
19
import { convertDefaultValue } from "./convert-expression" ;
15
20
import { ConverterEvents } from "./converter-events" ;
@@ -87,7 +92,10 @@ export function convertSymbol(
87
92
// that TD supports is merging a class and interface. All others are
88
93
// represented as multiple reflections
89
94
if ( hasAllFlags ( symbol . flags , ts . SymbolFlags . Class ) ) {
90
- flags = removeFlag ( flags , ts . SymbolFlags . Interface ) ;
95
+ flags = removeFlag (
96
+ flags ,
97
+ ts . SymbolFlags . Interface | ts . SymbolFlags . Function
98
+ ) ;
91
99
}
92
100
93
101
// Kind of declaration merging... we treat this as a property with get/set signatures.
@@ -166,15 +174,15 @@ function convertNamespace(
166
174
symbol : ts . Symbol ,
167
175
nameOverride ?: string
168
176
) {
169
- // This can happen in JS land where a user defines a class using a mixture
170
- // of ES6 class syntax and adding properties to the class manually.
171
- if (
172
- symbol
173
- . getDeclarations ( )
174
- ?. some ( ( d ) => ts . isModuleDeclaration ( d ) || ts . isSourceFile ( d ) ) ===
175
- false
176
- ) {
177
- return ;
177
+ let exportFlags = ts . SymbolFlags . ModuleMember ;
178
+
179
+ // This can happen in JS land where "class" functions get tagged as a namespace too
180
+ if ( symbol . getDeclarations ( ) ?. some ( ts . isModuleDeclaration ) !== true ) {
181
+ exportFlags = ts . SymbolFlags . ClassMember ;
182
+
183
+ if ( hasAnyFlag ( symbol . flags , ts . SymbolFlags . Class ) ) {
184
+ return ;
185
+ }
178
186
}
179
187
180
188
const reflection = context . createDeclarationReflection (
@@ -185,7 +193,7 @@ function convertNamespace(
185
193
186
194
convertSymbols (
187
195
context . withScope ( reflection ) ,
188
- getSymbolExportsWithFlag ( symbol , ts . SymbolFlags . ModuleMember )
196
+ getSymbolExportsWithFlag ( symbol , exportFlags )
189
197
) ;
190
198
}
191
199
@@ -304,7 +312,13 @@ function convertFunctionOrMethod(
304
312
const signatures = type . getCallSignatures ( ) ;
305
313
306
314
const reflection = context . createDeclarationReflection (
307
- isMethod ? ReflectionKind . Method : ReflectionKind . Function ,
315
+ context . scope . kindOf (
316
+ ReflectionKind . ClassOrInterface |
317
+ ReflectionKind . VariableOrProperty |
318
+ ReflectionKind . TypeLiteral
319
+ )
320
+ ? ReflectionKind . Method
321
+ : ReflectionKind . Function ,
308
322
symbol ,
309
323
nameOverride
310
324
) ;
@@ -360,7 +374,7 @@ function convertClassOrInterface(
360
374
361
375
const classDeclaration = symbol
362
376
. getDeclarations ( )
363
- ?. find ( ts . isClassDeclaration ) ;
377
+ ?. find ( ( d ) => ts . isClassDeclaration ( d ) || ts . isFunctionDeclaration ( d ) ) ;
364
378
if ( classDeclaration ) {
365
379
setModifiers ( classDeclaration , reflection ) ;
366
380
@@ -544,7 +558,9 @@ function convertProperty(
544
558
}
545
559
546
560
const reflection = context . createDeclarationReflection (
547
- ReflectionKind . Property ,
561
+ context . scope . kindOf ( ReflectionKind . Namespace )
562
+ ? ReflectionKind . Variable
563
+ : ReflectionKind . Property ,
548
564
symbol ,
549
565
nameOverride
550
566
) ;
0 commit comments