typedoc 0.23.24 → 0.23.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -2
- package/dist/lib/application.d.ts +0 -2
- package/dist/lib/application.js +38 -14
- package/dist/lib/converter/comments/discovery.d.ts +1 -1
- package/dist/lib/converter/comments/discovery.js +77 -74
- package/dist/lib/converter/comments/index.d.ts +1 -1
- package/dist/lib/converter/comments/index.js +18 -15
- package/dist/lib/converter/comments/linkResolver.js +6 -3
- package/dist/lib/converter/context.d.ts +2 -2
- package/dist/lib/converter/context.js +6 -3
- package/dist/lib/converter/convert-expression.d.ts +1 -1
- package/dist/lib/converter/convert-expression.js +16 -13
- package/dist/lib/converter/converter.d.ts +1 -1
- package/dist/lib/converter/converter.js +12 -9
- package/dist/lib/converter/factories/index-signature.d.ts +1 -1
- package/dist/lib/converter/factories/index-signature.js +8 -5
- package/dist/lib/converter/factories/signature.d.ts +1 -1
- package/dist/lib/converter/factories/signature.js +32 -29
- package/dist/lib/converter/jsdoc.d.ts +1 -1
- package/dist/lib/converter/jsdoc.js +18 -15
- package/dist/lib/converter/plugins/CommentPlugin.d.ts +2 -0
- package/dist/lib/converter/plugins/CommentPlugin.js +19 -4
- package/dist/lib/converter/plugins/ImplementsPlugin.js +10 -7
- package/dist/lib/converter/plugins/PackagePlugin.js +25 -2
- package/dist/lib/converter/plugins/SourcePlugin.js +7 -4
- package/dist/lib/converter/symbols.d.ts +1 -1
- package/dist/lib/converter/symbols.js +129 -126
- package/dist/lib/converter/types.d.ts +1 -1
- package/dist/lib/converter/types.js +101 -98
- package/dist/lib/converter/utils/base-path.js +24 -1
- package/dist/lib/converter/utils/nodes.d.ts +1 -1
- package/dist/lib/converter/utils/nodes.js +5 -2
- package/dist/lib/converter/utils/symbols.d.ts +1 -1
- package/dist/lib/converter/utils/symbols.js +5 -2
- package/dist/lib/output/components.js +24 -1
- package/dist/lib/output/events.js +24 -1
- package/dist/lib/output/plugins/JavascriptIndexPlugin.js +24 -1
- package/dist/lib/output/renderer.js +25 -2
- package/dist/lib/output/themes/MarkedPlugin.js +26 -3
- package/dist/lib/serialization/index.js +24 -1
- package/dist/lib/utils/entry-point.d.ts +1 -1
- package/dist/lib/utils/entry-point.js +35 -9
- package/dist/lib/utils/fs.js +33 -3
- package/dist/lib/utils/general.js +24 -1
- package/dist/lib/utils/highlighter.js +24 -1
- package/dist/lib/utils/index.js +14 -2
- package/dist/lib/utils/loggers.d.ts +1 -1
- package/dist/lib/utils/loggers.js +9 -6
- package/dist/lib/utils/options/declaration.d.ts +1 -0
- package/dist/lib/utils/options/readers/tsconfig.js +8 -5
- package/dist/lib/utils/options/readers/typedoc.d.ts +1 -1
- package/dist/lib/utils/options/readers/typedoc.js +39 -5
- package/dist/lib/utils/options/sources/typedoc.js +79 -11
- package/dist/lib/utils/package-manifest.d.ts +1 -1
- package/dist/lib/utils/paths.d.ts +2 -2
- package/dist/lib/utils/plugins.js +25 -2
- package/dist/lib/validation/exports.js +5 -2
- package/package.json +12 -12
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.convertSymbol = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
7
|
+
const assert_1 = __importDefault(require("assert"));
|
|
8
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
6
9
|
const models_1 = require("../models");
|
|
7
10
|
const enum_1 = require("../utils/enum");
|
|
8
11
|
const convert_expression_1 = require("./convert-expression");
|
|
@@ -12,24 +15,24 @@ const jsdoc_1 = require("./jsdoc");
|
|
|
12
15
|
const nodes_1 = require("./utils/nodes");
|
|
13
16
|
const reflections_1 = require("./utils/reflections");
|
|
14
17
|
const symbolConverters = {
|
|
15
|
-
[
|
|
16
|
-
[
|
|
17
|
-
[
|
|
18
|
-
[
|
|
19
|
-
[
|
|
20
|
-
[
|
|
21
|
-
[
|
|
22
|
-
[
|
|
23
|
-
[
|
|
24
|
-
[
|
|
25
|
-
[
|
|
26
|
-
[
|
|
27
|
-
[
|
|
28
|
-
[
|
|
29
|
-
[
|
|
30
|
-
[
|
|
31
|
-
[
|
|
32
|
-
[
|
|
18
|
+
[typescript_1.default.SymbolFlags.RegularEnum]: convertEnum,
|
|
19
|
+
[typescript_1.default.SymbolFlags.ConstEnum]: convertEnum,
|
|
20
|
+
[typescript_1.default.SymbolFlags.EnumMember]: convertEnumMember,
|
|
21
|
+
[typescript_1.default.SymbolFlags.ValueModule]: convertNamespace,
|
|
22
|
+
[typescript_1.default.SymbolFlags.NamespaceModule]: convertNamespace,
|
|
23
|
+
[typescript_1.default.SymbolFlags.TypeAlias]: convertTypeAlias,
|
|
24
|
+
[typescript_1.default.SymbolFlags.Function]: convertFunctionOrMethod,
|
|
25
|
+
[typescript_1.default.SymbolFlags.Method]: convertFunctionOrMethod,
|
|
26
|
+
[typescript_1.default.SymbolFlags.Interface]: convertClassOrInterface,
|
|
27
|
+
[typescript_1.default.SymbolFlags.Property]: convertProperty,
|
|
28
|
+
[typescript_1.default.SymbolFlags.Class]: convertClassOrInterface,
|
|
29
|
+
[typescript_1.default.SymbolFlags.Constructor]: convertConstructor,
|
|
30
|
+
[typescript_1.default.SymbolFlags.Alias]: convertAlias,
|
|
31
|
+
[typescript_1.default.SymbolFlags.BlockScopedVariable]: convertVariable,
|
|
32
|
+
[typescript_1.default.SymbolFlags.FunctionScopedVariable]: convertVariable,
|
|
33
|
+
[typescript_1.default.SymbolFlags.ExportValue]: convertVariable,
|
|
34
|
+
[typescript_1.default.SymbolFlags.GetAccessor]: convertAccessor,
|
|
35
|
+
[typescript_1.default.SymbolFlags.SetAccessor]: convertAccessor,
|
|
33
36
|
};
|
|
34
37
|
const allConverterFlags = Object.keys(symbolConverters).reduce((v, k) => v | +k, 0);
|
|
35
38
|
// This is kind of a hack, born of resolving references by symbols instead
|
|
@@ -37,33 +40,33 @@ const allConverterFlags = Object.keys(symbolConverters).reduce((v, k) => v | +k,
|
|
|
37
40
|
const conversionOrder = [
|
|
38
41
|
// Do enums before namespaces so that @hidden on a namespace
|
|
39
42
|
// merged with an enum works properly.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
typescript_1.default.SymbolFlags.RegularEnum,
|
|
44
|
+
typescript_1.default.SymbolFlags.ConstEnum,
|
|
45
|
+
typescript_1.default.SymbolFlags.EnumMember,
|
|
43
46
|
// Before type alias
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
47
|
+
typescript_1.default.SymbolFlags.BlockScopedVariable,
|
|
48
|
+
typescript_1.default.SymbolFlags.FunctionScopedVariable,
|
|
49
|
+
typescript_1.default.SymbolFlags.ExportValue,
|
|
50
|
+
typescript_1.default.SymbolFlags.TypeAlias,
|
|
51
|
+
typescript_1.default.SymbolFlags.Function,
|
|
52
|
+
typescript_1.default.SymbolFlags.Method,
|
|
53
|
+
typescript_1.default.SymbolFlags.Interface,
|
|
54
|
+
typescript_1.default.SymbolFlags.Property,
|
|
55
|
+
typescript_1.default.SymbolFlags.Class,
|
|
56
|
+
typescript_1.default.SymbolFlags.Constructor,
|
|
57
|
+
typescript_1.default.SymbolFlags.Alias,
|
|
58
|
+
typescript_1.default.SymbolFlags.GetAccessor,
|
|
59
|
+
typescript_1.default.SymbolFlags.SetAccessor,
|
|
60
|
+
typescript_1.default.SymbolFlags.ValueModule,
|
|
61
|
+
typescript_1.default.SymbolFlags.NamespaceModule,
|
|
59
62
|
];
|
|
60
63
|
// Sanity check, if this fails a dev messed up.
|
|
61
64
|
for (const key of Object.keys(symbolConverters)) {
|
|
62
65
|
if (!Number.isInteger(Math.log2(+key))) {
|
|
63
|
-
throw new Error(`Symbol converter for key ${
|
|
66
|
+
throw new Error(`Symbol converter for key ${typescript_1.default.SymbolFlags[+key]} does not specify a valid flag value.`);
|
|
64
67
|
}
|
|
65
68
|
if (!conversionOrder.includes(+key)) {
|
|
66
|
-
throw new Error(`Symbol converter for key ${
|
|
69
|
+
throw new Error(`Symbol converter for key ${typescript_1.default.SymbolFlags[+key]} is not specified in conversionOrder`);
|
|
67
70
|
}
|
|
68
71
|
}
|
|
69
72
|
if (conversionOrder.reduce((a, b) => a | b, 0) !== allConverterFlags) {
|
|
@@ -81,44 +84,44 @@ function convertSymbol(context, symbol, exportSymbol) {
|
|
|
81
84
|
createAlias(previous, context, symbol, exportSymbol);
|
|
82
85
|
return;
|
|
83
86
|
}
|
|
84
|
-
let flags = (0, enum_1.removeFlag)(symbol.flags,
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
87
|
+
let flags = (0, enum_1.removeFlag)(symbol.flags, typescript_1.default.SymbolFlags.Transient |
|
|
88
|
+
typescript_1.default.SymbolFlags.Assignment |
|
|
89
|
+
typescript_1.default.SymbolFlags.Optional |
|
|
90
|
+
typescript_1.default.SymbolFlags.Prototype);
|
|
88
91
|
// Declaration merging - the only type (excluding enum/enum, ns/ns, etc)
|
|
89
92
|
// that TD supports is merging a class and interface. All others are
|
|
90
93
|
// represented as multiple reflections
|
|
91
|
-
if ((0, enum_1.hasAllFlags)(symbol.flags,
|
|
92
|
-
flags = (0, enum_1.removeFlag)(flags,
|
|
94
|
+
if ((0, enum_1.hasAllFlags)(symbol.flags, typescript_1.default.SymbolFlags.Class)) {
|
|
95
|
+
flags = (0, enum_1.removeFlag)(flags, typescript_1.default.SymbolFlags.Interface | typescript_1.default.SymbolFlags.Function);
|
|
93
96
|
}
|
|
94
97
|
// Kind of declaration merging... we treat this as a property with get/set signatures.
|
|
95
|
-
if ((0, enum_1.hasAllFlags)(symbol.flags,
|
|
96
|
-
flags = (0, enum_1.removeFlag)(flags,
|
|
98
|
+
if ((0, enum_1.hasAllFlags)(symbol.flags, typescript_1.default.SymbolFlags.GetAccessor)) {
|
|
99
|
+
flags = (0, enum_1.removeFlag)(flags, typescript_1.default.SymbolFlags.SetAccessor);
|
|
97
100
|
}
|
|
98
|
-
if ((0, enum_1.hasAllFlags)(symbol.flags,
|
|
101
|
+
if ((0, enum_1.hasAllFlags)(symbol.flags, typescript_1.default.SymbolFlags.NamespaceModule)) {
|
|
99
102
|
// This might be here if a namespace is declared several times.
|
|
100
|
-
flags = (0, enum_1.removeFlag)(flags,
|
|
103
|
+
flags = (0, enum_1.removeFlag)(flags, typescript_1.default.SymbolFlags.ValueModule);
|
|
101
104
|
}
|
|
102
|
-
if ((0, enum_1.hasAnyFlag)(symbol.flags,
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
105
|
+
if ((0, enum_1.hasAnyFlag)(symbol.flags, typescript_1.default.SymbolFlags.Method |
|
|
106
|
+
typescript_1.default.SymbolFlags.Interface |
|
|
107
|
+
typescript_1.default.SymbolFlags.Class |
|
|
108
|
+
typescript_1.default.SymbolFlags.Variable)) {
|
|
106
109
|
// This happens when someone declares an object with methods:
|
|
107
110
|
// { methodProperty() {} }
|
|
108
|
-
flags = (0, enum_1.removeFlag)(flags,
|
|
111
|
+
flags = (0, enum_1.removeFlag)(flags, typescript_1.default.SymbolFlags.Property);
|
|
109
112
|
}
|
|
110
113
|
// A default exported function with no associated variable is a property, but
|
|
111
114
|
// we should really convert it as a variable for documentation purposes
|
|
112
115
|
// export default () => {}
|
|
113
116
|
// export default 123
|
|
114
|
-
if (flags ===
|
|
117
|
+
if (flags === typescript_1.default.SymbolFlags.Property &&
|
|
115
118
|
symbol.name === "default" &&
|
|
116
119
|
context.scope.kindOf(models_1.ReflectionKind.Module | models_1.ReflectionKind.Project)) {
|
|
117
|
-
flags =
|
|
120
|
+
flags = typescript_1.default.SymbolFlags.BlockScopedVariable;
|
|
118
121
|
}
|
|
119
122
|
for (const flag of (0, enum_1.getEnumFlags)(flags ^ allConverterFlags)) {
|
|
120
123
|
if (!(flag & allConverterFlags)) {
|
|
121
|
-
context.logger.verbose(`Missing converter for symbol: ${symbol.name} with flag ${
|
|
124
|
+
context.logger.verbose(`Missing converter for symbol: ${symbol.name} with flag ${typescript_1.default.SymbolFlags[flag]}`);
|
|
122
125
|
}
|
|
123
126
|
}
|
|
124
127
|
// Note: This method does not allow skipping earlier converters.
|
|
@@ -140,13 +143,13 @@ function convertSymbols(context, symbols) {
|
|
|
140
143
|
}
|
|
141
144
|
function convertEnum(context, symbol, exportSymbol) {
|
|
142
145
|
const reflection = context.createDeclarationReflection(models_1.ReflectionKind.Enum, symbol, exportSymbol);
|
|
143
|
-
if (symbol.flags &
|
|
146
|
+
if (symbol.flags & typescript_1.default.SymbolFlags.ConstEnum) {
|
|
144
147
|
reflection.setFlag(models_1.ReflectionFlag.Const);
|
|
145
148
|
}
|
|
146
149
|
context.finalizeDeclarationReflection(reflection);
|
|
147
150
|
convertSymbols(context.withScope(reflection), context.checker
|
|
148
151
|
.getExportsOfModule(symbol)
|
|
149
|
-
.filter((s) => s.flags &
|
|
152
|
+
.filter((s) => s.flags & typescript_1.default.SymbolFlags.EnumMember));
|
|
150
153
|
}
|
|
151
154
|
function convertEnumMember(context, symbol, exportSymbol) {
|
|
152
155
|
const reflection = context.createDeclarationReflection(models_1.ReflectionKind.EnumMember, symbol, exportSymbol);
|
|
@@ -162,14 +165,14 @@ function convertEnumMember(context, symbol, exportSymbol) {
|
|
|
162
165
|
context.finalizeDeclarationReflection(reflection);
|
|
163
166
|
}
|
|
164
167
|
function convertNamespace(context, symbol, exportSymbol) {
|
|
165
|
-
let exportFlags =
|
|
168
|
+
let exportFlags = typescript_1.default.SymbolFlags.ModuleMember;
|
|
166
169
|
// This can happen in JS land where "class" functions get tagged as a namespace too
|
|
167
170
|
if (symbol
|
|
168
171
|
.getDeclarations()
|
|
169
|
-
?.some((d) =>
|
|
172
|
+
?.some((d) => typescript_1.default.isModuleDeclaration(d) || typescript_1.default.isSourceFile(d)) !==
|
|
170
173
|
true) {
|
|
171
|
-
exportFlags =
|
|
172
|
-
if ((0, enum_1.hasAnyFlag)(symbol.flags,
|
|
174
|
+
exportFlags = typescript_1.default.SymbolFlags.ClassMember;
|
|
175
|
+
if ((0, enum_1.hasAnyFlag)(symbol.flags, typescript_1.default.SymbolFlags.Class)) {
|
|
173
176
|
return;
|
|
174
177
|
}
|
|
175
178
|
}
|
|
@@ -182,12 +185,12 @@ function convertNamespace(context, symbol, exportSymbol) {
|
|
|
182
185
|
function convertTypeAlias(context, symbol, exportSymbol) {
|
|
183
186
|
const declaration = symbol
|
|
184
187
|
?.getDeclarations()
|
|
185
|
-
?.find((d) =>
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
if (
|
|
188
|
+
?.find((d) => typescript_1.default.isTypeAliasDeclaration(d) ||
|
|
189
|
+
typescript_1.default.isJSDocTypedefTag(d) ||
|
|
190
|
+
typescript_1.default.isJSDocCallbackTag(d) ||
|
|
191
|
+
typescript_1.default.isJSDocEnumTag(d));
|
|
192
|
+
(0, assert_1.default)(declaration);
|
|
193
|
+
if (typescript_1.default.isTypeAliasDeclaration(declaration)) {
|
|
191
194
|
const reflection = context.createDeclarationReflection(models_1.ReflectionKind.TypeAlias, symbol, exportSymbol);
|
|
192
195
|
reflection.type = context.converter.convertType(context.withScope(reflection), declaration.type);
|
|
193
196
|
context.finalizeDeclarationReflection(reflection);
|
|
@@ -195,8 +198,8 @@ function convertTypeAlias(context, symbol, exportSymbol) {
|
|
|
195
198
|
// from the parent comment. Ugly, but works for now. Should be cleaned up eventually.
|
|
196
199
|
reflection.typeParameters = declaration.typeParameters?.map((param) => (0, signature_1.createTypeParamReflection)(param, context.withScope(reflection)));
|
|
197
200
|
}
|
|
198
|
-
else if (
|
|
199
|
-
|
|
201
|
+
else if (typescript_1.default.isJSDocTypedefTag(declaration) ||
|
|
202
|
+
typescript_1.default.isJSDocEnumTag(declaration)) {
|
|
200
203
|
(0, jsdoc_1.convertJsDocAlias)(context, symbol, declaration, exportSymbol);
|
|
201
204
|
}
|
|
202
205
|
else {
|
|
@@ -207,22 +210,22 @@ function convertFunctionOrMethod(context, symbol, exportSymbol) {
|
|
|
207
210
|
// Can't just check method flag because this might be called for properties as well
|
|
208
211
|
// This will *NOT* be called for variables that look like functions, they need a special case.
|
|
209
212
|
const isMethod = !!(symbol.flags &
|
|
210
|
-
(
|
|
211
|
-
const declarations = symbol.getDeclarations()?.filter(
|
|
213
|
+
(typescript_1.default.SymbolFlags.Property | typescript_1.default.SymbolFlags.Method));
|
|
214
|
+
const declarations = symbol.getDeclarations()?.filter(typescript_1.default.isFunctionLike) ?? [];
|
|
212
215
|
// Don't do anything if we inherited this method and it is private.
|
|
213
216
|
if (isMethod &&
|
|
214
217
|
isInherited(context, symbol) &&
|
|
215
218
|
declarations.length > 0 &&
|
|
216
|
-
(0, enum_1.hasAllFlags)(
|
|
219
|
+
(0, enum_1.hasAllFlags)(typescript_1.default.getCombinedModifierFlags(declarations[0]), typescript_1.default.ModifierFlags.Private)) {
|
|
217
220
|
return;
|
|
218
221
|
}
|
|
219
222
|
const parentSymbol = context.project.getSymbolFromReflection(context.scope);
|
|
220
223
|
const locationDeclaration = parentSymbol
|
|
221
224
|
?.getDeclarations()
|
|
222
|
-
?.find((d) =>
|
|
225
|
+
?.find((d) => typescript_1.default.isClassDeclaration(d) || typescript_1.default.isInterfaceDeclaration(d)) ??
|
|
223
226
|
parentSymbol?.getDeclarations()?.[0]?.getSourceFile() ??
|
|
224
227
|
symbol.getDeclarations()?.[0]?.getSourceFile();
|
|
225
|
-
|
|
228
|
+
(0, assert_1.default)(locationDeclaration, "Missing declaration context");
|
|
226
229
|
const type = context.checker.getTypeOfSymbolAtLocation(symbol, locationDeclaration);
|
|
227
230
|
// Need to get the non nullable type because interface methods might be declared
|
|
228
231
|
// with a question token. See GH1490.
|
|
@@ -247,26 +250,26 @@ function convertFunctionOrMethod(context, symbol, exportSymbol) {
|
|
|
247
250
|
// getDeclaredTypeOfSymbol gets the INSTANCE type
|
|
248
251
|
// getTypeOfSymbolAtLocation gets the STATIC type
|
|
249
252
|
function convertClassOrInterface(context, symbol, exportSymbol) {
|
|
250
|
-
const reflection = context.createDeclarationReflection(
|
|
253
|
+
const reflection = context.createDeclarationReflection(typescript_1.default.SymbolFlags.Class & symbol.flags
|
|
251
254
|
? models_1.ReflectionKind.Class
|
|
252
255
|
: models_1.ReflectionKind.Interface, symbol, exportSymbol, void 0);
|
|
253
256
|
const classDeclaration = symbol
|
|
254
257
|
.getDeclarations()
|
|
255
|
-
?.find((d) =>
|
|
258
|
+
?.find((d) => typescript_1.default.isClassDeclaration(d) || typescript_1.default.isFunctionDeclaration(d));
|
|
256
259
|
if (classDeclaration)
|
|
257
260
|
setModifiers(symbol, classDeclaration, reflection);
|
|
258
261
|
const reflectionContext = context.withScope(reflection);
|
|
259
262
|
const instanceType = context.checker.getDeclaredTypeOfSymbol(symbol);
|
|
260
|
-
|
|
263
|
+
(0, assert_1.default)(instanceType.isClassOrInterface());
|
|
261
264
|
// We might do some inheritance - do this first so that it's set when converting properties
|
|
262
265
|
const declarations = symbol
|
|
263
266
|
.getDeclarations()
|
|
264
|
-
?.filter((d) =>
|
|
265
|
-
const extendedTypes = (0, nodes_1.getHeritageTypes)(declarations,
|
|
267
|
+
?.filter((d) => typescript_1.default.isInterfaceDeclaration(d) || typescript_1.default.isClassDeclaration(d)) ?? [];
|
|
268
|
+
const extendedTypes = (0, nodes_1.getHeritageTypes)(declarations, typescript_1.default.SyntaxKind.ExtendsKeyword).map((t) => context.converter.convertType(reflectionContext, t));
|
|
266
269
|
if (extendedTypes.length) {
|
|
267
270
|
reflection.extendedTypes = extendedTypes;
|
|
268
271
|
}
|
|
269
|
-
const implementedTypes = (0, nodes_1.getHeritageTypes)(declarations,
|
|
272
|
+
const implementedTypes = (0, nodes_1.getHeritageTypes)(declarations, typescript_1.default.SyntaxKind.ImplementsKeyword).map((t) => context.converter.convertType(reflectionContext, t));
|
|
270
273
|
if (implementedTypes.length) {
|
|
271
274
|
reflection.implementedTypes = implementedTypes;
|
|
272
275
|
}
|
|
@@ -278,7 +281,7 @@ function convertClassOrInterface(context, symbol, exportSymbol) {
|
|
|
278
281
|
for (const prop of context.checker.getPropertiesOfType(staticType)) {
|
|
279
282
|
// Don't convert namespace members, or the prototype here.
|
|
280
283
|
if (prop.flags &
|
|
281
|
-
(
|
|
284
|
+
(typescript_1.default.SymbolFlags.ModuleMember | typescript_1.default.SymbolFlags.Prototype))
|
|
282
285
|
continue;
|
|
283
286
|
convertSymbol(reflectionContext, prop);
|
|
284
287
|
}
|
|
@@ -301,14 +304,14 @@ function convertClassOrInterface(context, symbol, exportSymbol) {
|
|
|
301
304
|
if (instanceType.typeParameters) {
|
|
302
305
|
reflection.typeParameters = instanceType.typeParameters.map((param) => {
|
|
303
306
|
const declaration = param.symbol?.declarations?.[0];
|
|
304
|
-
|
|
307
|
+
(0, assert_1.default)(declaration && typescript_1.default.isTypeParameterDeclaration(declaration));
|
|
305
308
|
return (0, signature_1.createTypeParamReflection)(declaration, reflectionContext);
|
|
306
309
|
});
|
|
307
310
|
}
|
|
308
311
|
// Interfaces might also have call signatures
|
|
309
312
|
// Classes might too, because of declaration merging
|
|
310
313
|
context.checker
|
|
311
|
-
.getSignaturesOfType(instanceType,
|
|
314
|
+
.getSignaturesOfType(instanceType, typescript_1.default.SignatureKind.Call)
|
|
312
315
|
.forEach((sig) => (0, signature_1.createSignature)(reflectionContext, models_1.ReflectionKind.CallSignature, sig));
|
|
313
316
|
// We also might have constructor signatures
|
|
314
317
|
// This is potentially a problem with classes having multiple "constructor" members...
|
|
@@ -322,22 +325,22 @@ function convertProperty(context, symbol, exportSymbol) {
|
|
|
322
325
|
// Don't do anything if we inherited this property and it is private.
|
|
323
326
|
if (isInherited(context, symbol) &&
|
|
324
327
|
declarations.length > 0 &&
|
|
325
|
-
(0, enum_1.hasAllFlags)(
|
|
328
|
+
(0, enum_1.hasAllFlags)(typescript_1.default.getCombinedModifierFlags(declarations[0]), typescript_1.default.ModifierFlags.Private)) {
|
|
326
329
|
return;
|
|
327
330
|
}
|
|
328
331
|
// Special case: We pretend properties are methods if they look like methods.
|
|
329
332
|
// This happens with mixins / weird inheritance.
|
|
330
333
|
if (declarations.length &&
|
|
331
|
-
declarations.every((decl) =>
|
|
334
|
+
declarations.every((decl) => typescript_1.default.isMethodSignature(decl) || typescript_1.default.isMethodDeclaration(decl))) {
|
|
332
335
|
return convertFunctionOrMethod(context, symbol, exportSymbol);
|
|
333
336
|
}
|
|
334
337
|
if (declarations.length === 1) {
|
|
335
338
|
const declaration = declarations[0];
|
|
336
339
|
// Special case: "arrow methods" should be treated as methods.
|
|
337
|
-
if (
|
|
340
|
+
if (typescript_1.default.isPropertyDeclaration(declaration) &&
|
|
338
341
|
!declaration.type &&
|
|
339
342
|
declaration.initializer &&
|
|
340
|
-
|
|
343
|
+
typescript_1.default.isArrowFunction(declaration.initializer)) {
|
|
341
344
|
return convertArrowAsMethod(context, symbol, declaration.initializer, exportSymbol);
|
|
342
345
|
}
|
|
343
346
|
}
|
|
@@ -348,11 +351,11 @@ function convertProperty(context, symbol, exportSymbol) {
|
|
|
348
351
|
const declaration = symbol.getDeclarations()?.[0];
|
|
349
352
|
let parameterType;
|
|
350
353
|
if (declaration &&
|
|
351
|
-
(
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
if (!
|
|
354
|
+
(typescript_1.default.isPropertyDeclaration(declaration) ||
|
|
355
|
+
typescript_1.default.isPropertySignature(declaration) ||
|
|
356
|
+
typescript_1.default.isParameter(declaration) ||
|
|
357
|
+
typescript_1.default.isPropertyAccessExpression(declaration))) {
|
|
358
|
+
if (!typescript_1.default.isPropertyAccessExpression(declaration)) {
|
|
356
359
|
parameterType = declaration.type;
|
|
357
360
|
}
|
|
358
361
|
setModifiers(symbol, declaration, reflection);
|
|
@@ -371,17 +374,17 @@ function convertArrowAsMethod(context, symbol, arrow, exportSymbol) {
|
|
|
371
374
|
context.finalizeDeclarationReflection(reflection);
|
|
372
375
|
const rc = context.withScope(reflection);
|
|
373
376
|
const signature = context.checker.getSignatureFromDeclaration(arrow);
|
|
374
|
-
|
|
377
|
+
(0, assert_1.default)(signature);
|
|
375
378
|
(0, signature_1.createSignature)(rc, models_1.ReflectionKind.CallSignature, signature, arrow);
|
|
376
379
|
}
|
|
377
380
|
function convertConstructor(context, symbol) {
|
|
378
381
|
const reflection = context.createDeclarationReflection(models_1.ReflectionKind.Constructor, symbol, void 0, "constructor");
|
|
379
382
|
context.finalizeDeclarationReflection(reflection);
|
|
380
383
|
const reflectionContext = context.withScope(reflection);
|
|
381
|
-
const declarations = symbol.getDeclarations()?.filter(
|
|
384
|
+
const declarations = symbol.getDeclarations()?.filter(typescript_1.default.isConstructorDeclaration) ?? [];
|
|
382
385
|
const signatures = declarations.map((decl) => {
|
|
383
386
|
const sig = context.checker.getSignatureFromDeclaration(decl);
|
|
384
|
-
|
|
387
|
+
(0, assert_1.default)(sig);
|
|
385
388
|
return sig;
|
|
386
389
|
});
|
|
387
390
|
for (const sig of signatures) {
|
|
@@ -392,7 +395,7 @@ function convertConstructSignatures(context, symbol) {
|
|
|
392
395
|
const type = context.checker.getDeclaredTypeOfSymbol(symbol);
|
|
393
396
|
// These get added as a "constructor" member of this interface. This is a problem... but nobody
|
|
394
397
|
// has complained yet. We really ought to have a constructSignatures property on the reflection instead.
|
|
395
|
-
const constructSignatures = context.checker.getSignaturesOfType(type,
|
|
398
|
+
const constructSignatures = context.checker.getSignaturesOfType(type, typescript_1.default.SignatureKind.Construct);
|
|
396
399
|
if (constructSignatures.length) {
|
|
397
400
|
const constructMember = new models_1.DeclarationReflection("constructor", models_1.ReflectionKind.Constructor, context.scope);
|
|
398
401
|
context.postReflectionCreation(constructMember, symbol, void 0);
|
|
@@ -419,7 +422,7 @@ function createAlias(target, context, symbol, exportSymbol) {
|
|
|
419
422
|
}
|
|
420
423
|
function convertVariable(context, symbol, exportSymbol) {
|
|
421
424
|
const declaration = symbol.getDeclarations()?.[0];
|
|
422
|
-
|
|
425
|
+
(0, assert_1.default)(declaration);
|
|
423
426
|
const type = context.checker.getTypeOfSymbolAtLocation(symbol, declaration);
|
|
424
427
|
if (isEnumLike(context.checker, type, declaration) &&
|
|
425
428
|
symbol.getJsDocTags().some((tag) => tag.name === "enum")) {
|
|
@@ -430,7 +433,7 @@ function convertVariable(context, symbol, exportSymbol) {
|
|
|
430
433
|
}
|
|
431
434
|
const reflection = context.createDeclarationReflection(models_1.ReflectionKind.Variable, symbol, exportSymbol);
|
|
432
435
|
let typeNode;
|
|
433
|
-
if (
|
|
436
|
+
if (typescript_1.default.isVariableDeclaration(declaration)) {
|
|
434
437
|
// Otherwise we might have destructuring
|
|
435
438
|
typeNode = declaration.type;
|
|
436
439
|
}
|
|
@@ -438,10 +441,10 @@ function convertVariable(context, symbol, exportSymbol) {
|
|
|
438
441
|
setModifiers(symbol, declaration, reflection);
|
|
439
442
|
reflection.defaultValue = (0, convert_expression_1.convertDefaultValue)(declaration);
|
|
440
443
|
context.finalizeDeclarationReflection(reflection);
|
|
441
|
-
return
|
|
444
|
+
return typescript_1.default.SymbolFlags.Property;
|
|
442
445
|
}
|
|
443
446
|
function isEnumLike(checker, type, location) {
|
|
444
|
-
if (!(0, enum_1.hasAllFlags)(type.flags,
|
|
447
|
+
if (!(0, enum_1.hasAllFlags)(type.flags, typescript_1.default.TypeFlags.Object)) {
|
|
445
448
|
return false;
|
|
446
449
|
}
|
|
447
450
|
return type.getProperties().every((prop) => {
|
|
@@ -450,7 +453,7 @@ function isEnumLike(checker, type, location) {
|
|
|
450
453
|
});
|
|
451
454
|
}
|
|
452
455
|
function isValidEnumProperty(type) {
|
|
453
|
-
return (0, enum_1.hasAnyFlag)(type.flags,
|
|
456
|
+
return (0, enum_1.hasAnyFlag)(type.flags, typescript_1.default.TypeFlags.NumberLike | typescript_1.default.TypeFlags.StringLike);
|
|
454
457
|
}
|
|
455
458
|
function convertVariableAsEnum(context, symbol, exportSymbol) {
|
|
456
459
|
const reflection = context.createDeclarationReflection(models_1.ReflectionKind.Enum, symbol, exportSymbol);
|
|
@@ -465,12 +468,12 @@ function convertVariableAsEnum(context, symbol, exportSymbol) {
|
|
|
465
468
|
rc.finalizeDeclarationReflection(reflection);
|
|
466
469
|
}
|
|
467
470
|
// Skip converting the type alias, if there is one
|
|
468
|
-
return
|
|
471
|
+
return typescript_1.default.SymbolFlags.TypeAlias;
|
|
469
472
|
}
|
|
470
473
|
function convertVariableAsFunction(context, symbol, exportSymbol) {
|
|
471
474
|
const declaration = symbol
|
|
472
475
|
.getDeclarations()
|
|
473
|
-
?.find(
|
|
476
|
+
?.find(typescript_1.default.isVariableDeclaration);
|
|
474
477
|
const accessDeclaration = declaration ?? symbol.valueDeclaration;
|
|
475
478
|
const type = accessDeclaration
|
|
476
479
|
? context.checker.getTypeOfSymbolAtLocation(symbol, accessDeclaration)
|
|
@@ -484,7 +487,7 @@ function convertVariableAsFunction(context, symbol, exportSymbol) {
|
|
|
484
487
|
for (const signature of type.getCallSignatures()) {
|
|
485
488
|
(0, signature_1.createSignature)(reflectionContext, models_1.ReflectionKind.CallSignature, signature);
|
|
486
489
|
}
|
|
487
|
-
return
|
|
490
|
+
return typescript_1.default.SymbolFlags.Property;
|
|
488
491
|
}
|
|
489
492
|
function convertAccessor(context, symbol, exportSymbol) {
|
|
490
493
|
const reflection = context.createDeclarationReflection(models_1.ReflectionKind.Accessor, symbol, exportSymbol);
|
|
@@ -494,14 +497,14 @@ function convertAccessor(context, symbol, exportSymbol) {
|
|
|
494
497
|
setModifiers(symbol, declaration, reflection);
|
|
495
498
|
}
|
|
496
499
|
context.finalizeDeclarationReflection(reflection);
|
|
497
|
-
const getDeclaration = symbol.getDeclarations()?.find(
|
|
500
|
+
const getDeclaration = symbol.getDeclarations()?.find(typescript_1.default.isGetAccessor);
|
|
498
501
|
if (getDeclaration) {
|
|
499
502
|
const signature = context.checker.getSignatureFromDeclaration(getDeclaration);
|
|
500
503
|
if (signature) {
|
|
501
504
|
(0, signature_1.createSignature)(rc, models_1.ReflectionKind.GetSignature, signature, getDeclaration);
|
|
502
505
|
}
|
|
503
506
|
}
|
|
504
|
-
const setDeclaration = symbol.getDeclarations()?.find(
|
|
507
|
+
const setDeclaration = symbol.getDeclarations()?.find(typescript_1.default.isSetAccessor);
|
|
505
508
|
if (setDeclaration) {
|
|
506
509
|
const signature = context.checker.getSignatureFromDeclaration(setDeclaration);
|
|
507
510
|
if (signature) {
|
|
@@ -511,10 +514,10 @@ function convertAccessor(context, symbol, exportSymbol) {
|
|
|
511
514
|
}
|
|
512
515
|
function isInherited(context, symbol) {
|
|
513
516
|
const parentSymbol = context.project.getSymbolFromReflection(context.scope);
|
|
514
|
-
|
|
517
|
+
(0, assert_1.default)(parentSymbol, `No parent symbol found for ${symbol.name} in ${context.scope.name}`);
|
|
515
518
|
const parents = parentSymbol.declarations?.slice() || [];
|
|
516
|
-
const constructorDecls = parents.flatMap((parent) =>
|
|
517
|
-
? parent.members.filter(
|
|
519
|
+
const constructorDecls = parents.flatMap((parent) => typescript_1.default.isClassDeclaration(parent)
|
|
520
|
+
? parent.members.filter(typescript_1.default.isConstructorDeclaration)
|
|
518
521
|
: []);
|
|
519
522
|
parents.push(...constructorDecls);
|
|
520
523
|
return (parents.some((d) => symbol.getDeclarations()?.some((d2) => d2.parent === d)) === false);
|
|
@@ -523,30 +526,30 @@ function setModifiers(symbol, declaration, reflection) {
|
|
|
523
526
|
if (!declaration) {
|
|
524
527
|
return;
|
|
525
528
|
}
|
|
526
|
-
const modifiers =
|
|
527
|
-
if (
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
if (
|
|
529
|
+
const modifiers = typescript_1.default.getCombinedModifierFlags(declaration);
|
|
530
|
+
if (typescript_1.default.isMethodDeclaration(declaration) ||
|
|
531
|
+
typescript_1.default.isPropertyDeclaration(declaration) ||
|
|
532
|
+
typescript_1.default.isAccessor(declaration)) {
|
|
533
|
+
if (typescript_1.default.isPrivateIdentifier(declaration.name)) {
|
|
531
534
|
reflection.setFlag(models_1.ReflectionFlag.Private);
|
|
532
535
|
}
|
|
533
536
|
}
|
|
534
|
-
if ((0, enum_1.hasAllFlags)(modifiers,
|
|
537
|
+
if ((0, enum_1.hasAllFlags)(modifiers, typescript_1.default.ModifierFlags.Private)) {
|
|
535
538
|
reflection.setFlag(models_1.ReflectionFlag.Private);
|
|
536
539
|
}
|
|
537
|
-
if ((0, enum_1.hasAllFlags)(modifiers,
|
|
540
|
+
if ((0, enum_1.hasAllFlags)(modifiers, typescript_1.default.ModifierFlags.Protected)) {
|
|
538
541
|
reflection.setFlag(models_1.ReflectionFlag.Protected);
|
|
539
542
|
}
|
|
540
|
-
if ((0, enum_1.hasAllFlags)(modifiers,
|
|
543
|
+
if ((0, enum_1.hasAllFlags)(modifiers, typescript_1.default.ModifierFlags.Public)) {
|
|
541
544
|
reflection.setFlag(models_1.ReflectionFlag.Public);
|
|
542
545
|
}
|
|
543
|
-
reflection.setFlag(models_1.ReflectionFlag.Optional, (0, enum_1.hasAllFlags)(symbol.flags,
|
|
544
|
-
reflection.setFlag(models_1.ReflectionFlag.Readonly, (0, enum_1.hasAllFlags)(symbol.checkFlags ?? 0,
|
|
545
|
-
(0, enum_1.hasAllFlags)(modifiers,
|
|
546
|
-
reflection.setFlag(models_1.ReflectionFlag.Abstract, (0, enum_1.hasAllFlags)(modifiers,
|
|
546
|
+
reflection.setFlag(models_1.ReflectionFlag.Optional, (0, enum_1.hasAllFlags)(symbol.flags, typescript_1.default.SymbolFlags.Optional));
|
|
547
|
+
reflection.setFlag(models_1.ReflectionFlag.Readonly, (0, enum_1.hasAllFlags)(symbol.checkFlags ?? 0, typescript_1.default.CheckFlags.Readonly) ||
|
|
548
|
+
(0, enum_1.hasAllFlags)(modifiers, typescript_1.default.ModifierFlags.Readonly));
|
|
549
|
+
reflection.setFlag(models_1.ReflectionFlag.Abstract, (0, enum_1.hasAllFlags)(modifiers, typescript_1.default.ModifierFlags.Abstract));
|
|
547
550
|
if (reflection.kindOf(models_1.ReflectionKind.Variable) &&
|
|
548
|
-
(0, enum_1.hasAllFlags)(symbol.flags,
|
|
549
|
-
reflection.setFlag(models_1.ReflectionFlag.Const, (0, enum_1.hasAllFlags)(declaration.parent.flags,
|
|
551
|
+
(0, enum_1.hasAllFlags)(symbol.flags, typescript_1.default.SymbolFlags.BlockScopedVariable)) {
|
|
552
|
+
reflection.setFlag(models_1.ReflectionFlag.Const, (0, enum_1.hasAllFlags)(declaration.parent.flags, typescript_1.default.NodeFlags.Const));
|
|
550
553
|
}
|
|
551
554
|
// ReflectionFlag.Static happens when constructing the reflection.
|
|
552
555
|
// We don't have sufficient information here to determine if it ought to be static.
|