typedoc 0.25.3 → 0.25.5

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.
Files changed (75) hide show
  1. package/dist/lib/converter/comments/declarationReference.js +14 -14
  2. package/dist/lib/converter/comments/discovery.js +4 -2
  3. package/dist/lib/converter/comments/parser.js +56 -13
  4. package/dist/lib/converter/context.d.ts +0 -3
  5. package/dist/lib/converter/context.js +0 -3
  6. package/dist/lib/converter/converter.d.ts +0 -1
  7. package/dist/lib/converter/converter.js +0 -1
  8. package/dist/lib/converter/factories/signature.js +29 -3
  9. package/dist/lib/converter/plugins/CategoryPlugin.d.ts +0 -7
  10. package/dist/lib/converter/plugins/CategoryPlugin.js +6 -12
  11. package/dist/lib/converter/plugins/CommentPlugin.d.ts +1 -0
  12. package/dist/lib/converter/plugins/CommentPlugin.js +59 -29
  13. package/dist/lib/converter/plugins/GroupPlugin.d.ts +0 -7
  14. package/dist/lib/converter/plugins/GroupPlugin.js +7 -13
  15. package/dist/lib/converter/plugins/SourcePlugin.js +23 -0
  16. package/dist/lib/converter/plugins/TypePlugin.js +4 -1
  17. package/dist/lib/converter/symbols.js +56 -28
  18. package/dist/lib/converter/types.js +14 -10
  19. package/dist/lib/converter/utils/repository.js +4 -4
  20. package/dist/lib/converter/utils/symbols.js +5 -0
  21. package/dist/lib/models/comments/comment.d.ts +0 -1
  22. package/dist/lib/models/comments/comment.js +0 -1
  23. package/dist/lib/models/reflections/ReflectionSymbolId.d.ts +8 -0
  24. package/dist/lib/models/reflections/ReflectionSymbolId.js +13 -3
  25. package/dist/lib/models/reflections/abstract.d.ts +3 -1
  26. package/dist/lib/models/reflections/abstract.js +4 -2
  27. package/dist/lib/models/reflections/declaration.js +1 -1
  28. package/dist/lib/models/reflections/kind.d.ts +6 -0
  29. package/dist/lib/models/reflections/kind.js +17 -0
  30. package/dist/lib/models/reflections/parameter.js +1 -1
  31. package/dist/lib/models/reflections/project.d.ts +3 -0
  32. package/dist/lib/models/reflections/project.js +59 -6
  33. package/dist/lib/models/reflections/signature.js +1 -1
  34. package/dist/lib/models/sources/file.d.ts +1 -1
  35. package/dist/lib/models/types.d.ts +5 -0
  36. package/dist/lib/models/types.js +42 -31
  37. package/dist/lib/output/themes/default/DefaultTheme.d.ts +1 -1
  38. package/dist/lib/output/themes/default/DefaultTheme.js +82 -11
  39. package/dist/lib/output/themes/default/DefaultThemeRenderContext.d.ts +15 -3
  40. package/dist/lib/output/themes/default/DefaultThemeRenderContext.js +12 -0
  41. package/dist/lib/output/themes/default/partials/comment.js +8 -3
  42. package/dist/lib/output/themes/default/partials/hierarchy.js +18 -1
  43. package/dist/lib/output/themes/default/partials/icon.js +2 -2
  44. package/dist/lib/output/themes/default/partials/member.getterSetter.js +2 -2
  45. package/dist/lib/output/themes/default/partials/member.signature.title.js +2 -2
  46. package/dist/lib/output/themes/default/partials/member.signatures.js +2 -1
  47. package/dist/lib/output/themes/default/partials/parameter.js +2 -2
  48. package/dist/lib/output/themes/default/partials/reflectionPreview.d.ts +4 -0
  49. package/dist/lib/output/themes/default/partials/reflectionPreview.js +21 -0
  50. package/dist/lib/output/themes/default/partials/type.d.ts +3 -1
  51. package/dist/lib/output/themes/default/partials/type.js +29 -27
  52. package/dist/lib/output/themes/default/partials/typeParameters.js +6 -3
  53. package/dist/lib/output/themes/default/templates/hierarchy.d.ts +5 -0
  54. package/dist/lib/output/themes/default/templates/hierarchy.js +32 -0
  55. package/dist/lib/output/themes/default/templates/reflection.js +2 -1
  56. package/dist/lib/output/themes/lib.js +3 -3
  57. package/dist/lib/serialization/components.d.ts +1 -1
  58. package/dist/lib/serialization/schema.d.ts +1 -0
  59. package/dist/lib/serialization/serializer.d.ts +0 -1
  60. package/dist/lib/serialization/serializer.js +0 -1
  61. package/dist/lib/utils/enum.d.ts +1 -0
  62. package/dist/lib/utils/enum.js +5 -1
  63. package/dist/lib/utils/loggers.d.ts +0 -3
  64. package/dist/lib/utils/loggers.js +0 -1
  65. package/dist/lib/utils/options/declaration.d.ts +1 -0
  66. package/dist/lib/utils/options/declaration.js +2 -2
  67. package/dist/lib/utils/options/options.js +6 -5
  68. package/dist/lib/utils/options/readers/tsconfig.js +4 -1
  69. package/dist/lib/utils/options/sources/typedoc.js +1 -0
  70. package/dist/lib/utils/tsconfig.d.ts +1 -0
  71. package/dist/lib/utils/tsconfig.js +33 -1
  72. package/dist/lib/validation/documentation.js +23 -16
  73. package/package.json +13 -10
  74. package/static/main.js +2 -2
  75. package/static/style.css +46 -15
@@ -48,7 +48,7 @@ const conversionOrder = [
48
48
  typescript_1.default.SymbolFlags.FunctionScopedVariable,
49
49
  typescript_1.default.SymbolFlags.ExportValue,
50
50
  typescript_1.default.SymbolFlags.TypeAlias,
51
- typescript_1.default.SymbolFlags.Function,
51
+ typescript_1.default.SymbolFlags.Function, // Before NamespaceModule
52
52
  typescript_1.default.SymbolFlags.Method,
53
53
  typescript_1.default.SymbolFlags.Interface,
54
54
  typescript_1.default.SymbolFlags.Property,
@@ -100,6 +100,10 @@ function convertSymbol(context, symbol, exportSymbol) {
100
100
  }
101
101
  if ((0, enum_1.hasAllFlags)(symbol.flags, typescript_1.default.SymbolFlags.NamespaceModule)) {
102
102
  // This might be here if a namespace is declared several times.
103
+ // Or if it's a namespace-like thing defined on a function
104
+ // In the function case, it's important to remove ValueModule so that
105
+ // if we convert the children as properties of the function rather than as
106
+ // a separate namespace, we skip creating the namespace.
103
107
  flags = (0, enum_1.removeFlag)(flags, typescript_1.default.SymbolFlags.ValueModule);
104
108
  }
105
109
  if ((0, enum_1.hasAnyFlag)(symbol.flags, typescript_1.default.SymbolFlags.Method |
@@ -110,19 +114,8 @@ function convertSymbol(context, symbol, exportSymbol) {
110
114
  // { methodProperty() {} }
111
115
  flags = (0, enum_1.removeFlag)(flags, typescript_1.default.SymbolFlags.Property);
112
116
  }
113
- // A default exported function with no associated variable is a property, but
114
- // we should really convert it as a variable for documentation purposes
115
- // export default () => {}
116
- // export default 123
117
- if (flags === typescript_1.default.SymbolFlags.Property &&
118
- symbol.name === "default" &&
119
- context.scope.kindOf(models_1.ReflectionKind.Module | models_1.ReflectionKind.Project)) {
120
- flags = typescript_1.default.SymbolFlags.BlockScopedVariable;
121
- }
122
- for (const flag of (0, enum_1.getEnumFlags)(flags ^ allConverterFlags)) {
123
- if (!(flag & allConverterFlags)) {
124
- context.logger.verbose(`Missing converter for symbol: ${symbol.name} with flag ${typescript_1.default.SymbolFlags[flag]}`);
125
- }
117
+ for (const flag of (0, enum_1.getEnumFlags)(flags & ~allConverterFlags)) {
118
+ context.logger.verbose(`Missing converter for symbol: ${symbol.name} with flag ${typescript_1.default.SymbolFlags[flag]}`);
126
119
  }
127
120
  // Note: This method does not allow skipping earlier converters.
128
121
  // For now, this is fine... might not be flexible enough in the future.
@@ -269,9 +262,7 @@ function convertFunctionOrMethod(context, symbol, exportSymbol) {
269
262
  // Need to get the non nullable type because interface methods might be declared
270
263
  // with a question token. See GH1490.
271
264
  const signatures = type.getNonNullableType().getCallSignatures();
272
- const reflection = context.createDeclarationReflection(context.scope.kindOf(models_1.ReflectionKind.ClassOrInterface |
273
- models_1.ReflectionKind.VariableOrProperty |
274
- models_1.ReflectionKind.TypeLiteral)
265
+ const reflection = context.createDeclarationReflection(context.scope.kindOf(models_1.ReflectionKind.MethodContainer)
275
266
  ? models_1.ReflectionKind.Method
276
267
  : models_1.ReflectionKind.Function, symbol, exportSymbol, void 0);
277
268
  if (symbol.declarations?.length && isMethod) {
@@ -285,6 +276,8 @@ function convertFunctionOrMethod(context, symbol, exportSymbol) {
285
276
  for (const sig of signatures) {
286
277
  (0, signature_1.createSignature)(scope, models_1.ReflectionKind.CallSignature, sig, symbol);
287
278
  }
279
+ convertFunctionProperties(scope, symbol, type);
280
+ return typescript_1.default.SymbolFlags.NamespaceModule;
288
281
  }
289
282
  // getDeclaredTypeOfSymbol gets the INSTANCE type
290
283
  // getTypeOfSymbolAtLocation gets the STATIC type
@@ -359,8 +352,15 @@ function convertClassOrInterface(context, symbol, exportSymbol) {
359
352
  convertConstructSignatures(reflectionContext, symbol);
360
353
  // And finally, index signatures
361
354
  (0, index_signature_1.convertIndexSignature)(reflectionContext, symbol);
355
+ // Normally this shouldn't matter, unless someone did something with skipLibCheck on.
356
+ return typescript_1.default.SymbolFlags.Alias;
362
357
  }
363
358
  function convertProperty(context, symbol, exportSymbol) {
359
+ // This might happen if we're converting a function-module created with Object.assign
360
+ // or `export default () => {}`
361
+ if (context.scope.kindOf(models_1.ReflectionKind.VariableContainer)) {
362
+ return convertVariable(context, symbol, exportSymbol);
363
+ }
364
364
  const declarations = symbol.getDeclarations() ?? [];
365
365
  // Don't do anything if we inherited this property and it is private.
366
366
  if (isInherited(context, symbol) &&
@@ -384,7 +384,7 @@ function convertProperty(context, symbol, exportSymbol) {
384
384
  return convertArrowAsMethod(context, symbol, declaration.initializer, exportSymbol);
385
385
  }
386
386
  }
387
- const reflection = context.createDeclarationReflection(context.scope.kindOf(models_1.ReflectionKind.Namespace)
387
+ const reflection = context.createDeclarationReflection(context.scope.kindOf(models_1.ReflectionKind.VariableContainer)
388
388
  ? models_1.ReflectionKind.Variable
389
389
  : models_1.ReflectionKind.Property, symbol, exportSymbol);
390
390
  reflection.conversionFlags |= models_1.ConversionFlags.VariableOrPropertySource;
@@ -415,9 +415,16 @@ function convertArrowAsMethod(context, symbol, arrow, exportSymbol) {
415
415
  setModifiers(symbol, arrow.parent, reflection);
416
416
  context.finalizeDeclarationReflection(reflection);
417
417
  const rc = context.withScope(reflection);
418
- const signature = context.checker.getSignatureFromDeclaration(arrow);
419
- (0, assert_1.default)(signature);
420
- (0, signature_1.createSignature)(rc, models_1.ReflectionKind.CallSignature, signature, symbol, arrow);
418
+ const locationDeclaration = symbol.parent
419
+ ?.getDeclarations()
420
+ ?.find((d) => typescript_1.default.isClassDeclaration(d) || typescript_1.default.isInterfaceDeclaration(d)) ??
421
+ symbol.parent?.getDeclarations()?.[0]?.getSourceFile() ??
422
+ symbol.getDeclarations()?.[0]?.getSourceFile();
423
+ (0, assert_1.default)(locationDeclaration, "Missing declaration context");
424
+ const type = context.checker.getTypeOfSymbolAtLocation(symbol, locationDeclaration);
425
+ const signatures = type.getNonNullableType().getCallSignatures();
426
+ (0, assert_1.default)(signatures.length, "Missing signatures");
427
+ (0, signature_1.createSignature)(rc, models_1.ReflectionKind.CallSignature, signatures[0], symbol, arrow);
421
428
  }
422
429
  function convertConstructor(context, symbol) {
423
430
  const reflection = context.createDeclarationReflection(models_1.ReflectionKind.Constructor, symbol, void 0, "constructor");
@@ -466,9 +473,10 @@ function createAlias(target, context, symbol, exportSymbol) {
466
473
  }
467
474
  function convertVariable(context, symbol, exportSymbol) {
468
475
  const declaration = symbol.getDeclarations()?.[0];
469
- (0, assert_1.default)(declaration);
470
476
  const comment = context.getComment(symbol, models_1.ReflectionKind.Variable);
471
- const type = context.checker.getTypeOfSymbolAtLocation(symbol, declaration);
477
+ const type = declaration
478
+ ? context.checker.getTypeOfSymbolAtLocation(symbol, declaration)
479
+ : context.checker.getTypeOfSymbol(symbol);
472
480
  if (isEnumLike(context.checker, type, declaration) &&
473
481
  comment?.hasModifier("@enum")) {
474
482
  return convertVariableAsEnum(context, symbol, exportSymbol);
@@ -479,9 +487,11 @@ function convertVariable(context, symbol, exportSymbol) {
479
487
  if (type.getCallSignatures().length) {
480
488
  return convertVariableAsFunction(context, symbol, exportSymbol);
481
489
  }
482
- const reflection = context.createDeclarationReflection(models_1.ReflectionKind.Variable, symbol, exportSymbol);
490
+ const reflection = context.createDeclarationReflection(context.scope.kindOf(models_1.ReflectionKind.VariableContainer)
491
+ ? models_1.ReflectionKind.Variable
492
+ : models_1.ReflectionKind.Property, symbol, exportSymbol);
483
493
  let typeNode;
484
- if (typescript_1.default.isVariableDeclaration(declaration)) {
494
+ if (declaration && typescript_1.default.isVariableDeclaration(declaration)) {
485
495
  // Otherwise we might have destructuring
486
496
  typeNode = declaration.type;
487
497
  }
@@ -492,7 +502,7 @@ function convertVariable(context, symbol, exportSymbol) {
492
502
  return typescript_1.default.SymbolFlags.Property;
493
503
  }
494
504
  function isEnumLike(checker, type, location) {
495
- if (!(0, enum_1.hasAllFlags)(type.flags, typescript_1.default.TypeFlags.Object)) {
505
+ if (!location || !(0, enum_1.hasAllFlags)(type.flags, typescript_1.default.TypeFlags.Object)) {
496
506
  return false;
497
507
  }
498
508
  return type.getProperties().every((prop) => {
@@ -536,7 +546,9 @@ function convertVariableAsFunction(context, symbol, exportSymbol) {
536
546
  const type = accessDeclaration
537
547
  ? context.checker.getTypeOfSymbolAtLocation(symbol, accessDeclaration)
538
548
  : context.checker.getDeclaredTypeOfSymbol(symbol);
539
- const reflection = context.createDeclarationReflection(models_1.ReflectionKind.Function, symbol, exportSymbol);
549
+ const reflection = context.createDeclarationReflection(context.scope.kindOf(models_1.ReflectionKind.MethodContainer)
550
+ ? models_1.ReflectionKind.Method
551
+ : models_1.ReflectionKind.Function, symbol, exportSymbol);
540
552
  setModifiers(symbol, accessDeclaration, reflection);
541
553
  reflection.conversionFlags |= models_1.ConversionFlags.VariableOrPropertySource;
542
554
  context.finalizeDeclarationReflection(reflection);
@@ -545,7 +557,23 @@ function convertVariableAsFunction(context, symbol, exportSymbol) {
545
557
  for (const signature of type.getCallSignatures()) {
546
558
  (0, signature_1.createSignature)(reflectionContext, models_1.ReflectionKind.CallSignature, signature, symbol);
547
559
  }
548
- return typescript_1.default.SymbolFlags.Property;
560
+ convertFunctionProperties(context.withScope(reflection), symbol, type);
561
+ return typescript_1.default.SymbolFlags.Property | typescript_1.default.SymbolFlags.NamespaceModule;
562
+ }
563
+ function convertFunctionProperties(context, symbol, type) {
564
+ // #2436/#2461: Functions created with Object.assign on a function likely have properties
565
+ // that we should document. We also add properties to the function if they are defined like:
566
+ // function f() {}
567
+ // f.x = 123;
568
+ // rather than creating a separate namespace.
569
+ // In the expando case, we'll have both namespace flags.
570
+ // In the Object.assign case, we'll have no namespace flags.
571
+ const nsFlags = typescript_1.default.SymbolFlags.ValueModule | typescript_1.default.SymbolFlags.NamespaceModule;
572
+ if (type.getProperties().length &&
573
+ ((0, enum_1.hasAllFlags)(symbol.flags, nsFlags) ||
574
+ !(0, enum_1.hasAnyFlag)(symbol.flags, nsFlags))) {
575
+ convertSymbols(context, type.getProperties());
576
+ }
549
577
  }
550
578
  function convertAccessor(context, symbol, exportSymbol) {
551
579
  const reflection = context.createDeclarationReflection(models_1.ReflectionKind.Accessor, symbol, exportSymbol);
@@ -83,6 +83,14 @@ function convertType(context, typeOrNode) {
83
83
  }
84
84
  return requestBugReport(context, typeOrNode);
85
85
  }
86
+ // TS 4.2 added this to enable better tracking of type aliases.
87
+ // We need to check it here, not just in the union checker, because typeToTypeNode
88
+ // will use the origin when serializing
89
+ if (typeOrNode.isUnion() &&
90
+ typeOrNode.origin &&
91
+ !typeOrNode.origin.isUnion()) {
92
+ return convertType(context, typeOrNode.origin);
93
+ }
86
94
  // IgnoreErrors is important, without it, we can't assert that we will get a node.
87
95
  const node = context.checker.typeToTypeNode(typeOrNode, void 0, typescript_1.default.NodeBuilderFlags.IgnoreErrors);
88
96
  (0, assert_1.default)(node); // According to the TS source of typeToString, this is a bug if it does not hold.
@@ -402,12 +410,16 @@ const queryConverter = {
402
410
  // on a variable typed as `any` with a name that doesn't exist.
403
411
  return new models_1.QueryType(models_1.ReferenceType.createBrokenReference(node.exprName.getText(), context.project));
404
412
  }
405
- return new models_1.QueryType(models_1.ReferenceType.createSymbolReference(context.resolveAliasedSymbol(querySymbol), context, node.exprName.getText()));
413
+ const ref = models_1.ReferenceType.createSymbolReference(context.resolveAliasedSymbol(querySymbol), context, node.exprName.getText());
414
+ ref.preferValues = true;
415
+ return new models_1.QueryType(ref);
406
416
  },
407
417
  convertType(context, type, node) {
408
418
  const symbol = type.getSymbol() || context.getSymbolAtLocation(node.exprName);
409
419
  (0, assert_1.default)(symbol, `Query type failed to get a symbol for: ${context.checker.typeToString(type)}. This is a bug.`);
410
- return new models_1.QueryType(models_1.ReferenceType.createSymbolReference(context.resolveAliasedSymbol(symbol), context));
420
+ const ref = models_1.ReferenceType.createSymbolReference(context.resolveAliasedSymbol(symbol), context);
421
+ ref.preferValues = true;
422
+ return new models_1.QueryType(ref);
411
423
  },
412
424
  };
413
425
  const referenceConverter = {
@@ -623,10 +635,6 @@ const typeOperatorConverter = {
623
635
  // keyof will only show up with generic functions, otherwise it gets eagerly
624
636
  // resolved to a union of strings.
625
637
  if (node.operator === typescript_1.default.SyntaxKind.KeyOfKeyword) {
626
- // TS 4.2 added this to enable better tracking of type aliases.
627
- if (type.isUnion() && type.origin) {
628
- return convertType(context, type.origin);
629
- }
630
638
  // There's probably an interface for this somewhere... I couldn't find it.
631
639
  const targetType = type.type;
632
640
  return new models_1.TypeOperatorType(convertType(context, targetType), "keyof");
@@ -642,10 +650,6 @@ const unionConverter = {
642
650
  return new models_1.UnionType(node.types.map((type) => convertType(context, type)));
643
651
  },
644
652
  convertType(context, type) {
645
- // TS 4.2 added this to enable better tracking of type aliases.
646
- if (type.origin) {
647
- return convertType(context, type.origin);
648
- }
649
653
  return new models_1.UnionType(type.types.map((type) => convertType(context, type)));
650
654
  },
651
655
  };
@@ -29,7 +29,7 @@ class AssumedRepository {
29
29
  path: fileName.substring(this.path.length + 1),
30
30
  line,
31
31
  };
32
- return this.sourceLinkTemplate.replace(/\{(path|line)\}/g, (_, key) => replacements[key]);
32
+ return this.sourceLinkTemplate.replace(/\{(gitRevision|path|line)\}/g, (_, key) => replacements[key]);
33
33
  }
34
34
  }
35
35
  exports.AssumedRepository = AssumedRepository;
@@ -117,9 +117,9 @@ exports.GitRepository = GitRepository;
117
117
  // 3. project
118
118
  const repoExpressions = [
119
119
  /(github(?!.us)(?:\.[a-z]+)*\.[a-z]{2,})[:/]([^/]+)\/(.*)/,
120
- /(\w+\.githubprivate.com)[:/]([^/]+)\/(.*)/,
121
- /(\w+\.ghe.com)[:/]([^/]+)\/(.*)/,
122
- /(\w+\.github.us)[:/]([^/]+)\/(.*)/,
120
+ /(\w+\.githubprivate.com)[:/]([^/]+)\/(.*)/, // GitHub enterprise
121
+ /(\w+\.ghe.com)[:/]([^/]+)\/(.*)/, // GitHub enterprise
122
+ /(\w+\.github.us)[:/]([^/]+)\/(.*)/, // GitHub enterprise
123
123
  /(bitbucket.org)[:/]([^/]+)\/(.*)/,
124
124
  /(gitlab.com)[:/]([^/]+)\/(.*)/,
125
125
  ];
@@ -6,8 +6,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.resolveAliasedSymbol = void 0;
7
7
  const typescript_1 = __importDefault(require("typescript"));
8
8
  function resolveAliasedSymbol(symbol, checker) {
9
+ const seen = new Set();
9
10
  while (typescript_1.default.SymbolFlags.Alias & symbol.flags) {
10
11
  symbol = checker.getAliasedSymbol(symbol);
12
+ // #2438, with declaration files, we might have an aliased symbol which eventually points to itself.
13
+ if (seen.has(symbol))
14
+ return symbol;
15
+ seen.add(symbol);
11
16
  }
12
17
  return symbol;
13
18
  }
@@ -140,7 +140,6 @@ export declare class Comment {
140
140
  * Return the first tag with the given name.
141
141
  *
142
142
  * @param tagName The name of the tag to look for.
143
- * @param paramName An optional parameter name to look for.
144
143
  * @returns The found tag or undefined.
145
144
  */
146
145
  getTag(tagName: `@${string}`): CommentTag | undefined;
@@ -273,7 +273,6 @@ class Comment {
273
273
  * Return the first tag with the given name.
274
274
  *
275
275
  * @param tagName The name of the tag to look for.
276
- * @param paramName An optional parameter name to look for.
277
276
  * @returns The found tag or undefined.
278
277
  */
279
278
  getTag(tagName) {
@@ -17,8 +17,16 @@ export declare class ReflectionSymbolId {
17
17
  /**
18
18
  * Note: This is **not** serialized. It exists for sorting by declaration order, but
19
19
  * should not be needed when deserializing from JSON.
20
+ * Will be set to `Infinity` if the ID was deserialized from JSON.
20
21
  */
21
22
  pos: number;
23
+ /**
24
+ * Note: This is **not** serialized. It exists to support detection of the differences between
25
+ * symbols which share declarations, but are instantiated with different type parameters.
26
+ * This will be `NaN` if the symbol reference is not transient.
27
+ * Note: This can only be non-NaN if {@link pos} is finite.
28
+ */
29
+ transientId: number;
22
30
  constructor(symbol: ts.Symbol, declaration?: ts.Declaration);
23
31
  constructor(json: JSONOutput.ReflectionSymbolId);
24
32
  getStableKey(): ReflectionSymbolIdString;
@@ -8,9 +8,11 @@ const fs_1 = require("fs");
8
8
  const path_1 = require("path");
9
9
  const typescript_1 = __importDefault(require("typescript"));
10
10
  const fs_2 = require("../../utils/fs");
11
+ const paths_1 = require("../../utils/paths");
11
12
  const tsutils_1 = require("../../utils/tsutils");
12
13
  const validation_1 = require("../../utils/validation");
13
- const paths_1 = require("../../utils/paths");
14
+ let transientCount = 0;
15
+ const transientIds = new WeakMap();
14
16
  /**
15
17
  * This exists so that TypeDoc can store a unique identifier for a `ts.Symbol` without
16
18
  * keeping a reference to the `ts.Symbol` itself. This identifier should be stable across
@@ -28,16 +30,24 @@ class ReflectionSymbolId {
28
30
  this.qualifiedName = (0, tsutils_1.getQualifiedName)(symbol, symbol.name);
29
31
  }
30
32
  this.pos = declaration?.pos ?? Infinity;
33
+ if (symbol.flags & typescript_1.default.SymbolFlags.Transient) {
34
+ this.transientId = transientIds.get(symbol) ?? ++transientCount;
35
+ transientIds.set(symbol, this.transientId);
36
+ }
37
+ else {
38
+ this.transientId = NaN;
39
+ }
31
40
  }
32
41
  else {
33
42
  this.fileName = symbol.sourceFileName;
34
43
  this.qualifiedName = symbol.qualifiedName;
35
44
  this.pos = Infinity;
45
+ this.transientId = NaN;
36
46
  }
37
47
  }
38
48
  getStableKey() {
39
49
  if (Number.isFinite(this.pos)) {
40
- return `${this.fileName}\0${this.qualifiedName}\0${this.pos}`;
50
+ return `${this.fileName}\0${this.qualifiedName}\0${this.pos}\0${this.transientId}`;
41
51
  }
42
52
  else {
43
53
  return `${this.fileName}\0${this.qualifiedName}`;
@@ -95,7 +105,7 @@ function addInferredDeclarationMapPaths(opts, files) {
95
105
  const rootDir = opts.rootDir || (0, fs_2.getCommonDirectory)(files);
96
106
  const declDir = opts.declarationDir || opts.outDir || rootDir;
97
107
  for (const file of files) {
98
- const mapFile = (0, path_1.resolve)(declDir, (0, path_1.relative)(rootDir, file)).replace(/\.([cm]?[tj]s)x?$/, ".d.$1");
108
+ const mapFile = (0, paths_1.normalizePath)((0, path_1.resolve)(declDir, (0, path_1.relative)(rootDir, file)).replace(/\.([cm]?[tj]s)x?$/, ".d.$1"));
99
109
  declarationMapCache.set(mapFile, file);
100
110
  }
101
111
  }
@@ -194,7 +194,7 @@ export declare abstract class Reflection {
194
194
  /**
195
195
  * Return a child by its name.
196
196
  *
197
- * @param names The name hierarchy of the child to look for.
197
+ * @param arg The name hierarchy of the child to look for.
198
198
  * @returns The found child or undefined.
199
199
  */
200
200
  getChildByName(arg: string | string[]): Reflection | undefined;
@@ -227,6 +227,8 @@ export declare abstract class Reflection {
227
227
  /**
228
228
  * Return a string representation of this reflection and all of its children.
229
229
  *
230
+ * Note: This is intended as a debug tool only, output may change between patch versions.
231
+ *
230
232
  * @param indent Used internally to indent child reflections.
231
233
  */
232
234
  toStringHierarchy(indent?: string): string;
@@ -366,7 +366,7 @@ let Reflection = (() => {
366
366
  /**
367
367
  * Return a child by its name.
368
368
  *
369
- * @param names The name hierarchy of the child to look for.
369
+ * @param arg The name hierarchy of the child to look for.
370
370
  * @returns The found child or undefined.
371
371
  */
372
372
  getChildByName(arg) {
@@ -405,7 +405,7 @@ let Reflection = (() => {
405
405
  let signaturesDeprecated = false;
406
406
  this.visit({
407
407
  declaration(decl) {
408
- if (decl.signatures &&
408
+ if (decl.signatures?.length &&
409
409
  decl.signatures.every((sig) => sig.comment?.getTag("@deprecated"))) {
410
410
  signaturesDeprecated = true;
411
411
  }
@@ -428,6 +428,8 @@ let Reflection = (() => {
428
428
  /**
429
429
  * Return a string representation of this reflection and all of its children.
430
430
  *
431
+ * Note: This is intended as a debug tool only, output may change between patch versions.
432
+ *
431
433
  * @param indent Used internally to indent child reflections.
432
434
  */
433
435
  toStringHierarchy(indent = "") {
@@ -104,7 +104,7 @@ class DeclarationReflection extends container_1.ContainerReflection {
104
104
  result += "<" + parameters.join(", ") + ">";
105
105
  }
106
106
  if (this.type) {
107
- result += ":" + this.type.toString();
107
+ result += ": " + this.type.toString();
108
108
  }
109
109
  return result;
110
110
  }
@@ -58,11 +58,17 @@ export declare namespace ReflectionKind {
58
58
  const Inheritable: number;
59
59
  /** @internal */
60
60
  const ContainsCallSignatures: number;
61
+ /** @internal */
62
+ const TypeReferenceTarget: number;
63
+ /** @internal */
64
+ const ValueReferenceTarget: number;
61
65
  /**
62
66
  * Note: This does not include Class/Interface, even though they technically could contain index signatures
63
67
  * @internal
64
68
  */
65
69
  const SignatureContainer: number;
70
+ const VariableContainer: number;
71
+ const MethodContainer: number;
66
72
  function singularString(kind: ReflectionKind): string;
67
73
  function pluralString(kind: ReflectionKind): string;
68
74
  function classString(kind: ReflectionKind): string;
@@ -87,11 +87,28 @@ var ReflectionKind;
87
87
  ReflectionKind.ContainsCallSignatures = ReflectionKind.Constructor |
88
88
  ReflectionKind.Function |
89
89
  ReflectionKind.Method;
90
+ // The differences between Type/Value here only really matter for
91
+ // possibly merged declarations where we have multiple reflections.
92
+ /** @internal */
93
+ ReflectionKind.TypeReferenceTarget = ReflectionKind.Interface |
94
+ ReflectionKind.TypeAlias |
95
+ ReflectionKind.Class |
96
+ ReflectionKind.Enum;
97
+ /** @internal */
98
+ ReflectionKind.ValueReferenceTarget = ReflectionKind.Module |
99
+ ReflectionKind.Namespace |
100
+ ReflectionKind.Variable |
101
+ ReflectionKind.Function;
90
102
  /**
91
103
  * Note: This does not include Class/Interface, even though they technically could contain index signatures
92
104
  * @internal
93
105
  */
94
106
  ReflectionKind.SignatureContainer = ReflectionKind.ContainsCallSignatures | ReflectionKind.Accessor;
107
+ ReflectionKind.VariableContainer = ReflectionKind.SomeModule | ReflectionKind.Project;
108
+ ReflectionKind.MethodContainer = ReflectionKind.ClassOrInterface |
109
+ ReflectionKind.VariableOrProperty |
110
+ ReflectionKind.FunctionOrMethod |
111
+ ReflectionKind.TypeLiteral;
95
112
  const SINGULARS = {
96
113
  [ReflectionKind.Enum]: "Enumeration",
97
114
  [ReflectionKind.EnumMember]: "Enumeration Member",
@@ -22,7 +22,7 @@ class ParameterReflection extends abstract_1.Reflection {
22
22
  * Return a string representation of this reflection.
23
23
  */
24
24
  toString() {
25
- return super.toString() + (this.type ? ":" + this.type.toString() : "");
25
+ return (super.toString() + (this.type ? ": " + this.type.toString() : ""));
26
26
  }
27
27
  toObject(serializer) {
28
28
  return {
@@ -81,10 +81,13 @@ export declare class ProjectReflection extends ContainerReflection {
81
81
  getReflectionFromSymbol(symbol: ts.Symbol): Reflection | undefined;
82
82
  /**
83
83
  * Gets the reflection associated with the given symbol id, if it exists.
84
+ * If there are multiple reflections associated with this symbol, gets the first one.
84
85
  * @internal
85
86
  */
86
87
  getReflectionFromSymbolId(symbolId: ReflectionSymbolId): Reflection | undefined;
87
88
  /** @internal */
89
+ getReflectionsFromSymbolId(symbolId: ReflectionSymbolId): Reflection[];
90
+ /** @internal */
88
91
  getSymbolIdFromReflection(reflection: Reflection): ReflectionSymbolId | undefined;
89
92
  /** @internal */
90
93
  registerSymbolId(reflection: Reflection, id: ReflectionSymbolId): void;
@@ -65,10 +65,27 @@ class ProjectReflection extends container_1.ContainerReflection {
65
65
  }
66
66
  this.reflections[reflection.id] = reflection;
67
67
  if (symbol) {
68
- const id = new ReflectionSymbolId_1.ReflectionSymbolId(symbol);
69
- this.symbolToReflectionIdMap.set(id, this.symbolToReflectionIdMap.get(id) ?? reflection.id);
70
- this.reflectionIdToSymbolIdMap.set(reflection.id, id);
71
68
  this.reflectionIdToSymbolMap.set(reflection.id, symbol);
69
+ const id = new ReflectionSymbolId_1.ReflectionSymbolId(symbol);
70
+ this.registerSymbolId(reflection, id);
71
+ // #2466
72
+ // If we just registered a member of a class or interface, then we need to check if
73
+ // we've registered this symbol before under the wrong parent reflection.
74
+ // This can happen because the compiler API will use non-dependently-typed symbols
75
+ // for properties of classes/interfaces which inherit them, so we can't rely on the
76
+ // property being unique for each class.
77
+ if (reflection.parent?.kindOf(kind_1.ReflectionKind.ClassOrInterface) &&
78
+ reflection.kindOf(kind_1.ReflectionKind.SomeMember)) {
79
+ const saved = this.symbolToReflectionIdMap.get(id);
80
+ const parentSymbolReflection = symbol.parent &&
81
+ this.getReflectionFromSymbol(symbol.parent);
82
+ if (typeof saved === "object" &&
83
+ saved.length > 1 &&
84
+ parentSymbolReflection) {
85
+ (0, utils_1.removeIf)(saved, (item) => this.getReflectionById(item)?.parent !==
86
+ parentSymbolReflection);
87
+ }
88
+ }
72
89
  }
73
90
  }
74
91
  /**
@@ -91,6 +108,9 @@ class ProjectReflection extends container_1.ContainerReflection {
91
108
  }
92
109
  if (property === abstract_1.TraverseProperty.Children) {
93
110
  (0, utils_1.removeIfPresent)(parent.children, reflection);
111
+ if (!parent.children?.length) {
112
+ delete parent.children;
113
+ }
94
114
  }
95
115
  else if (property === abstract_1.TraverseProperty.GetSignature) {
96
116
  delete parent.getSignature;
@@ -100,18 +120,29 @@ class ProjectReflection extends container_1.ContainerReflection {
100
120
  }
101
121
  else if (property === abstract_1.TraverseProperty.Parameters) {
102
122
  (0, utils_1.removeIfPresent)(reflection.parent.parameters, reflection);
123
+ if (!reflection.parent.parameters
124
+ ?.length) {
125
+ delete reflection.parent
126
+ .parameters;
127
+ }
103
128
  }
104
129
  else if (property === abstract_1.TraverseProperty.SetSignature) {
105
130
  delete parent.setSignature;
106
131
  }
107
132
  else if (property === abstract_1.TraverseProperty.Signatures) {
108
133
  (0, utils_1.removeIfPresent)(parent.signatures, reflection);
134
+ if (!parent.signatures?.length) {
135
+ delete parent.signatures;
136
+ }
109
137
  }
110
138
  else if (property === abstract_1.TraverseProperty.TypeLiteral) {
111
139
  parent.type = new types_1.IntrinsicType("Object");
112
140
  }
113
141
  else if (property === abstract_1.TraverseProperty.TypeParameter) {
114
142
  (0, utils_1.removeIfPresent)(parent.typeParameters, reflection);
143
+ if (!parent.typeParameters?.length) {
144
+ delete parent.typeParameters;
145
+ }
115
146
  }
116
147
  return false; // Stop iteration
117
148
  });
@@ -144,9 +175,13 @@ class ProjectReflection extends container_1.ContainerReflection {
144
175
  const symbol = this.reflectionIdToSymbolMap.get(reflection.id);
145
176
  if (symbol) {
146
177
  const id = new ReflectionSymbolId_1.ReflectionSymbolId(symbol);
147
- if (this.symbolToReflectionIdMap.get(id) === reflection.id) {
178
+ const saved = this.symbolToReflectionIdMap.get(id);
179
+ if (saved === reflection.id) {
148
180
  this.symbolToReflectionIdMap.delete(id);
149
181
  }
182
+ else if (typeof saved === "object") {
183
+ (0, utils_1.removeIfPresent)(saved, reflection.id);
184
+ }
150
185
  }
151
186
  this.reflectionIdToSymbolIdMap.delete(reflection.id);
152
187
  delete this.reflections[reflection.id];
@@ -167,13 +202,22 @@ class ProjectReflection extends container_1.ContainerReflection {
167
202
  }
168
203
  /**
169
204
  * Gets the reflection associated with the given symbol id, if it exists.
205
+ * If there are multiple reflections associated with this symbol, gets the first one.
170
206
  * @internal
171
207
  */
172
208
  getReflectionFromSymbolId(symbolId) {
209
+ return this.getReflectionsFromSymbolId(symbolId)[0];
210
+ }
211
+ /** @internal */
212
+ getReflectionsFromSymbolId(symbolId) {
173
213
  const id = this.symbolToReflectionIdMap.get(symbolId);
174
214
  if (typeof id === "number") {
175
- return this.getReflectionById(id);
215
+ return [this.getReflectionById(id)];
216
+ }
217
+ else if (typeof id === "object") {
218
+ return id.map((id) => this.getReflectionById(id));
176
219
  }
220
+ return [];
177
221
  }
178
222
  /** @internal */
179
223
  getSymbolIdFromReflection(reflection) {
@@ -182,7 +226,16 @@ class ProjectReflection extends container_1.ContainerReflection {
182
226
  /** @internal */
183
227
  registerSymbolId(reflection, id) {
184
228
  this.reflectionIdToSymbolIdMap.set(reflection.id, id);
185
- if (!this.symbolToReflectionIdMap.has(id)) {
229
+ const previous = this.symbolToReflectionIdMap.get(id);
230
+ if (previous) {
231
+ if (typeof previous === "number") {
232
+ this.symbolToReflectionIdMap.set(id, [previous, reflection.id]);
233
+ }
234
+ else {
235
+ previous.push(reflection.id);
236
+ }
237
+ }
238
+ else {
186
239
  this.symbolToReflectionIdMap.set(id, reflection.id);
187
240
  }
188
241
  }
@@ -39,7 +39,7 @@ class SignatureReflection extends abstract_1.Reflection {
39
39
  result += "<" + parameters.join(", ") + ">";
40
40
  }
41
41
  if (this.type) {
42
- result += ":" + this.type.toString();
42
+ result += ": " + this.type.toString();
43
43
  }
44
44
  return result;
45
45
  }
@@ -16,7 +16,7 @@ export declare class SourceReference {
16
16
  */
17
17
  fullFileName: string;
18
18
  /**
19
- * The number of the line that emitted the declaration.
19
+ * The one based number of the line that emitted the declaration.
20
20
  */
21
21
  line: number;
22
22
  /**
@@ -365,6 +365,11 @@ export declare class ReferenceType extends Type {
365
365
  * be registered on the project.
366
366
  */
367
367
  refersToTypeParameter: boolean;
368
+ /**
369
+ * If set, will prefer reflections with {@link ReflectionKind | ReflectionKinds} which represent
370
+ * values rather than those which represent types.
371
+ */
372
+ preferValues: boolean;
368
373
  private _target;
369
374
  private _project;
370
375
  private constructor();