From a429a0224447a94f7ee3e35b4c49607f646b5710 Mon Sep 17 00:00:00 2001 From: Gerrit Birkeland Date: Sun, 10 Apr 2022 15:58:44 -0600 Subject: [PATCH] Correct getAlias to always get unique aliases ... even if there's only one entry point. Resolves #1845 --- CHANGELOG.md | 3 ++- src/lib/models/reflections/abstract.ts | 12 +++--------- .../output/themes/default/DefaultTheme.tsx | 19 +------------------ 3 files changed, 6 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bfca3b706..af3cb08e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ These TODOs will be resolved before a full release. ([GitHub project](https://gi - `@inheritDoc` now follows the behavior specified by TSDoc when copying comments with a reference. - The `gaSite` option has been removed since Google Analytics now infers the site automatically, updated Google Analytics script to latest version, #1846. +- Comments on export declarations will only overrides comments for references and namespaces, #1901. - The deprecated `listInvalidSymbolLinks` option has been removed. Use `validation.invalidLink` instead. - The deprecated `true` and `false` values have been removed from `--emit`, to migrate replace `true` with `"both"` and `false` with `"docs"`. - Links are no longer be resolved against a global list of all symbols. See [the documentation](https://typedoc.org/guides/link-resolution/) for details on link resolution. @@ -28,7 +29,6 @@ These TODOs will be resolved before a full release. ([GitHub project](https://gi - Listeners to `Converter.EVENT_CREATE_TYPE_PARAMETER` and `Converter.EVENT_CREATE_DECLARATION` will now never be passed a `ts.Node` as their third argument. - Constant variables which are interpreted as functions will no longer have the `ReflectionFlag.Const` flag set. - Removed deprecated `removeReaderByName`, `addDeclarations` and `removeDeclarationByName` methods on `Options`. -- Comments on export declarations will only overrides comments for references and namespaces, #1901. ### Features @@ -47,6 +47,7 @@ These TODOs will be resolved before a full release. ([GitHub project](https://gi - Improved comment discovery on destructured exported functions, #1770. - Links which refer to members within a reference reflection will now correctly resolve to the referenced reflection's member, #1770. - Correctly detect optional parameters in JavaScript projects using JSDoc, #1804. +- Fixed identical anchor links for reflections with the same name, #1845. - JS exports defined as `exports.foo = ...` will now be converted as variables rather than properties. ### Thanks! diff --git a/src/lib/models/reflections/abstract.ts b/src/lib/models/reflections/abstract.ts index ac1efb756..4e8a9c243 100644 --- a/src/lib/models/reflections/abstract.ts +++ b/src/lib/models/reflections/abstract.ts @@ -414,18 +414,12 @@ export abstract class Reflection { alias = "reflection-" + this.id; } - let target = this; - while ( - target.parent && - !target.parent.isProject() && - !target.hasOwnDocument - ) { + let target = this as Reflection; + while (target.parent && !target.hasOwnDocument) { target = target.parent; } - if (!target._aliases) { - target._aliases = new Map(); - } + target._aliases ||= new Map(); let suffix = ""; if (!target._aliases.has(alias)) { diff --git a/src/lib/output/themes/default/DefaultTheme.tsx b/src/lib/output/themes/default/DefaultTheme.tsx index 3af40b967..38ff98701 100644 --- a/src/lib/output/themes/default/DefaultTheme.tsx +++ b/src/lib/output/themes/default/DefaultTheme.tsx @@ -25,12 +25,6 @@ interface TemplateMapping { */ kind: ReflectionKind[]; - /** - * Can this mapping have children or should all further reflections be rendered - * to the defined output page? - */ - isLeaf: boolean; - /** * The name of the directory the output files should be written to. */ @@ -73,43 +67,36 @@ export class DefaultTheme extends Theme { private mappings: TemplateMapping[] = [ { kind: [ReflectionKind.Class], - isLeaf: false, directory: "classes", template: this.reflectionTemplate, }, { kind: [ReflectionKind.Interface], - isLeaf: false, directory: "interfaces", template: this.reflectionTemplate, }, { kind: [ReflectionKind.Enum], - isLeaf: false, directory: "enums", template: this.reflectionTemplate, }, { kind: [ReflectionKind.Namespace, ReflectionKind.Module], - isLeaf: false, directory: "modules", template: this.reflectionTemplate, }, { kind: [ReflectionKind.TypeAlias], - isLeaf: false, directory: "types", template: this.reflectionTemplate, }, { kind: [ReflectionKind.Function], - isLeaf: false, directory: "functions", template: this.reflectionTemplate, }, { kind: [ReflectionKind.Variable], - isLeaf: false, directory: "variables", template: this.reflectionTemplate, }, @@ -225,11 +212,7 @@ export class DefaultTheme extends Theme { } for (const child of reflection.children || []) { - if (mapping.isLeaf) { - DefaultTheme.applyAnchorUrl(child, reflection); - } else { - this.buildUrls(child, urls); - } + this.buildUrls(child, urls); } } else if (reflection.parent) { DefaultTheme.applyAnchorUrl(reflection, reflection.parent);