typedoc 0.25.2 → 0.25.3

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.
@@ -96,6 +96,7 @@ const application_events_1 = require("./application-events");
96
96
  const tsconfig_1 = require("./utils/tsconfig");
97
97
  const fs_1 = require("./utils/fs");
98
98
  const abstract_1 = require("./models/reflections/abstract");
99
+ const ReflectionSymbolId_1 = require("./models/reflections/ReflectionSymbolId");
99
100
  // eslint-disable-next-line @typescript-eslint/no-var-requires
100
101
  const packageInfo = require("../../package.json");
101
102
  const supportedVersionMajorMinor = packageInfo.peerDependencies.typescript
@@ -451,9 +452,10 @@ let Application = (() => {
451
452
  }
452
453
  const origOptions = this.options;
453
454
  const projects = [];
455
+ const projectsToConvert = [];
454
456
  // Generate a json file for each package
455
457
  for (const dir of packageDirs) {
456
- this.logger.info(`Converting project at ${(0, paths_1.nicePath)(dir)}`);
458
+ this.logger.verbose(`Reading project at ${(0, paths_1.nicePath)(dir)}`);
457
459
  const opts = origOptions.copyForPackage(dir);
458
460
  await opts.read(this.logger, dir);
459
461
  // Invalid links should only be reported after everything has been merged.
@@ -463,7 +465,12 @@ let Application = (() => {
463
465
  this.logger.error(`Project at ${(0, paths_1.nicePath)(dir)} has entryPointStrategy set to packages, but nested packages are not supported.`);
464
466
  continue;
465
467
  }
466
- this.options = opts;
468
+ (0, ReflectionSymbolId_1.addInferredDeclarationMapPaths)(opts.getCompilerOptions(), opts.getFileNames());
469
+ projectsToConvert.push({ dir, options: opts });
470
+ }
471
+ for (const { dir, options } of projectsToConvert) {
472
+ this.logger.info(`Converting project at ${(0, paths_1.nicePath)(dir)}`);
473
+ this.options = options;
467
474
  const project = await this.convert();
468
475
  if (project) {
469
476
  this.validate(project);
@@ -21,6 +21,7 @@ function convertIndexSignature(context, symbol) {
21
21
  const param = indexDeclaration.parameters[0];
22
22
  (0, assert_1.default)(param && typescript_1.default.isParameter(param));
23
23
  const index = new models_1.SignatureReflection("__index", models_1.ReflectionKind.IndexSignature, context.scope);
24
+ index.comment = context.getComment(indexSymbol, index.kind);
24
25
  index.parameters = [
25
26
  new models_1.ParameterReflection(param.name.getText(), models_1.ReflectionKind.Parameter, index),
26
27
  ];
@@ -572,7 +572,10 @@ function convertAccessor(context, symbol, exportSymbol) {
572
572
  }
573
573
  function isInherited(context, symbol) {
574
574
  const parentSymbol = context.project.getSymbolFromReflection(context.scope);
575
- (0, assert_1.default)(parentSymbol, `No parent symbol found for ${symbol.name} in ${context.scope.name}`);
575
+ // It'd be nice to be able to assert that this is true, but sometimes object
576
+ // types don't get symbols if they are inferred.
577
+ if (!parentSymbol)
578
+ return false;
576
579
  const parents = parentSymbol.declarations?.slice() || [];
577
580
  const constructorDecls = parents.flatMap((parent) => typescript_1.default.isClassDeclaration(parent)
578
581
  ? parent.members.filter(typescript_1.default.isConstructorDeclaration)
@@ -164,13 +164,14 @@ const constructorConverter = {
164
164
  return new models_1.ReflectionType(reflection);
165
165
  },
166
166
  convertType(context, type) {
167
- if (!type.symbol) {
167
+ const symbol = type.getSymbol();
168
+ if (!symbol) {
168
169
  return new models_1.IntrinsicType("Function");
169
170
  }
170
171
  const reflection = new models_1.DeclarationReflection("__type", models_1.ReflectionKind.Constructor, context.scope);
171
- context.registerReflection(reflection, type.symbol);
172
+ context.registerReflection(reflection, symbol);
172
173
  context.trigger(converter_events_1.ConverterEvents.CREATE_DECLARATION, reflection);
173
- (0, signature_1.createSignature)(context.withScope(reflection), models_1.ReflectionKind.ConstructorSignature, type.getConstructSignatures()[0], type.symbol);
174
+ (0, signature_1.createSignature)(context.withScope(reflection), models_1.ReflectionKind.ConstructorSignature, type.getConstructSignatures()[0], symbol);
174
175
  return new models_1.ReflectionType(reflection);
175
176
  },
176
177
  };
@@ -212,11 +213,12 @@ const functionTypeConverter = {
212
213
  return new models_1.ReflectionType(reflection);
213
214
  },
214
215
  convertType(context, type) {
215
- if (!type.symbol) {
216
+ const symbol = type.getSymbol();
217
+ if (!symbol) {
216
218
  return new models_1.IntrinsicType("Function");
217
219
  }
218
220
  const reflection = new models_1.DeclarationReflection("__type", models_1.ReflectionKind.TypeLiteral, context.scope);
219
- context.registerReflection(reflection, type.symbol);
221
+ context.registerReflection(reflection, symbol);
220
222
  context.trigger(converter_events_1.ConverterEvents.CREATE_DECLARATION, reflection);
221
223
  (0, signature_1.createSignature)(context.withScope(reflection), models_1.ReflectionKind.CallSignature, type.getCallSignatures()[0], type.getSymbol());
222
224
  return new models_1.ReflectionType(reflection);
@@ -251,7 +253,7 @@ const inferredConverter = {
251
253
  return new models_1.InferredType(node.typeParameter.name.text, maybeConvertType(context, node.typeParameter.constraint));
252
254
  },
253
255
  convertType(context, type) {
254
- return new models_1.InferredType(type.symbol.name, maybeConvertType(context, type.getConstraint()));
256
+ return new models_1.InferredType(type.getSymbol().name, maybeConvertType(context, type.getConstraint()));
255
257
  },
256
258
  };
257
259
  const intersectionConverter = {
@@ -372,22 +374,22 @@ const typeLiteralConverter = {
372
374
  return new models_1.ReflectionType(reflection);
373
375
  },
374
376
  convertType(context, type) {
375
- if (!type.symbol) {
376
- return new models_1.IntrinsicType("Object");
377
- }
377
+ const symbol = type.getSymbol();
378
378
  const reflection = new models_1.DeclarationReflection("__type", models_1.ReflectionKind.TypeLiteral, context.scope);
379
- context.registerReflection(reflection, type.symbol);
379
+ context.registerReflection(reflection, symbol);
380
380
  context.trigger(converter_events_1.ConverterEvents.CREATE_DECLARATION, reflection);
381
381
  for (const prop of context.checker.getPropertiesOfType(type)) {
382
382
  (0, symbols_1.convertSymbol)(context.withScope(reflection), prop);
383
383
  }
384
384
  for (const signature of type.getCallSignatures()) {
385
- (0, signature_1.createSignature)(context.withScope(reflection), models_1.ReflectionKind.CallSignature, signature, type.symbol);
385
+ (0, signature_1.createSignature)(context.withScope(reflection), models_1.ReflectionKind.CallSignature, signature, symbol);
386
386
  }
387
387
  for (const signature of type.getConstructSignatures()) {
388
- (0, signature_1.createSignature)(context.withScope(reflection), models_1.ReflectionKind.ConstructorSignature, signature, type.symbol);
388
+ (0, signature_1.createSignature)(context.withScope(reflection), models_1.ReflectionKind.ConstructorSignature, signature, symbol);
389
+ }
390
+ if (symbol) {
391
+ (0, index_signature_1.convertIndexSignature)(context.withScope(reflection), symbol);
389
392
  }
390
- (0, index_signature_1.convertIndexSignature)(context.withScope(reflection), type.symbol);
391
393
  return new models_1.ReflectionType(reflection);
392
394
  },
393
395
  };
@@ -27,3 +27,4 @@ export declare class ReflectionSymbolId {
27
27
  qualifiedName: string;
28
28
  };
29
29
  }
30
+ export declare function addInferredDeclarationMapPaths(opts: ts.CompilerOptions, files: readonly string[]): void;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ReflectionSymbolId = void 0;
6
+ exports.addInferredDeclarationMapPaths = exports.ReflectionSymbolId = void 0;
7
7
  const fs_1 = require("fs");
8
8
  const path_1 = require("path");
9
9
  const typescript_1 = __importDefault(require("typescript"));
@@ -20,7 +20,7 @@ class ReflectionSymbolId {
20
20
  constructor(symbol, declaration) {
21
21
  if ("name" in symbol) {
22
22
  declaration ??= symbol?.declarations?.[0];
23
- this.fileName = (0, paths_1.normalizePath)(declaration?.getSourceFile().fileName ?? "\0");
23
+ this.fileName = (0, paths_1.normalizePath)(declaration?.getSourceFile().fileName ?? "");
24
24
  if (symbol.declarations?.some(typescript_1.default.isSourceFile)) {
25
25
  this.qualifiedName = "";
26
26
  }
@@ -44,21 +44,19 @@ class ReflectionSymbolId {
44
44
  }
45
45
  }
46
46
  toObject(serializer) {
47
+ const sourceFileName = (0, path_1.isAbsolute)(this.fileName)
48
+ ? (0, paths_1.normalizePath)((0, path_1.relative)(serializer.projectRoot, resolveDeclarationMaps(this.fileName)))
49
+ : this.fileName;
47
50
  return {
48
- sourceFileName: (0, path_1.isAbsolute)(this.fileName)
49
- ? (0, paths_1.normalizePath)((0, path_1.relative)(serializer.projectRoot, resolveDeclarationMaps(this.fileName)))
50
- : this.fileName,
51
+ sourceFileName,
51
52
  qualifiedName: this.qualifiedName,
52
53
  };
53
54
  }
54
55
  }
55
56
  exports.ReflectionSymbolId = ReflectionSymbolId;
56
57
  const declarationMapCache = new Map();
57
- /**
58
- * See also getTsSourceFromJsSource in package-manifest.ts.
59
- */
60
58
  function resolveDeclarationMaps(file) {
61
- if (!file.endsWith(".d.ts"))
59
+ if (!/\.d\.[cm]?ts$/.test(file))
62
60
  return file;
63
61
  if (declarationMapCache.has(file))
64
62
  return declarationMapCache.get(file);
@@ -93,3 +91,12 @@ function resolveDeclarationMaps(file) {
93
91
  }
94
92
  return file;
95
93
  }
94
+ function addInferredDeclarationMapPaths(opts, files) {
95
+ const rootDir = opts.rootDir || (0, fs_2.getCommonDirectory)(files);
96
+ const declDir = opts.declarationDir || opts.outDir || rootDir;
97
+ 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");
99
+ declarationMapCache.set(mapFile, file);
100
+ }
101
+ }
102
+ exports.addInferredDeclarationMapPaths = addInferredDeclarationMapPaths;
@@ -1,10 +1,45 @@
1
1
  "use strict";
2
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
3
+ var useValue = arguments.length > 2;
4
+ for (var i = 0; i < initializers.length; i++) {
5
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
6
+ }
7
+ return useValue ? value : void 0;
8
+ };
9
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
10
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
11
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
12
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
13
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
14
+ var _, done = false;
15
+ for (var i = decorators.length - 1; i >= 0; i--) {
16
+ var context = {};
17
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
18
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
19
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
20
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
21
+ if (kind === "accessor") {
22
+ if (result === void 0) continue;
23
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
24
+ if (_ = accept(result.get)) descriptor.get = _;
25
+ if (_ = accept(result.set)) descriptor.set = _;
26
+ if (_ = accept(result.init)) initializers.unshift(_);
27
+ }
28
+ else if (_ = accept(result)) {
29
+ if (kind === "field") initializers.unshift(_);
30
+ else descriptor[key] = _;
31
+ }
32
+ }
33
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
34
+ done = true;
35
+ };
2
36
  Object.defineProperty(exports, "__esModule", { value: true });
3
37
  exports.Reflection = exports.TraverseProperty = exports.ReflectionFlags = exports.ReflectionFlag = exports.resetReflectionID = void 0;
4
38
  const assert_1 = require("assert");
5
39
  const comment_1 = require("../comments/comment");
6
40
  const utils_1 = require("./utils");
7
41
  const kind_1 = require("./kind");
42
+ const general_1 = require("../../utils/general");
8
43
  /**
9
44
  * Current reflection id.
10
45
  */
@@ -207,214 +242,236 @@ var TraverseProperty;
207
242
  * contains a list of all children grouped and sorted for rendering.
208
243
  * @category Reflections
209
244
  */
210
- class Reflection {
211
- get project() {
212
- if (this.isProject())
213
- return this;
214
- (0, assert_1.ok)(this.parent, "Tried to get the project on a reflection not in a project");
215
- return this.parent.project;
216
- }
217
- constructor(name, kind, parent) {
218
- this.flags = new ReflectionFlags();
219
- this.id = REFLECTION_ID++;
220
- this.parent = parent;
221
- this.name = name;
222
- this.kind = kind;
223
- // If our parent is external, we are too.
224
- if (parent?.flags.isExternal) {
225
- this.setFlag(ReflectionFlag.External);
226
- }
227
- }
228
- /**
229
- * Test whether this reflection is of the given kind.
230
- */
231
- kindOf(kind) {
232
- const kindArray = Array.isArray(kind) ? kind : [kind];
233
- return kindArray.some((kind) => (this.kind & kind) !== 0);
234
- }
235
- /**
236
- * Return the full name of this reflection. Intended for use in debugging. For log messages
237
- * intended to be displayed to the user for them to fix, prefer {@link getFriendlyFullName} instead.
238
- *
239
- * The full name contains the name of this reflection and the names of all parent reflections.
240
- *
241
- * @param separator Separator used to join the names of the reflections.
242
- * @returns The full name of this reflection.
243
- */
244
- getFullName(separator = ".") {
245
- if (this.parent && !this.parent.isProject()) {
246
- return this.parent.getFullName(separator) + separator + this.name;
247
- }
248
- else {
249
- return this.name;
250
- }
251
- }
252
- /**
253
- * Return the full name of this reflection, with signature names dropped if possible without
254
- * introducing ambiguity in the name.
255
- */
256
- getFriendlyFullName() {
257
- if (this.parent && !this.parent.isProject()) {
258
- if (this.kindOf(kind_1.ReflectionKind.ConstructorSignature |
259
- kind_1.ReflectionKind.CallSignature |
260
- kind_1.ReflectionKind.GetSignature |
261
- kind_1.ReflectionKind.SetSignature)) {
262
- return this.parent.getFriendlyFullName();
245
+ let Reflection = (() => {
246
+ var _a;
247
+ let _instanceExtraInitializers = [];
248
+ let _parent_decorators;
249
+ let _parent_initializers = [];
250
+ return _a = class Reflection {
251
+ get project() {
252
+ if (this.isProject())
253
+ return this;
254
+ (0, assert_1.ok)(this.parent, "Tried to get the project on a reflection not in a project");
255
+ return this.parent.project;
263
256
  }
264
- return this.parent.getFriendlyFullName() + "." + this.name;
265
- }
266
- else {
267
- return this.name;
268
- }
269
- }
270
- /**
271
- * Set a flag on this reflection.
272
- */
273
- setFlag(flag, value = true) {
274
- this.flags.setFlag(flag, value);
275
- }
276
- /**
277
- * Return an url safe alias for this reflection.
278
- */
279
- getAlias() {
280
- if (!this._alias) {
281
- let alias = this.name.replace(/\W/g, "_");
282
- if (alias === "") {
283
- alias = "reflection-" + this.id;
284
- }
285
- // NTFS/ExFAT use uppercase, so we will too. It probably won't matter
286
- // in this case since names will generally be valid identifiers, but to be safe...
287
- const upperAlias = alias.toUpperCase();
288
- let target = this;
289
- while (target.parent && !target.hasOwnDocument) {
290
- target = target.parent;
257
+ constructor(name, kind, parent) {
258
+ /**
259
+ * Unique id of this reflection.
260
+ */
261
+ this.id = (__runInitializers(this, _instanceExtraInitializers), void 0);
262
+ this.flags = new ReflectionFlags();
263
+ /**
264
+ * The reflection this reflection is a child of.
265
+ */
266
+ this.parent = __runInitializers(this, _parent_initializers, void 0);
267
+ this.id = REFLECTION_ID++;
268
+ this.parent = parent;
269
+ this.name = name;
270
+ this.kind = kind;
271
+ // If our parent is external, we are too.
272
+ if (parent?.flags.isExternal) {
273
+ this.setFlag(ReflectionFlag.External);
274
+ }
291
275
  }
292
- target._aliases ||= new Map();
293
- let suffix = "";
294
- if (!target._aliases.has(upperAlias)) {
295
- target._aliases.set(upperAlias, 1);
276
+ /**
277
+ * Test whether this reflection is of the given kind.
278
+ */
279
+ kindOf(kind) {
280
+ const kindArray = Array.isArray(kind) ? kind : [kind];
281
+ return kindArray.some((kind) => (this.kind & kind) !== 0);
296
282
  }
297
- else {
298
- const count = target._aliases.get(upperAlias);
299
- suffix = "-" + count.toString();
300
- target._aliases.set(upperAlias, count + 1);
283
+ /**
284
+ * Return the full name of this reflection. Intended for use in debugging. For log messages
285
+ * intended to be displayed to the user for them to fix, prefer {@link getFriendlyFullName} instead.
286
+ *
287
+ * The full name contains the name of this reflection and the names of all parent reflections.
288
+ *
289
+ * @param separator Separator used to join the names of the reflections.
290
+ * @returns The full name of this reflection.
291
+ */
292
+ getFullName(separator = ".") {
293
+ if (this.parent && !this.parent.isProject()) {
294
+ return this.parent.getFullName(separator) + separator + this.name;
295
+ }
296
+ else {
297
+ return this.name;
298
+ }
301
299
  }
302
- alias += suffix;
303
- this._alias = alias;
304
- }
305
- return this._alias;
306
- }
307
- /**
308
- * Has this reflection a visible comment?
309
- *
310
- * @returns TRUE when this reflection has a visible comment.
311
- */
312
- hasComment() {
313
- return this.comment ? this.comment.hasVisibleComponent() : false;
314
- }
315
- hasGetterOrSetter() {
316
- return false;
317
- }
318
- /**
319
- * Return a child by its name.
320
- *
321
- * @param names The name hierarchy of the child to look for.
322
- * @returns The found child or undefined.
323
- */
324
- getChildByName(arg) {
325
- const names = Array.isArray(arg)
326
- ? arg
327
- : (0, utils_1.splitUnquotedString)(arg, ".");
328
- const name = names[0];
329
- let result;
330
- this.traverse((child) => {
331
- if (child.name === name) {
332
- if (names.length <= 1) {
333
- result = child;
300
+ /**
301
+ * Return the full name of this reflection, with signature names dropped if possible without
302
+ * introducing ambiguity in the name.
303
+ */
304
+ getFriendlyFullName() {
305
+ if (this.parent && !this.parent.isProject()) {
306
+ if (this.kindOf(kind_1.ReflectionKind.ConstructorSignature |
307
+ kind_1.ReflectionKind.CallSignature |
308
+ kind_1.ReflectionKind.GetSignature |
309
+ kind_1.ReflectionKind.SetSignature)) {
310
+ return this.parent.getFriendlyFullName();
311
+ }
312
+ return this.parent.getFriendlyFullName() + "." + this.name;
334
313
  }
335
314
  else {
336
- result = child.getChildByName(names.slice(1));
315
+ return this.name;
316
+ }
317
+ }
318
+ /**
319
+ * Set a flag on this reflection.
320
+ */
321
+ setFlag(flag, value = true) {
322
+ this.flags.setFlag(flag, value);
323
+ }
324
+ /**
325
+ * Return an url safe alias for this reflection.
326
+ */
327
+ getAlias() {
328
+ if (!this._alias) {
329
+ let alias = this.name.replace(/\W/g, "_");
330
+ if (alias === "") {
331
+ alias = "reflection-" + this.id;
332
+ }
333
+ // NTFS/ExFAT use uppercase, so we will too. It probably won't matter
334
+ // in this case since names will generally be valid identifiers, but to be safe...
335
+ const upperAlias = alias.toUpperCase();
336
+ let target = this;
337
+ while (target.parent && !target.hasOwnDocument) {
338
+ target = target.parent;
339
+ }
340
+ target._aliases ||= new Map();
341
+ let suffix = "";
342
+ if (!target._aliases.has(upperAlias)) {
343
+ target._aliases.set(upperAlias, 1);
344
+ }
345
+ else {
346
+ const count = target._aliases.get(upperAlias);
347
+ suffix = "-" + count.toString();
348
+ target._aliases.set(upperAlias, count + 1);
349
+ }
350
+ alias += suffix;
351
+ this._alias = alias;
337
352
  }
353
+ return this._alias;
354
+ }
355
+ /**
356
+ * Has this reflection a visible comment?
357
+ *
358
+ * @returns TRUE when this reflection has a visible comment.
359
+ */
360
+ hasComment() {
361
+ return this.comment ? this.comment.hasVisibleComponent() : false;
362
+ }
363
+ hasGetterOrSetter() {
338
364
  return false;
339
365
  }
340
- return true;
341
- });
342
- return result;
343
- }
344
- /**
345
- * Return whether this reflection is the root / project reflection.
346
- */
347
- isProject() {
348
- return false;
349
- }
350
- isDeclaration() {
351
- return false;
352
- }
353
- /**
354
- * Check if this reflection or any of its parents have been marked with the `@deprecated` tag.
355
- */
356
- isDeprecated() {
357
- let signaturesDeprecated = false;
358
- this.visit({
359
- declaration(decl) {
360
- if (decl.signatures &&
361
- decl.signatures.every((sig) => sig.comment?.getTag("@deprecated"))) {
362
- signaturesDeprecated = true;
366
+ /**
367
+ * Return a child by its name.
368
+ *
369
+ * @param names The name hierarchy of the child to look for.
370
+ * @returns The found child or undefined.
371
+ */
372
+ getChildByName(arg) {
373
+ const names = Array.isArray(arg)
374
+ ? arg
375
+ : (0, utils_1.splitUnquotedString)(arg, ".");
376
+ const name = names[0];
377
+ let result;
378
+ this.traverse((child) => {
379
+ if (child.name === name) {
380
+ if (names.length <= 1) {
381
+ result = child;
382
+ }
383
+ else {
384
+ result = child.getChildByName(names.slice(1));
385
+ }
386
+ return false;
387
+ }
388
+ return true;
389
+ });
390
+ return result;
391
+ }
392
+ /**
393
+ * Return whether this reflection is the root / project reflection.
394
+ */
395
+ isProject() {
396
+ return false;
397
+ }
398
+ isDeclaration() {
399
+ return false;
400
+ }
401
+ /**
402
+ * Check if this reflection or any of its parents have been marked with the `@deprecated` tag.
403
+ */
404
+ isDeprecated() {
405
+ let signaturesDeprecated = false;
406
+ this.visit({
407
+ declaration(decl) {
408
+ if (decl.signatures &&
409
+ decl.signatures.every((sig) => sig.comment?.getTag("@deprecated"))) {
410
+ signaturesDeprecated = true;
411
+ }
412
+ },
413
+ });
414
+ if (signaturesDeprecated || this.comment?.getTag("@deprecated")) {
415
+ return true;
363
416
  }
364
- },
365
- });
366
- if (signaturesDeprecated || this.comment?.getTag("@deprecated")) {
367
- return true;
368
- }
369
- return this.parent?.isDeprecated() ?? false;
370
- }
371
- visit(visitor) {
372
- visitor[this.variant]?.(this);
373
- }
374
- /**
375
- * Return a string representation of this reflection.
376
- */
377
- toString() {
378
- return kind_1.ReflectionKind[this.kind] + " " + this.name;
379
- }
380
- /**
381
- * Return a string representation of this reflection and all of its children.
382
- *
383
- * @param indent Used internally to indent child reflections.
384
- */
385
- toStringHierarchy(indent = "") {
386
- const lines = [indent + this.toString()];
387
- indent += " ";
388
- this.traverse((child) => {
389
- lines.push(child.toStringHierarchy(indent));
390
- return true;
391
- });
392
- return lines.join("\n");
393
- }
394
- toObject(serializer) {
395
- return {
396
- id: this.id,
397
- name: this.name,
398
- variant: this.variant,
399
- kind: this.kind,
400
- flags: this.flags.toObject(),
401
- comment: this.comment && !this.comment.isEmpty()
402
- ? serializer.toObject(this.comment)
403
- : undefined,
404
- };
405
- }
406
- fromObject(de, obj) {
407
- // DO NOT copy id from obj. When deserializing reflections
408
- // they should be given new ids since they belong to a different project.
409
- this.name = obj.name;
410
- // Skip copying variant, we know it's already the correct value because the deserializer
411
- // will construct the correct class type.
412
- this.kind = obj.kind;
413
- this.flags.fromObject(obj.flags);
414
- // Parent is set during construction, so we don't need to do it here.
415
- this.comment = de.revive(obj.comment, () => new comment_1.Comment());
416
- // url, anchor, hasOwnDocument, _alias, _aliases are set during rendering and only relevant during render.
417
- // It doesn't make sense to serialize them to json, or restore them.
418
- }
419
- }
417
+ return this.parent?.isDeprecated() ?? false;
418
+ }
419
+ visit(visitor) {
420
+ visitor[this.variant]?.(this);
421
+ }
422
+ /**
423
+ * Return a string representation of this reflection.
424
+ */
425
+ toString() {
426
+ return kind_1.ReflectionKind[this.kind] + " " + this.name;
427
+ }
428
+ /**
429
+ * Return a string representation of this reflection and all of its children.
430
+ *
431
+ * @param indent Used internally to indent child reflections.
432
+ */
433
+ toStringHierarchy(indent = "") {
434
+ const lines = [indent + this.toString()];
435
+ indent += " ";
436
+ this.traverse((child) => {
437
+ lines.push(child.toStringHierarchy(indent));
438
+ return true;
439
+ });
440
+ return lines.join("\n");
441
+ }
442
+ toObject(serializer) {
443
+ return {
444
+ id: this.id,
445
+ name: this.name,
446
+ variant: this.variant,
447
+ kind: this.kind,
448
+ flags: this.flags.toObject(),
449
+ comment: this.comment && !this.comment.isEmpty()
450
+ ? serializer.toObject(this.comment)
451
+ : undefined,
452
+ };
453
+ }
454
+ fromObject(de, obj) {
455
+ // DO NOT copy id from obj. When deserializing reflections
456
+ // they should be given new ids since they belong to a different project.
457
+ this.name = obj.name;
458
+ // Skip copying variant, we know it's already the correct value because the deserializer
459
+ // will construct the correct class type.
460
+ this.kind = obj.kind;
461
+ this.flags.fromObject(obj.flags);
462
+ // Parent is set during construction, so we don't need to do it here.
463
+ this.comment = de.revive(obj.comment, () => new comment_1.Comment());
464
+ // url, anchor, hasOwnDocument, _alias, _aliases are set during rendering and only relevant during render.
465
+ // It doesn't make sense to serialize them to json, or restore them.
466
+ }
467
+ },
468
+ (() => {
469
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
470
+ _parent_decorators = [general_1.NonEnumerable // So that it doesn't show up in console.log
471
+ ];
472
+ __esDecorate(null, null, _parent_decorators, { kind: "field", name: "parent", static: false, private: false, access: { has: obj => "parent" in obj, get: obj => obj.parent, set: (obj, value) => { obj.parent = value; } }, metadata: _metadata }, _parent_initializers, _instanceExtraInitializers);
473
+ if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
474
+ })(),
475
+ _a;
476
+ })();
420
477
  exports.Reflection = Reflection;
@@ -203,25 +203,21 @@ output file :
203
203
  Marked.marked.setOptions(this.createMarkedOptions());
204
204
  delete this.includes;
205
205
  if (this.includeSource) {
206
- if (fs.existsSync(this.includeSource) &&
207
- fs.statSync(this.includeSource).isDirectory()) {
206
+ if (fs.existsSync(this.includeSource) && fs.statSync(this.includeSource).isDirectory()) {
208
207
  this.includes = this.includeSource;
209
208
  }
210
209
  else {
211
- this.application.logger.warn("Could not find provided includes directory: " +
212
- this.includeSource);
210
+ this.application.logger.warn("Could not find provided includes directory: " + this.includeSource);
213
211
  }
214
212
  }
215
213
  if (this.mediaSource) {
216
- if (fs.existsSync(this.mediaSource) &&
217
- fs.statSync(this.mediaSource).isDirectory()) {
214
+ if (fs.existsSync(this.mediaSource) && fs.statSync(this.mediaSource).isDirectory()) {
218
215
  this.mediaDirectory = Path.join(event.outputDirectory, "media");
219
216
  (0, utils_1.copySync)(this.mediaSource, this.mediaDirectory);
220
217
  }
221
218
  else {
222
219
  this.mediaDirectory = undefined;
223
- this.application.logger.warn("Could not find provided media directory: " +
224
- this.mediaSource);
220
+ this.application.logger.warn("Could not find provided media directory: " + this.mediaSource);
225
221
  }
226
222
  }
227
223
  }
@@ -236,6 +232,12 @@ output file :
236
232
  markedOptions.highlight ??= (text, lang) => this.getHighlighted(text, lang);
237
233
  if (!markedOptions.renderer) {
238
234
  markedOptions.renderer = new Marked.Renderer();
235
+ markedOptions.renderer.link = (href, title, text) => {
236
+ // Prefix the #anchor links `#md:`.
237
+ const target = href?.replace(/^#(?:md:)?(.+)/, "#md:$1") || undefined;
238
+ return (0, utils_1.renderElement)(utils_1.JSX.createElement("a", { href: target, title: title || undefined },
239
+ utils_1.JSX.createElement(utils_1.JSX.Raw, { html: text })));
240
+ };
239
241
  markedOptions.renderer.heading = (text, level, _, slugger) => {
240
242
  const slug = slugger.slug(text);
241
243
  // Prefix the slug with an extra `md:` to prevent conflicts with TypeDoc's anchors.
@@ -244,7 +246,12 @@ output file :
244
246
  text: (0, html_1.getTextContent)(text),
245
247
  level,
246
248
  });
247
- return `<a id="md:${slug}" class="tsd-anchor"></a><h${level}><a href="#md:${slug}">${text}</a></h${level}>`;
249
+ const H = `h${level}`;
250
+ return (0, utils_1.renderElement)(utils_1.JSX.createElement(utils_1.JSX.Fragment, null,
251
+ utils_1.JSX.createElement("a", { id: `md:${slug}`, class: "tsd-anchor" }),
252
+ utils_1.JSX.createElement(H, null,
253
+ utils_1.JSX.createElement("a", { href: `#md:${slug}` },
254
+ utils_1.JSX.createElement(utils_1.JSX.Raw, { html: text })))));
248
255
  };
249
256
  markedOptions.renderer.code = renderCode;
250
257
  }
@@ -8,6 +8,6 @@ function footer(context) {
8
8
  return (utils_1.JSX.createElement("div", { class: "tsd-generator" },
9
9
  utils_1.JSX.createElement("p", null,
10
10
  "Generated using ",
11
- utils_1.JSX.createElement("a", { href: "https://typedoc.org/", rel: "noopener", target: "_blank" }, "TypeDoc"))));
11
+ utils_1.JSX.createElement("a", { href: "https://typedoc.org/", target: "_blank" }, "TypeDoc"))));
12
12
  }
13
13
  exports.footer = footer;
@@ -2,6 +2,29 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.memberSources = void 0;
4
4
  const utils_1 = require("../../../../utils");
5
+ function sourceLink(context, item) {
6
+ if (!item.url) {
7
+ return (utils_1.JSX.createElement("li", null,
8
+ "Defined in ",
9
+ item.fileName,
10
+ ":",
11
+ item.line));
12
+ }
13
+ if (context.options.getValue("sourceLinkExternal")) {
14
+ return (utils_1.JSX.createElement("li", null,
15
+ "Defined in ",
16
+ utils_1.JSX.createElement("a", { href: item.url, class: "external", target: "_blank" },
17
+ item.fileName,
18
+ ":",
19
+ item.line)));
20
+ }
21
+ return (utils_1.JSX.createElement("li", null,
22
+ "Defined in ",
23
+ utils_1.JSX.createElement("a", { href: item.url },
24
+ item.fileName,
25
+ ":",
26
+ item.line)));
27
+ }
5
28
  const memberSources = (context, props) => {
6
29
  const sources = [];
7
30
  if (props.implementationOf) {
@@ -19,17 +42,8 @@ const memberSources = (context, props) => {
19
42
  "Overrides ",
20
43
  context.typeAndParent(props.overwrites)));
21
44
  }
22
- if (props.sources) {
23
- sources.push(utils_1.JSX.createElement("ul", null, props.sources.map((item) => item.url ? (utils_1.JSX.createElement("li", null,
24
- "Defined in ",
25
- utils_1.JSX.createElement("a", { href: item.url },
26
- item.fileName,
27
- ":",
28
- item.line))) : (utils_1.JSX.createElement("li", null,
29
- "Defined in ",
30
- item.fileName,
31
- ":",
32
- item.line)))));
45
+ if (props.sources?.length) {
46
+ sources.push(utils_1.JSX.createElement("ul", null, props.sources.map((item) => sourceLink(context, item))));
33
47
  }
34
48
  if (sources.length === 0) {
35
49
  return utils_1.JSX.createElement(utils_1.JSX.Fragment, null);
@@ -38,6 +38,7 @@ export type Chars<T extends string> = T extends `${infer C}${infer R}` ? C | Cha
38
38
  * Utility to help type checking ensure that there is no uncovered case.
39
39
  */
40
40
  export declare function assertNever(x: never): never;
41
+ export declare function NonEnumerable(_cls: unknown, context: ClassFieldDecoratorContext): void;
41
42
  export declare function hasBeenLoadedMultipleTimes(): boolean;
42
43
  export declare function getLoadedPaths(): string[];
43
44
  export {};
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.getLoadedPaths = exports.hasBeenLoadedMultipleTimes = exports.assertNever = void 0;
26
+ exports.getLoadedPaths = exports.hasBeenLoadedMultipleTimes = exports.NonEnumerable = exports.assertNever = void 0;
27
27
  const path_1 = require("path");
28
28
  const Util = __importStar(require("util"));
29
29
  /**
@@ -33,6 +33,16 @@ function assertNever(x) {
33
33
  throw new Error(`Expected handling to cover all possible cases, but it didn't cover: ${Util.inspect(x)}`);
34
34
  }
35
35
  exports.assertNever = assertNever;
36
+ function NonEnumerable(_cls, context) {
37
+ context.addInitializer(function () {
38
+ Object.defineProperty(this, context.name, {
39
+ enumerable: false,
40
+ configurable: true,
41
+ writable: true,
42
+ });
43
+ });
44
+ }
45
+ exports.NonEnumerable = NonEnumerable;
36
46
  /**
37
47
  * This is a hack to make it possible to detect and warn about installation setups
38
48
  * which result in TypeDoc being installed multiple times. If TypeDoc has been loaded
@@ -89,7 +89,7 @@ const renderElement = function renderElement(element) {
89
89
  }
90
90
  let html = "";
91
91
  if (tag !== jsx_elements_1.JsxFragment) {
92
- if (blockElements.has(tag) && renderPretty) {
92
+ if (blockElements.has(tag) && renderPretty && html) {
93
93
  html += "\n";
94
94
  }
95
95
  html += "<";
@@ -106,8 +106,9 @@ const renderElement = function renderElement(element) {
106
106
  else {
107
107
  html += " ";
108
108
  html += key;
109
- html += "=";
110
- html += JSON.stringify(val);
109
+ html += '="';
110
+ html += (typeof val === "string" ? val : JSON.stringify(val)).replaceAll('"', "&quot;");
111
+ html += '"';
111
112
  }
112
113
  }
113
114
  }
@@ -76,6 +76,7 @@ export interface TypeDocOptionMap {
76
76
  includeVersion: boolean;
77
77
  disableSources: boolean;
78
78
  sourceLinkTemplate: string;
79
+ sourceLinkExternal: boolean;
79
80
  disableGit: boolean;
80
81
  gitRevision: string;
81
82
  gitRemote: string;
@@ -292,6 +292,24 @@ function addTypeDocOptions(options) {
292
292
  help: "Disable setting the source of a reflection when documenting it.",
293
293
  type: declaration_1.ParameterType.Boolean,
294
294
  });
295
+ options.addDeclaration({
296
+ name: "sourceLinkTemplate",
297
+ help: "Specify a link template to be used when generating source urls. If not set, will be automatically created using the git remote. Supports {path}, {line}, {gitRevision} placeholders.",
298
+ });
299
+ options.addDeclaration({
300
+ name: "gitRevision",
301
+ help: "Use specified revision instead of the last revision for linking to GitHub/Bitbucket source files. Has no effect if disableSources is set.",
302
+ });
303
+ options.addDeclaration({
304
+ name: "gitRemote",
305
+ help: "Use the specified remote for linking to GitHub/Bitbucket source files. Has no effect if disableGit or disableSources is set.",
306
+ defaultValue: "origin",
307
+ });
308
+ options.addDeclaration({
309
+ name: "disableGit",
310
+ help: "Assume that all can be linked to with the sourceLinkTemplate, sourceLinkTemplate must be set if this is enabled. {path} will be rooted at basePath",
311
+ type: declaration_1.ParameterType.Boolean,
312
+ });
295
313
  options.addDeclaration({
296
314
  name: "basePath",
297
315
  help: "Specifies the base path to be used when displaying file paths.",
@@ -329,23 +347,10 @@ function addTypeDocOptions(options) {
329
347
  help: "Set the CNAME file text, it's useful for custom domains on GitHub Pages.",
330
348
  });
331
349
  options.addDeclaration({
332
- name: "sourceLinkTemplate",
333
- help: "Specify a link template to be used when generating source urls. If not set, will be automatically created using the git remote. Supports {path}, {line}, {gitRevision} placeholders.",
334
- });
335
- options.addDeclaration({
336
- name: "disableGit",
337
- help: "Assume that all can be linked to with the sourceLinkTemplate, sourceLinkTemplate must be set if this is enabled. {path} will be rooted at basePath",
350
+ name: "sourceLinkExternal",
351
+ help: "Specifies that source links should be treated as external links to be opened in a new tab.",
338
352
  type: declaration_1.ParameterType.Boolean,
339
353
  });
340
- options.addDeclaration({
341
- name: "gitRevision",
342
- help: "Use specified revision instead of the last revision for linking to GitHub/Bitbucket source files. Has no effect if disableSources is set.",
343
- });
344
- options.addDeclaration({
345
- name: "gitRemote",
346
- help: "Use the specified remote for linking to GitHub/Bitbucket source files. Has no effect if disableGit or disableSources is set.",
347
- defaultValue: "origin",
348
- });
349
354
  options.addDeclaration({
350
355
  name: "githubPages",
351
356
  help: "Generate a .nojekyll file to prevent 404 errors in GitHub Pages. Defaults to `true`.",
@@ -4,6 +4,6 @@
4
4
  */
5
5
  import type { DeclarationReflection } from "../models/reflections/declaration";
6
6
  import type { Options } from "./options";
7
- export declare const SORT_STRATEGIES: readonly ["source-order", "alphabetical", "enum-value-ascending", "enum-value-descending", "enum-member-source-order", "static-first", "instance-first", "visibility", "required-first", "kind"];
7
+ export declare const SORT_STRATEGIES: readonly ["source-order", "alphabetical", "enum-value-ascending", "enum-value-descending", "enum-member-source-order", "static-first", "instance-first", "visibility", "required-first", "kind", "external-last"];
8
8
  export type SortStrategy = (typeof SORT_STRATEGIES)[number];
9
9
  export declare function getSortFunction(opts: Options): (reflections: DeclarationReflection[]) => void;
@@ -18,6 +18,7 @@ exports.SORT_STRATEGIES = [
18
18
  "visibility",
19
19
  "required-first",
20
20
  "kind",
21
+ "external-last",
21
22
  ];
22
23
  const defaultKindSortOrder = [
23
24
  kind_1.ReflectionKind.Reference,
@@ -120,6 +121,9 @@ const sorts = {
120
121
  kind(a, b, { kindSortOrder }) {
121
122
  return kindSortOrder.indexOf(a.kind) < kindSortOrder.indexOf(b.kind);
122
123
  },
124
+ "external-last"(a, b) {
125
+ return !a.flags.isExternal && b.flags.isExternal;
126
+ },
123
127
  };
124
128
  function getSortFunction(opts) {
125
129
  const kindSortOrder = opts
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "typedoc",
3
3
  "description": "Create api documentation for TypeScript projects.",
4
- "version": "0.25.2",
4
+ "version": "0.25.3",
5
5
  "homepage": "https://typedoc.org",
6
6
  "exports": {
7
7
  ".": "./dist/index.js",