From 7322a66c141023355da8389c34c0afb78d75a3d8 Mon Sep 17 00:00:00 2001 From: Cary Hu Date: Tue, 12 Jul 2022 11:44:45 +0800 Subject: [PATCH 01/20] fix excludeNotDocumented behavior --- src/lib/converter/plugins/CommentPlugin.ts | 22 +++++++++- src/test/converter2/issues/gh1994.d.ts | 48 ++++++++++++++++++++++ src/test/issueTests.ts | 9 ++++ 3 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 src/test/converter2/issues/gh1994.d.ts diff --git a/src/lib/converter/plugins/CommentPlugin.ts b/src/lib/converter/plugins/CommentPlugin.ts index e39e46d67..33287c9da 100644 --- a/src/lib/converter/plugins/CommentPlugin.ts +++ b/src/lib/converter/plugins/CommentPlugin.ts @@ -203,6 +203,26 @@ export class CommentPlugin extends ConverterComponent { this.removeExcludedTags(comment); } + private getHiddenItems(reflection: Reflection) { + const hiddenItems = new Set(); + if (reflection.kindOf(ReflectionKind.FunctionOrMethod)) { + const decl = reflection as DeclarationReflection; + if (decl.signatures) { + for (const sig of decl.signatures) { + if (!sig.comment) { + hiddenItems.add(sig); + } + } + } + if (!decl.signatures?.some(sig => sig.comment)) { + hiddenItems.add(decl); + } + } else { + hiddenItems.add(reflection); + } + return hiddenItems || []; + } + /** * Triggered when the converter begins resolving a project. * @@ -225,7 +245,7 @@ export class CommentPlugin extends ConverterComponent { } if (this.isHidden(ref)) { - hidden.add(ref); + this.getHiddenItems(ref).forEach(item => hidden.add(item)); } } hidden.forEach((reflection) => project.removeReflection(reflection)); diff --git a/src/test/converter2/issues/gh1994.d.ts b/src/test/converter2/issues/gh1994.d.ts new file mode 100644 index 000000000..defc2b4af --- /dev/null +++ b/src/test/converter2/issues/gh1994.d.ts @@ -0,0 +1,48 @@ +/** + * + * test 2 + */ +declare class Collection { + + /** + * + * @param {boolean} n Test boolean + */ + public case1(n: boolean) + public case1(n: number) + private case2() +} + + +/** + * Comment for case4 + */ +export declare type Case4 = { + case5: string; + + /** + * comment for case6 + * + * @param number1 test comment + */ + case6: (number1: number) => boolean; +} + +/** + * Comment for case7 + */ +export declare type case7 = (number1: number) => boolean; + +/** + * Rounds or truncates a number to a specified precision. + * + * @param value Value to round or truncate. + * @param prec Number of decimal digits for the result. + * @param truncate Whether to truncate or round the original value. + */ +declare function case3(value: number, prec: number, truncate: boolean): number; + +export { + Collection, + case3 +} diff --git a/src/test/issueTests.ts b/src/test/issueTests.ts index 85e160c31..048c3003d 100644 --- a/src/test/issueTests.ts +++ b/src/test/issueTests.ts @@ -608,4 +608,13 @@ export const issueTests: { logger.discardDebugMessages(); logger.expectNoOtherMessages(); }, + + gh1994(project, logger) { + const case1 = query(project, "Collection.case1"); + // TODO: I don't know how to add test case for this case + // and I added a test simple file in 'issues' folder. + // But I don't know how to test it. + logger.discardDebugMessages(); + logger.expectNoOtherMessages(); + } }; From d527647e5cc882affeb7b65f1e7b48e26c9c9cba Mon Sep 17 00:00:00 2001 From: Cary Hu Date: Tue, 12 Jul 2022 11:59:29 +0800 Subject: [PATCH 02/20] fix some warning --- src/test/issueTests.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/issueTests.ts b/src/test/issueTests.ts index 048c3003d..f2f1e4a25 100644 --- a/src/test/issueTests.ts +++ b/src/test/issueTests.ts @@ -609,8 +609,8 @@ export const issueTests: { logger.expectNoOtherMessages(); }, - gh1994(project, logger) { - const case1 = query(project, "Collection.case1"); + gh1994(_project, logger) { + // const case1 = query(project, "Collection.case1"); // TODO: I don't know how to add test case for this case // and I added a test simple file in 'issues' folder. // But I don't know how to test it. From 0f74511d5ebf0c954a970ea9bde74d31b4b45f93 Mon Sep 17 00:00:00 2001 From: Cary Hu Date: Tue, 12 Jul 2022 12:07:27 +0800 Subject: [PATCH 03/20] fix formatting error --- src/lib/converter/plugins/CommentPlugin.ts | 4 +- src/test/converter2/issues/gh1994.d.ts | 48 ---------------------- src/test/issueTests.ts | 2 +- 3 files changed, 3 insertions(+), 51 deletions(-) delete mode 100644 src/test/converter2/issues/gh1994.d.ts diff --git a/src/lib/converter/plugins/CommentPlugin.ts b/src/lib/converter/plugins/CommentPlugin.ts index 33287c9da..d14a077f4 100644 --- a/src/lib/converter/plugins/CommentPlugin.ts +++ b/src/lib/converter/plugins/CommentPlugin.ts @@ -214,7 +214,7 @@ export class CommentPlugin extends ConverterComponent { } } } - if (!decl.signatures?.some(sig => sig.comment)) { + if (!decl.signatures?.some((sig) => sig.comment)) { hiddenItems.add(decl); } } else { @@ -245,7 +245,7 @@ export class CommentPlugin extends ConverterComponent { } if (this.isHidden(ref)) { - this.getHiddenItems(ref).forEach(item => hidden.add(item)); + this.getHiddenItems(ref).forEach((item) => hidden.add(item)); } } hidden.forEach((reflection) => project.removeReflection(reflection)); diff --git a/src/test/converter2/issues/gh1994.d.ts b/src/test/converter2/issues/gh1994.d.ts deleted file mode 100644 index defc2b4af..000000000 --- a/src/test/converter2/issues/gh1994.d.ts +++ /dev/null @@ -1,48 +0,0 @@ -/** - * - * test 2 - */ -declare class Collection { - - /** - * - * @param {boolean} n Test boolean - */ - public case1(n: boolean) - public case1(n: number) - private case2() -} - - -/** - * Comment for case4 - */ -export declare type Case4 = { - case5: string; - - /** - * comment for case6 - * - * @param number1 test comment - */ - case6: (number1: number) => boolean; -} - -/** - * Comment for case7 - */ -export declare type case7 = (number1: number) => boolean; - -/** - * Rounds or truncates a number to a specified precision. - * - * @param value Value to round or truncate. - * @param prec Number of decimal digits for the result. - * @param truncate Whether to truncate or round the original value. - */ -declare function case3(value: number, prec: number, truncate: boolean): number; - -export { - Collection, - case3 -} diff --git a/src/test/issueTests.ts b/src/test/issueTests.ts index f2f1e4a25..a3b2cdbf9 100644 --- a/src/test/issueTests.ts +++ b/src/test/issueTests.ts @@ -616,5 +616,5 @@ export const issueTests: { // But I don't know how to test it. logger.discardDebugMessages(); logger.expectNoOtherMessages(); - } + }, }; From 7cff28616fd97bc0d71077a3b3145beecdcdb4ef Mon Sep 17 00:00:00 2001 From: Cary Hu Date: Tue, 12 Jul 2022 12:10:00 +0800 Subject: [PATCH 04/20] remove test case --- src/test/issueTests.ts | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/test/issueTests.ts b/src/test/issueTests.ts index a3b2cdbf9..85e160c31 100644 --- a/src/test/issueTests.ts +++ b/src/test/issueTests.ts @@ -608,13 +608,4 @@ export const issueTests: { logger.discardDebugMessages(); logger.expectNoOtherMessages(); }, - - gh1994(_project, logger) { - // const case1 = query(project, "Collection.case1"); - // TODO: I don't know how to add test case for this case - // and I added a test simple file in 'issues' folder. - // But I don't know how to test it. - logger.discardDebugMessages(); - logger.expectNoOtherMessages(); - }, }; From 9e23a1d95ee342f45d019d0e75b3e0b3f3e6a603 Mon Sep 17 00:00:00 2001 From: Chad Hietala Date: Wed, 13 Jul 2022 10:38:02 -0400 Subject: [PATCH 05/20] Add more Github Enterprise URLs This PR adds support for more github enterprise URLs. They offer: ``` *.ghe.com *.github.us ``` https://github.com/github/docs/blob/5f4ef9a6217181efc12e67463894783496fb0c79/content/admin/identity-and-access-management/using-saml-for-enterprise-iam/saml-configuration-reference.md#saml-response-requirements --- src/lib/converter/utils/repository.ts | 12 +++++++++++- src/test/Repository.test.ts | 26 ++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/lib/converter/utils/repository.ts b/src/lib/converter/utils/repository.ts index 99ba4cca1..b1087d80b 100644 --- a/src/lib/converter/utils/repository.ts +++ b/src/lib/converter/utils/repository.ts @@ -71,7 +71,7 @@ export class Repository { for (let i = 0, c = repoLinks.length; i < c; i++) { let match = - /(github(?:\.[a-z]+)*\.[a-z]{2,})[:/]([^/]+)\/(.*)/.exec( + /(github(?!.us)(?:\.[a-z]+)*\.[a-z]{2,})[:/]([^/]+)\/(.*)/.exec( repoLinks[i] ); @@ -82,6 +82,16 @@ export class Repository { ); } + // Github Enterprise + if (!match) { + match = /(\w+\.ghe.com)[:/]([^/]+)\/(.*)/.exec(repoLinks[i]); + } + + // Github Enterprise + if (!match) { + match = /(\w+\.github.us)[:/]([^/]+)\/(.*)/.exec(repoLinks[i]); + } + if (!match) { match = /(bitbucket.org)[:/]([^/]+)\/(.*)/.exec(repoLinks[i]); } diff --git a/src/test/Repository.test.ts b/src/test/Repository.test.ts index d1e2067dc..a2c40b774 100644 --- a/src/test/Repository.test.ts +++ b/src/test/Repository.test.ts @@ -46,6 +46,32 @@ describe("Repository", function () { equal(repository.type, RepositoryType.GitHub); }); + it("handles a ghe.com URL", function () { + const mockRemotes = [ + "ssh://org@bigcompany.ghe.com/joebloggs/foobar.git", + ]; + + const repository = new Repository("", "", mockRemotes); + + equal(repository.hostname, "bigcompany.ghe.com"); + equal(repository.user, "joebloggs"); + equal(repository.project, "foobar"); + equal(repository.type, RepositoryType.GitHub); + }); + + it("handles a github.us URL", function () { + const mockRemotes = [ + "ssh://org@bigcompany.github.us/joebloggs/foobar.git", + ]; + + const repository = new Repository("", "", mockRemotes); + + equal(repository.hostname, "bigcompany.github.us"); + equal(repository.user, "joebloggs"); + equal(repository.project, "foobar"); + equal(repository.type, RepositoryType.GitHub); + }); + it("handles a Bitbucket HTTPS URL", function () { const mockRemotes = [ "https://joebloggs@bitbucket.org/joebloggs/foobar.git", From e13a8f76d5d7ace2882fc033a124fc5026daed16 Mon Sep 17 00:00:00 2001 From: Gerrit Birkeland Date: Sun, 17 Jul 2022 14:30:30 -0600 Subject: [PATCH 06/20] Update changelog --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a886da89a..4d4e721e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Unreleased +### Features + +- Added support for `*.ghe.com` and `*.github.us` GitHub enterprise domains for source links, #2001. + +### Thanks! + +- @chadhietala + ## v0.23.7 (2022-07-09) ### Bug Fixes From 70ab81ac2aa1225188c811ec69e359296aac175e Mon Sep 17 00:00:00 2001 From: Gerrit Birkeland Date: Sun, 17 Jul 2022 14:43:14 -0600 Subject: [PATCH 07/20] Expose `Converter.parseRawComment` Closes #2004 --- CHANGELOG.md | 1 + src/lib/converter/converter.ts | 19 ++++++++++++++----- src/lib/converter/plugins/PackagePlugin.ts | 9 ++------- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d4e721e9..705f5de3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### Features - Added support for `*.ghe.com` and `*.github.us` GitHub enterprise domains for source links, #2001. +- Expose `Converter.parseRawComment` for plugins to parse additional markdown files, #2004. ### Thanks! diff --git a/src/lib/converter/converter.ts b/src/lib/converter/converter.ts index f94444d18..c963b082b 100644 --- a/src/lib/converter/converter.ts +++ b/src/lib/converter/converter.ts @@ -183,6 +183,18 @@ export class Converter extends ChildableComponent< return convertType(context, node); } + /** + * Parse the given file into a comment. Intended to be used with markdown files. + */ + parseRawComment(file: MinimalSourceFile) { + return parseComment( + lexCommentString(file.text), + this.config, + file, + this.application.logger + ); + } + /** * Compile the files within the given context and convert the compiler symbols to reflections. * @@ -264,11 +276,8 @@ export class Converter extends ChildableComponent< if (entryPoint.readmeFile) { const readme = readFile(entryPoint.readmeFile); - const comment = parseComment( - lexCommentString(readme), - context.converter.config, - new MinimalSourceFile(readme, entryPoint.readmeFile), - context.logger + const comment = this.parseRawComment( + new MinimalSourceFile(readme, entryPoint.readmeFile) ); if (comment.blockTags.length || comment.modifierTags.size) { diff --git a/src/lib/converter/plugins/PackagePlugin.ts b/src/lib/converter/plugins/PackagePlugin.ts index f48b43a87..85c7d0770 100644 --- a/src/lib/converter/plugins/PackagePlugin.ts +++ b/src/lib/converter/plugins/PackagePlugin.ts @@ -7,8 +7,6 @@ import type { Context } from "../context"; import { BindOption, EntryPointStrategy, readFile } from "../../utils"; import { getCommonDirectory } from "../../utils/fs"; import { nicePath } from "../../utils/paths"; -import { lexCommentString } from "../comments/rawLexer"; -import { parseComment } from "../comments/parser"; import { MinimalSourceFile } from "../../utils/minimalSourceFile"; /** @@ -105,11 +103,8 @@ export class PackagePlugin extends ConverterComponent { const project = context.project; if (this.readmeFile) { const readme = readFile(this.readmeFile); - const comment = parseComment( - lexCommentString(readme), - context.converter.config, - new MinimalSourceFile(readme, this.readmeFile), - context.logger + const comment = context.converter.parseRawComment( + new MinimalSourceFile(readme, this.readmeFile) ); if (comment.blockTags.length || comment.modifierTags.size) { From ec9efa0628005909cf49d4b0e649e7b51c0bbb05 Mon Sep 17 00:00:00 2001 From: Gerrit Birkeland Date: Sun, 17 Jul 2022 15:37:47 -0600 Subject: [PATCH 08/20] Fix source links for signatures Closes #180 Closes #1996 --- .config/typedoc.json | 2 +- CHANGELOG.md | 5 ++++ src/lib/converter/converter.ts | 3 ++- src/lib/converter/factories/signature.ts | 2 +- src/lib/converter/plugins/SourcePlugin.ts | 27 ++++++++++++++++++- .../themes/default/templates/reflection.tsx | 1 + src/test/converter/comment/specs.json | 8 ++++++ src/test/converter2/issues/gh1996.ts | 3 +++ src/test/issueTests.ts | 11 ++++++++ static/style.css | 2 +- 10 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 src/test/converter2/issues/gh1996.ts diff --git a/.config/typedoc.json b/.config/typedoc.json index 7c97d4b06..ae6df8d04 100644 --- a/.config/typedoc.json +++ b/.config/typedoc.json @@ -11,7 +11,7 @@ "MarkedPlugin" ], "entryPoints": ["../src"], - "entryPointStrategy": "Resolve", + "entryPointStrategy": "resolve", "excludeExternals": true, "excludeInternal": false, "excludePrivate": true, diff --git a/CHANGELOG.md b/CHANGELOG.md index 705f5de3e..a28653d94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ - Added support for `*.ghe.com` and `*.github.us` GitHub enterprise domains for source links, #2001. - Expose `Converter.parseRawComment` for plugins to parse additional markdown files, #2004. +- Added defined in links for classes, enums #180. + +### Bug Fixes + +- Fixed missing `sources` property on signature reflections #1996. ### Thanks! diff --git a/src/lib/converter/converter.ts b/src/lib/converter/converter.ts index c963b082b..5834016b6 100644 --- a/src/lib/converter/converter.ts +++ b/src/lib/converter/converter.ts @@ -94,7 +94,8 @@ export class Converter extends ChildableComponent< /** * Triggered when the converter has created a signature reflection. - * The listener will be given {@link Context}, {@link SignatureReflection} | {@link ProjectReflection} and a `ts.Node?` + * The listener will be given {@link Context}, {@link SignatureReflection} | {@link ProjectReflection} and + * `ts.SignatureDeclaration | ts.IndexSignatureDeclaration | ts.JSDocSignature | undefined` * @event */ static readonly EVENT_CREATE_SIGNATURE = ConverterEvents.CREATE_SIGNATURE; diff --git a/src/lib/converter/factories/signature.ts b/src/lib/converter/factories/signature.ts index 513144027..00aefd594 100644 --- a/src/lib/converter/factories/signature.ts +++ b/src/lib/converter/factories/signature.ts @@ -98,7 +98,7 @@ export function createSignature( break; } - context.trigger(ConverterEvents.CREATE_SIGNATURE, sigRef); + context.trigger(ConverterEvents.CREATE_SIGNATURE, sigRef, declaration); } function convertParameters( diff --git a/src/lib/converter/plugins/SourcePlugin.ts b/src/lib/converter/plugins/SourcePlugin.ts index 631eaf04f..d2186cb0e 100644 --- a/src/lib/converter/plugins/SourcePlugin.ts +++ b/src/lib/converter/plugins/SourcePlugin.ts @@ -50,7 +50,7 @@ export class SourcePlugin extends ConverterComponent { this.listenTo(this.owner, { [Converter.EVENT_END]: this.onEnd, [Converter.EVENT_CREATE_DECLARATION]: this.onDeclaration, - [Converter.EVENT_CREATE_SIGNATURE]: this.onDeclaration, + [Converter.EVENT_CREATE_SIGNATURE]: this.onSignature, [Converter.EVENT_RESOLVE_BEGIN]: this.onBeginResolve, }); } @@ -101,6 +101,31 @@ export class SourcePlugin extends ConverterComponent { } } + private onSignature( + _context: Context, + reflection: Reflection, + sig?: + | ts.SignatureDeclaration + | ts.IndexSignatureDeclaration + | ts.JSDocSignature + ) { + if (this.disableSources || !sig) return; + + const sourceFile = sig.getSourceFile(); + const fileName = sourceFile.fileName; + this.fileNames.add(fileName); + + const position = ts.getLineAndCharacterOfPosition( + sourceFile, + sig.getStart() + ); + + reflection.sources ||= []; + reflection.sources.push( + new SourceReference(fileName, position.line + 1, position.character) + ); + } + /** * Triggered when the converter begins resolving a project. * diff --git a/src/lib/output/themes/default/templates/reflection.tsx b/src/lib/output/themes/default/templates/reflection.tsx index d1342b73a..2899e6ae3 100644 --- a/src/lib/output/themes/default/templates/reflection.tsx +++ b/src/lib/output/themes/default/templates/reflection.tsx @@ -71,6 +71,7 @@ export function reflectionTemplate(context: DefaultThemeRenderContext, props: Pa context.parameter(props.model.indexSignature.type.declaration)} )} + {!props.model.signatures && context.memberSources(props.model)} )} {!!props.model.children?.length && context.index(props.model)} diff --git a/src/test/converter/comment/specs.json b/src/test/converter/comment/specs.json index a3ee5fc33..94f18aab6 100644 --- a/src/test/converter/comment/specs.json +++ b/src/test/converter/comment/specs.json @@ -99,6 +99,14 @@ "kind": 2048, "kindString": "Method", "flags": {}, + "sources": [ + { + "fileName": "comment.ts", + "line": 77, + "character": 4, + "url": "typedoc://comment.ts#L77" + } + ], "signatures": [ { "id": 22, diff --git a/src/test/converter2/issues/gh1996.ts b/src/test/converter2/issues/gh1996.ts new file mode 100644 index 000000000..9bd77a2a4 --- /dev/null +++ b/src/test/converter2/issues/gh1996.ts @@ -0,0 +1,3 @@ +export const a = () => {}; + +export function b() {} diff --git a/src/test/issueTests.ts b/src/test/issueTests.ts index 85e160c31..20e8c727b 100644 --- a/src/test/issueTests.ts +++ b/src/test/issueTests.ts @@ -608,4 +608,15 @@ export const issueTests: { logger.discardDebugMessages(); logger.expectNoOtherMessages(); }, + + gh1996(project) { + const a = query(project, "a"); + equal(a.signatures![0].sources?.[0].fileName, "gh1996.ts"); + equal(a.signatures![0].sources?.[0].line, 1); + equal(a.signatures![0].sources?.[0].character, 17); + const b = query(project, "b"); + equal(b.signatures![0].sources?.[0].fileName, "gh1996.ts"); + equal(b.signatures![0].sources?.[0].line, 3); + equal(b.signatures![0].sources?.[0].character, 0); + }, }; diff --git a/static/style.css b/static/style.css index 048427e08..8f6ed2c43 100644 --- a/static/style.css +++ b/static/style.css @@ -942,7 +942,7 @@ a.tsd-index-link { margin: 2rem 0; } .tsd-panel-group.tsd-index-group details { - margin: 4rem 0; + margin: 2rem 0; } #tsd-search { From 366346963f5345d07cad6fc77429643acd2edbfe Mon Sep 17 00:00:00 2001 From: Gerrit Birkeland Date: Sun, 17 Jul 2022 16:37:12 -0600 Subject: [PATCH 09/20] Add tests, also fix accessors while we're here --- src/lib/converter/plugins/CommentPlugin.ts | 68 +++++++++------------- src/lib/models/reflections/kind.ts | 7 +++ src/test/converter2.test.ts | 2 +- src/test/converter2/issues/gh1994.ts | 39 +++++++++++++ src/test/issueTests.ts | 16 +++++ 5 files changed, 91 insertions(+), 41 deletions(-) create mode 100644 src/test/converter2/issues/gh1994.ts diff --git a/src/lib/converter/plugins/CommentPlugin.ts b/src/lib/converter/plugins/CommentPlugin.ts index d14a077f4..71a6b363f 100644 --- a/src/lib/converter/plugins/CommentPlugin.ts +++ b/src/lib/converter/plugins/CommentPlugin.ts @@ -203,26 +203,6 @@ export class CommentPlugin extends ConverterComponent { this.removeExcludedTags(comment); } - private getHiddenItems(reflection: Reflection) { - const hiddenItems = new Set(); - if (reflection.kindOf(ReflectionKind.FunctionOrMethod)) { - const decl = reflection as DeclarationReflection; - if (decl.signatures) { - for (const sig of decl.signatures) { - if (!sig.comment) { - hiddenItems.add(sig); - } - } - } - if (!decl.signatures?.some((sig) => sig.comment)) { - hiddenItems.add(decl); - } - } else { - hiddenItems.add(reflection); - } - return hiddenItems || []; - } - /** * Triggered when the converter begins resolving a project. * @@ -245,31 +225,29 @@ export class CommentPlugin extends ConverterComponent { } if (this.isHidden(ref)) { - this.getHiddenItems(ref).forEach((item) => hidden.add(item)); + hidden.add(ref); } } hidden.forEach((reflection) => project.removeReflection(reflection)); // remove functions with empty signatures after their signatures have been removed const [allRemoved, someRemoved] = partition( - filterMap(hidden, (reflection) => - reflection.parent?.kindOf( - ReflectionKind.FunctionOrMethod | ReflectionKind.Constructor - ) - ? reflection.parent - : void 0 - ) as DeclarationReflection[], - (method) => method.signatures?.length === 0 + unique( + filterMap(hidden, (reflection) => + reflection.parent?.kindOf(ReflectionKind.SignatureContainer) + ? reflection.parent + : void 0 + ) as DeclarationReflection[] + ), + (method) => method.getNonIndexSignatures().length === 0 ); allRemoved.forEach((reflection) => { project.removeReflection(reflection); }); someRemoved.forEach((reflection) => { - reflection.sources = unique( - reflection.signatures!.flatMap( - (s) => s.sources ?? [] - ) - ); + reflection.sources = reflection + .getNonIndexSignatures() + .flatMap((s) => s.sources ?? []); }); } @@ -425,19 +403,22 @@ export class CommentPlugin extends ConverterComponent { if (!comment) { if (this.excludeNotDocumented) { - // Only allow excludeNotDocumented to exclude root level reflections - if (!(reflection instanceof DeclarationReflection)) { + // Don't let excludeNotDocumented remove parameters. + if ( + !(reflection instanceof DeclarationReflection) && + !(reflection instanceof SignatureReflection) + ) { return false; } // excludeNotDocumented should hide a module only if it has no visible children if (reflection.kindOf(ReflectionKind.SomeModule)) { - if (!reflection.children) { + if (!(reflection as DeclarationReflection).children) { return true; } - return reflection.children.every((child) => - this.isHidden(child) - ); + return ( + reflection as DeclarationReflection + ).children!.every((child) => this.isHidden(child)); } // enum members should all be included if the parent enum is documented @@ -445,6 +426,13 @@ export class CommentPlugin extends ConverterComponent { return false; } + // signature containers should only be hidden if all their signatures are hidden + if (reflection.kindOf(ReflectionKind.SignatureContainer)) { + return (reflection as DeclarationReflection) + .getAllSignatures() + .every((child) => this.isHidden(child)); + } + // excludeNotDocumented should never hide parts of "type" reflections return inTypeLiteral(reflection) === false; } diff --git a/src/lib/models/reflections/kind.ts b/src/lib/models/reflections/kind.ts index f96043428..ea7c4c096 100644 --- a/src/lib/models/reflections/kind.ts +++ b/src/lib/models/reflections/kind.ts @@ -93,4 +93,11 @@ export namespace ReflectionKind { ReflectionKind.Constructor | ReflectionKind.Function | ReflectionKind.Method; + + /** + * Note: This does not include Class/Interface, even though they technically could contain index signatures + * @internal + */ + export const SignatureContainer = + ContainsCallSignatures | ReflectionKind.Accessor; } diff --git a/src/test/converter2.test.ts b/src/test/converter2.test.ts index ab29aa4af..f90c13eb3 100644 --- a/src/test/converter2.test.ts +++ b/src/test/converter2.test.ts @@ -78,7 +78,7 @@ describe("Converter2", () => { } else { runTest( name, - issueTests[`pre${entry}`], + issueTests[`pre${entry[0].toUpperCase()}${entry.slice(1)}`], join("issues", entry), check as ( project: ProjectReflection, diff --git a/src/test/converter2/issues/gh1994.ts b/src/test/converter2/issues/gh1994.ts new file mode 100644 index 000000000..127a4121f --- /dev/null +++ b/src/test/converter2/issues/gh1994.ts @@ -0,0 +1,39 @@ +/** + * Has docs + */ +export function documented() {} + +/** + * Some signatures with docs + */ +export function documented2(): void; +export function documented2(x: number): number; +export function documented2(x?: number) { + return x; +} + +export function notDocumented() {} + +/** Docs */ +export class Docs { + /** Docs */ + get x() { + return 1; + } + /** Docs */ + set x(value: number) { + throw value; + } + + /** Docs */ + get y() { + return 2; + } + set y(value: number) { + throw value; + } + + get z() { + return 3; + } +} diff --git a/src/test/issueTests.ts b/src/test/issueTests.ts index 85e160c31..93535425b 100644 --- a/src/test/issueTests.ts +++ b/src/test/issueTests.ts @@ -608,4 +608,20 @@ export const issueTests: { logger.discardDebugMessages(); logger.expectNoOtherMessages(); }, + + preGh1994(app) { + app.options.setValue("excludeNotDocumented", true); + }, + gh1994(project) { + for (const exp of ["documented", "documented2", "Docs.x", "Docs.y"]) { + query(project, exp); + } + for (const rem of ["notDocumented", "Docs.z"]) { + ok(!project.getChildByName(rem)); + } + + const y = query(project, "Docs.y"); + ok(y.getSignature); + ok(!y.setSignature); + }, }; From 9ed9f01a6ca60b97b5209c6980d5b2db64cab01d Mon Sep 17 00:00:00 2001 From: Gerrit Birkeland Date: Sun, 17 Jul 2022 16:41:46 -0600 Subject: [PATCH 10/20] Update changelog Also tweak how issueTests works, pre1994 reads better than preGh1994 --- CHANGELOG.md | 2 ++ src/test/converter2.test.ts | 2 +- src/test/issueTests.ts | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a28653d94..0e36b961d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,9 +9,11 @@ ### Bug Fixes - Fixed missing `sources` property on signature reflections #1996. +- `excludeNotDocumented` will no longer remove functions/methods/accessors which are documented, #1994. ### Thanks! +- @cary-hu - @chadhietala ## v0.23.7 (2022-07-09) diff --git a/src/test/converter2.test.ts b/src/test/converter2.test.ts index f90c13eb3..a4d1709f8 100644 --- a/src/test/converter2.test.ts +++ b/src/test/converter2.test.ts @@ -78,7 +78,7 @@ describe("Converter2", () => { } else { runTest( name, - issueTests[`pre${entry[0].toUpperCase()}${entry.slice(1)}`], + issueTests[`pre${entry.slice(2)}`], join("issues", entry), check as ( project: ProjectReflection, diff --git a/src/test/issueTests.ts b/src/test/issueTests.ts index eb902fa9d..8c1d7799a 100644 --- a/src/test/issueTests.ts +++ b/src/test/issueTests.ts @@ -609,7 +609,7 @@ export const issueTests: { logger.expectNoOtherMessages(); }, - preGh1994(app) { + pre1994(app) { app.options.setValue("excludeNotDocumented", true); }, gh1994(project) { From f41f6c8f578c8c60a02a0678fd37182322ad9ca8 Mon Sep 17 00:00:00 2001 From: Gerrit Birkeland Date: Sun, 17 Jul 2022 16:54:20 -0600 Subject: [PATCH 11/20] Do not emit warnings on urls within `@link` tags Resolves #1980 --- CHANGELOG.md | 5 ++-- .../converter/plugins/LinkResolverPlugin.ts | 23 +++++++++++---- src/test/converter2/issues/gh1980.ts | 6 ++++ src/test/issueTests.ts | 29 +++++++++++++++++++ 4 files changed, 56 insertions(+), 7 deletions(-) create mode 100644 src/test/converter2/issues/gh1980.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e36b961d..a24cc780e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,14 +2,15 @@ ### Features +- Added defined in links for classes, enums, #180. - Added support for `*.ghe.com` and `*.github.us` GitHub enterprise domains for source links, #2001. - Expose `Converter.parseRawComment` for plugins to parse additional markdown files, #2004. -- Added defined in links for classes, enums #180. ### Bug Fixes -- Fixed missing `sources` property on signature reflections #1996. +- TypeDoc will no longer emit a warning for `{@link}` containing a URL, #1980. - `excludeNotDocumented` will no longer remove functions/methods/accessors which are documented, #1994. +- Fixed missing `sources` property on signature reflections #1996. ### Thanks! diff --git a/src/lib/converter/plugins/LinkResolverPlugin.ts b/src/lib/converter/plugins/LinkResolverPlugin.ts index a537bc8cf..d9dec5bd3 100644 --- a/src/lib/converter/plugins/LinkResolverPlugin.ts +++ b/src/lib/converter/plugins/LinkResolverPlugin.ts @@ -220,26 +220,37 @@ function resolveLinkTag( ) { let pos = 0; const end = part.text.length; + while (pos < end && ts.isWhiteSpaceLike(part.text.charCodeAt(pos))) { + pos++; + } + const origText = part.text; // Try to parse one const declRef = parseDeclarationReference(part.text, pos, end); - let target: Reflection | undefined; + let target: Reflection | string | undefined; if (declRef) { // Got one, great! Try to resolve the link target = resolveDeclarationReference(reflection, declRef[0]); pos = declRef[1]; } + if (!target) { + if (urlPrefix.test(part.text)) { + const wsIndex = part.text.search(/\s/); + target = + wsIndex === -1 ? part.text : part.text.substring(0, wsIndex); + pos = target.length; + } + } + // If resolution via a declaration reference failed, revert to the legacy "split and check" // method... this should go away in 0.24, once people have had a chance to migrate any failing links. if (!target) { const resolved = legacyResolveLinkTag(reflection, part); if (resolved) { warn( - `Failed to resolve {@link ${ - part.text - }} in ${reflection.getFriendlyFullName()} with declaration references. This link will break in v0.24.` + `Failed to resolve {@link ${origText}} in ${reflection.getFriendlyFullName()} with declaration references. This link will break in v0.24.` ); } return resolved; @@ -255,7 +266,9 @@ function resolveLinkTag( } part.target = target; - part.text = part.text.substring(pos).trim() || target.name; + part.text = + part.text.substring(pos).trim() || + (typeof target === "string" ? target : target.name); return part; } diff --git a/src/test/converter2/issues/gh1980.ts b/src/test/converter2/issues/gh1980.ts new file mode 100644 index 000000000..10e749133 --- /dev/null +++ b/src/test/converter2/issues/gh1980.ts @@ -0,0 +1,6 @@ +/** + * {@link http://example.com } + * {@link http://example.com | with text} + * {@link http://example.com jsdoc support} + */ +export const link = 123; diff --git a/src/test/issueTests.ts b/src/test/issueTests.ts index 8c1d7799a..b7e488b97 100644 --- a/src/test/issueTests.ts +++ b/src/test/issueTests.ts @@ -599,6 +599,35 @@ export const issueTests: { equal(comments2, ["Comment for a", "Comment for b"]); }, + gh1980(project, logger) { + const link = query(project, "link"); + equal( + link.comment?.summary.filter((t) => t.kind === "inline-tag"), + [ + { + kind: "inline-tag", + tag: "@link", + target: "http://example.com", + text: "http://example.com", + }, + { + kind: "inline-tag", + tag: "@link", + target: "http://example.com", + text: "with text", + }, + { + kind: "inline-tag", + tag: "@link", + target: "http://example.com", + text: "jsdoc support", + }, + ] + ); + logger.discardDebugMessages(); + logger.expectNoOtherMessages(); + }, + gh1986(project, logger) { const a = query(project, "a"); equal( From 5611232cc715c7c88714682b6819e2c564e1a8fb Mon Sep 17 00:00:00 2001 From: Gerrit Birkeland Date: Sun, 17 Jul 2022 16:56:54 -0600 Subject: [PATCH 12/20] Bump version to 0.23.8 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index eb67bad0c..8f1c50892 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "typedoc", - "version": "0.23.7", + "version": "0.23.8", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "typedoc", - "version": "0.23.7", + "version": "0.23.8", "license": "Apache-2.0", "dependencies": { "lunr": "^2.3.9", diff --git a/package.json b/package.json index 9719c9910..8985fdea1 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "typedoc", "description": "Create api documentation for TypeScript projects.", - "version": "0.23.7", + "version": "0.23.8", "homepage": "https://typedoc.org", "main": "./dist/index.js", "exports": { From 7f48f280058015c45bb0786ce624ff55eeb5f5db Mon Sep 17 00:00:00 2001 From: TypeDoc Bot Date: Sun, 17 Jul 2022 22:58:27 +0000 Subject: [PATCH 13/20] Update changelog for release --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a24cc780e..d8192b35f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Unreleased +## v0.23.8 (2022-07-17) + ### Features - Added defined in links for classes, enums, #180. From 55b72aaef9538ba8e286b5e8e4235e1f5f612cca Mon Sep 17 00:00:00 2001 From: Gerrit Birkeland Date: Sat, 23 Jul 2022 14:07:25 -0600 Subject: [PATCH 14/20] Fix example links --- CHANGELOG.md | 1 + example/README.md | 36 +++++++++++------------ example/src/classes/CancellablePromise.ts | 4 +-- example/src/classes/Customer.ts | 2 +- example/src/functions.ts | 2 +- example/src/reactComponents.tsx | 4 +-- example/src/showcase.ts | 2 +- example/src/types.ts | 2 +- 8 files changed, 27 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d8192b35f..4a9d36bd7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -113,6 +113,7 @@ - `{@link}` tags in comments will now be resolved as declaration references similar to TSDoc's declaration references. For most cases, this will just work. See [the documentation](https://typedoc.org/guides/link-resolution/) for details on how link resolution works. - TypeDoc will now produce warnings for bracketed links (`[[ target ]]`). Use `{@link target}` instead. The `{@link}` syntax will be recognized by [TypeScript 4.3](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-3.html#editor-support-for-link-tags) and later and used to provide better intellisense. TypeDoc version 0.24.0 will remove support for `[[ target ]]` style links. + Support for `` [[`links`]] `` with brackets + code ticks have been dropped. - `extends` in typedoc.json is now resolved using NodeJS module resolution, so a local path must begin with `./`. - In the JSON output for `DeclarationReflection`s, `getSignature` is no longer a one-tuple. - In the JSON output for `DeclarationReflection`s, `setSignature` is no longer a one-tuple. diff --git a/example/README.md b/example/README.md index 5e0973902..be0f3cf83 100644 --- a/example/README.md +++ b/example/README.md @@ -34,39 +34,39 @@ Here are some examples we wanted to highlight: ### Rendering -- Markdown showcase: [[`markdownShowcase`]] -- Syntax highlighting showcase: [[`syntaxHighlightingShowcase`]] +- Markdown showcase: {@link markdownShowcase | `markdownShowcase`} +- Syntax highlighting showcase: {@link syntaxHighlightingShowcase | `syntaxHighlightingShowcase` } ### Functions -- Simple functions: [[`sqrt`]] and [[`sqrtArrowFunction`]] -- A generic function: [[`concat`]] -- Functions that take an options object: [[`makeHttpCallA`]] and [[`makeHttpCallB`]] -- An overloaded function: [[`overloadedFunction`]] -- An external function exported under a different name: [[`lodashSortBy`]] +- Simple functions: {@link sqrt | `sqrt` } and {@link sqrtArrowFunction | `sqrtArrowFunction` } +- A generic function: {@link concat | `concat` } +- Functions that take an options object: {@link makeHttpCallA | `makeHttpCallA` } and {@link makeHttpCallB | `makeHttpCallB` } +- An overloaded function: {@link overloadedFunction | `overloadedFunction` } +- An external function exported under a different name: {@link lodashSortBy | `lodashSortBy` } ### Types -- Type aliases: [[`SimpleTypeAlias`]] and [[`ComplexGenericTypeAlias`]] -- Interfaces: [[`User`]] and [[`AdminUser`]] +- Type aliases: {@link SimpleTypeAlias | `SimpleTypeAlias` } and {@link ComplexGenericTypeAlias | `ComplexGenericTypeAlias` } +- Interfaces: {@link User | `User` } and {@link AdminUser | `AdminUser` } ### Classes -- A basic class: [[`Customer`]] -- A subclass: [[`DeliveryCustomer`]] -- A complex class: [[`CancellablePromise`]] -- A class that extends a built-in generic type: [[`StringArray`]] +- A basic class: {@link Customer | `Customer` } +- A subclass: {@link DeliveryCustomer | `DeliveryCustomer` } +- A complex class: {@link CancellablePromise | `CancellablePromise` } +- A class that extends a built-in generic type: {@link StringArray | `StringArray` } ### Enums -- A basic enum: [[`SimpleEnum`]] -- Using the `@enum` tag: [[`EnumLikeObject`]] +- A basic enum: {@link SimpleEnum | `SimpleEnum` } +- Using the `@enum` tag: {@link EnumLikeObject | `EnumLikeObject` } ### Variables -- [[`PI`]], [[`STRING_CONSTANT`]], and [[`ObjectConstant`]] +- {@link PI | `PI` }, {@link STRING_CONSTANT | `STRING_CONSTANT` }, and {@link ObjectConstant | `ObjectConstant` } ### React Components -- Basic React components: [[`CardA`]] and [[`CardB`]] -- A complex React component: [[`EasyFormDialog`]] and [[`EasyFormDialogProps`]] +- Basic React components: {@link CardA | `CardA` } and {@link CardB | `CardB` } +- A complex React component: {@link EasyFormDialog | `EasyFormDialog` } and {@link EasyFormDialogProps | `EasyFormDialogProps` } diff --git a/example/src/classes/CancellablePromise.ts b/example/src/classes/CancellablePromise.ts index d551164e6..662fd14c0 100644 --- a/example/src/classes/CancellablePromise.ts +++ b/example/src/classes/CancellablePromise.ts @@ -3,7 +3,7 @@ const noop = () => { }; /** - * If canceled, a [[`CancellablePromise`]] should throw an `Cancellation` object. + * If canceled, a {@link CancellablePromise | `CancellablePromise`} should throw an `Cancellation` object. */ class Cancellation extends Error { constructor(message = "Promise canceled.") { @@ -301,7 +301,7 @@ export class CancellablePromise { * * @param values an array that may contain `CancellablePromise`s, promises, * thenables, and resolved values - * @returns a [[`CancellablePromise`]], which, if canceled, will cancel each + * @returns a {@link CancellablePromise | `CancellablePromise`}, which, if canceled, will cancel each * of the promises passed in to `CancellablePromise.all`. */ static all(values: readonly unknown[]): CancellablePromise { diff --git a/example/src/classes/Customer.ts b/example/src/classes/Customer.ts index 1c42329e7..311ade103 100644 --- a/example/src/classes/Customer.ts +++ b/example/src/classes/Customer.ts @@ -78,7 +78,7 @@ export abstract class Customer { } /** - * A class that extends [[`Customer`]]. + * A class that extends {@link Customer | `Customer`}. */ export class DeliveryCustomer extends Customer { /** A property defined on the subclass. */ diff --git a/example/src/functions.ts b/example/src/functions.ts index 27e89bbdb..980698bab 100644 --- a/example/src/functions.ts +++ b/example/src/functions.ts @@ -42,7 +42,7 @@ export function concat(array1: T[], array2: T[]): T[] { } /** - * The options type for [[`makeHttpCallA`]]. + * The options type for {@link makeHttpCallA}. */ export interface MakeHttpCallAOptions { url: string; diff --git a/example/src/reactComponents.tsx b/example/src/reactComponents.tsx index 6df57b24e..da39c5c8a 100644 --- a/example/src/reactComponents.tsx +++ b/example/src/reactComponents.tsx @@ -1,7 +1,7 @@ import { ReactElement, PropsWithChildren } from "react"; /** - * The props type for [[`CardA`]]. + * The props type for {@link CardA}. */ export interface CardAProps { /** The theme of the card. Defaults to `primary`. */ @@ -81,7 +81,7 @@ export function CardB({ return
{children}
; } -/** The props type of [[`EasyFormDialog`]]. */ +/** The props type of {@link EasyFormDialog | `EasyFormDialog`}. */ export interface EasyFormDialogProps { /** The title of the dialog. Can be a JSX element. */ title: React.ReactNode; diff --git a/example/src/showcase.ts b/example/src/showcase.ts index ad384494a..c6f38a402 100644 --- a/example/src/showcase.ts +++ b/example/src/showcase.ts @@ -23,7 +23,7 @@ * const x: number | string = 12 * ``` * - * See [[`syntaxHighlightingShowcase`]] for more code blocks. + * See {@link syntaxHighlightingShowcase | `syntaxHighlightingShowcase`} for more code blocks. * * ## A List * diff --git a/example/src/types.ts b/example/src/types.ts index fa40a0f17..96b8a402a 100644 --- a/example/src/types.ts +++ b/example/src/types.ts @@ -32,7 +32,7 @@ export interface User { } /** - * An interface that extends [[`User`]] and adds more properties. + * An interface that extends {@link User | `User`} and adds more properties. * * Notice how TypeDoc automatically shows the inheritance hierarchy and where * each property was originally defined. From 3e5a1a247cc2d006bd04ffa6e09aaac2303e4fb6 Mon Sep 17 00:00:00 2001 From: Gerrit Birkeland Date: Sat, 23 Jul 2022 14:15:12 -0600 Subject: [PATCH 15/20] Fix multiple reflections mapping to the same file name I don't like this fix, but `getAlias` isn't something that should exist to begin with, so... Resolves #2012 --- CHANGELOG.md | 4 ++++ src/lib/models/reflections/abstract.ts | 11 +++++++---- src/test/converter2/issues/gh2012.ts | 6 ++++++ src/test/issueTests.ts | 8 ++++++++ 4 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 src/test/converter2/issues/gh2012.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a9d36bd7..f5e1c6ef3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Unreleased +### Bug Fixes + +- Fixed multiple reflections mapping to the same file name on case insensitive file systems, #2012. + ## v0.23.8 (2022-07-17) ### Features diff --git a/src/lib/models/reflections/abstract.ts b/src/lib/models/reflections/abstract.ts index 6105eca25..33af2a770 100644 --- a/src/lib/models/reflections/abstract.ts +++ b/src/lib/models/reflections/abstract.ts @@ -413,6 +413,9 @@ export abstract class Reflection { if (alias === "") { alias = "reflection-" + this.id; } + // NTFS/ExFAT use uppercase, so we will too. It probably won't matter + // in this case since names will generally be valid identifiers, but to be safe... + const upperAlias = alias.toUpperCase(); let target = this as Reflection; while (target.parent && !target.hasOwnDocument) { @@ -422,12 +425,12 @@ export abstract class Reflection { target._aliases ||= new Map(); let suffix = ""; - if (!target._aliases.has(alias)) { - target._aliases.set(alias, 1); + if (!target._aliases.has(upperAlias)) { + target._aliases.set(upperAlias, 1); } else { - const count = target._aliases.get(alias)!; + const count = target._aliases.get(upperAlias)!; suffix = "-" + count.toString(); - target._aliases.set(alias, count + 1); + target._aliases.set(upperAlias, count + 1); } alias += suffix; diff --git a/src/test/converter2/issues/gh2012.ts b/src/test/converter2/issues/gh2012.ts new file mode 100644 index 000000000..f61081847 --- /dev/null +++ b/src/test/converter2/issues/gh2012.ts @@ -0,0 +1,6 @@ +export function model(): number { + return 1; +} +export function Model(): string { + return ""; +} diff --git a/src/test/issueTests.ts b/src/test/issueTests.ts index b7e488b97..5adc301fc 100644 --- a/src/test/issueTests.ts +++ b/src/test/issueTests.ts @@ -665,4 +665,12 @@ export const issueTests: { equal(b.signatures![0].sources?.[0].line, 3); equal(b.signatures![0].sources?.[0].character, 0); }, + + gh2012(project) { + project.hasOwnDocument = true; + const model = query(project, "model"); + const Model = query(project, "Model"); + equal(model.getAlias(), "model"); + equal(Model.getAlias(), "Model-1"); + }, }; From 4f2a12f330aec495641d21347de60c67ad2b5a88 Mon Sep 17 00:00:00 2001 From: Gerrit Birkeland Date: Sat, 23 Jul 2022 14:48:06 -0600 Subject: [PATCH 16/20] Fix missing comments on indirectly created var-fns Resolves #2008 --- CHANGELOG.md | 1 + package.json | 3 ++- src/lib/converter/comments/discovery.ts | 11 +++++++++-- src/lib/converter/plugins/CommentPlugin.ts | 18 +++++++++++++++--- src/test/converter/function/specs.json | 16 ++++++++++++++++ src/test/converter2/issues/gh2008.ts | 4 ++++ src/test/converter2/validation/interface.ts | 5 +++++ src/test/issueTests.ts | 5 +++++ src/test/validation.test.ts | 11 +++++++++++ 9 files changed, 68 insertions(+), 6 deletions(-) create mode 100644 src/test/converter2/issues/gh2008.ts create mode 100644 src/test/converter2/validation/interface.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index f5e1c6ef3..0e3a0643f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### Bug Fixes +- Fixed missing comments on callable variable-functions constructed indirectly, #2008. - Fixed multiple reflections mapping to the same file name on case insensitive file systems, #2012. ## v0.23.8 (2022-07-17) diff --git a/package.json b/package.json index 8985fdea1..fad69552a 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,8 @@ "/tsdoc.json" ], "scripts": { - "test": "c8 mocha -r ts-node/register --config .config/mocha.fast.json", + "test": "mocha -r ts-node/register --config .config/mocha.fast.json", + "test:cov": "c8 mocha -r ts-node/register --config .config/mocha.fast.json", "build:c2": "node bin/typedoc --tsconfig src/test/converter2/tsconfig.json", "test:full": "c8 mocha -r ts-node/register --config .config/mocha.full.json", "test:visual": "node ./dist/test/capture-screenshots.js && reg-suit -c .config/regconfig.json compare", diff --git a/src/lib/converter/comments/discovery.ts b/src/lib/converter/comments/discovery.ts index 9e443848c..373ff5ad5 100644 --- a/src/lib/converter/comments/discovery.ts +++ b/src/lib/converter/comments/discovery.ts @@ -37,6 +37,9 @@ const wantedKinds: Record = { [ReflectionKind.Function]: [ ts.SyntaxKind.FunctionDeclaration, ts.SyntaxKind.BindingElement, + ts.SyntaxKind.VariableDeclaration, + ts.SyntaxKind.ExportAssignment, + ts.SyntaxKind.PropertyAccessExpression, ], [ReflectionKind.Class]: [ ts.SyntaxKind.ClassDeclaration, @@ -106,8 +109,12 @@ export function discoverComment( // See the gh1770 test for an example. if ( kind & ReflectionKind.ContainsCallSignatures && - !(node as ts.FunctionDeclaration).body && - node.kind !== ts.SyntaxKind.BindingElement + [ + ts.SyntaxKind.FunctionDeclaration, + ts.SyntaxKind.MethodDeclaration, + ts.SyntaxKind.Constructor, + ].includes(node.kind) && + !(node as ts.FunctionDeclaration).body ) { continue; } diff --git a/src/lib/converter/plugins/CommentPlugin.ts b/src/lib/converter/plugins/CommentPlugin.ts index 71a6b363f..d4c162532 100644 --- a/src/lib/converter/plugins/CommentPlugin.ts +++ b/src/lib/converter/plugins/CommentPlugin.ts @@ -439,11 +439,23 @@ export class CommentPlugin extends ConverterComponent { return false; } - return ( + const isHidden = comment.hasModifier("@hidden") || comment.hasModifier("@ignore") || - (comment.hasModifier("@internal") && this.excludeInternal) - ); + (comment.hasModifier("@internal") && this.excludeInternal); + + if ( + isHidden && + reflection.kindOf(ReflectionKind.ContainsCallSignatures) + ) { + return (reflection as DeclarationReflection) + .getNonIndexSignatures() + .every((sig) => { + return !sig.comment || this.isHidden(sig); + }); + } + + return isHidden; } } diff --git a/src/test/converter/function/specs.json b/src/test/converter/function/specs.json index eea266563..12daa8fe2 100644 --- a/src/test/converter/function/specs.json +++ b/src/test/converter/function/specs.json @@ -449,6 +449,14 @@ "kind": 4096, "kindString": "Call signature", "flags": {}, + "comment": { + "summary": [ + { + "kind": "text", + "text": "Returns true if fn returns true for every item in the iterator\n\nReturns true if the iterator is empty" + } + ] + }, "typeParameter": [ { "id": 101, @@ -543,6 +551,14 @@ "kind": 4096, "kindString": "Call signature", "flags": {}, + "comment": { + "summary": [ + { + "kind": "text", + "text": "Returns true if fn returns true for every item in the iterator\n\nReturns true if the iterator is empty" + } + ] + }, "typeParameter": [ { "id": 108, diff --git a/src/test/converter2/issues/gh2008.ts b/src/test/converter2/issues/gh2008.ts new file mode 100644 index 000000000..61c323ae1 --- /dev/null +++ b/src/test/converter2/issues/gh2008.ts @@ -0,0 +1,4 @@ +const makeFn = () => () => {}; + +/** Docs */ +export const myFn = makeFn(); diff --git a/src/test/converter2/validation/interface.ts b/src/test/converter2/validation/interface.ts new file mode 100644 index 000000000..a057be41c --- /dev/null +++ b/src/test/converter2/validation/interface.ts @@ -0,0 +1,5 @@ +export interface Foo { + /** a */ + method(): void; + method(a: string): string; +} diff --git a/src/test/issueTests.ts b/src/test/issueTests.ts index 5adc301fc..3198ab47b 100644 --- a/src/test/issueTests.ts +++ b/src/test/issueTests.ts @@ -666,6 +666,11 @@ export const issueTests: { equal(b.signatures![0].sources?.[0].character, 0); }, + gh2008(project) { + const fn = query(project, "myFn").signatures![0]; + equal(Comment.combineDisplayParts(fn.comment?.summary), "Docs"); + }, + gh2012(project) { project.hasOwnDocument = true; const model = query(project, "model"); diff --git a/src/test/validation.test.ts b/src/test/validation.test.ts index eba3abdf8..09c8a9d94 100644 --- a/src/test/validation.test.ts +++ b/src/test/validation.test.ts @@ -195,4 +195,15 @@ describe("validateDocumentation", () => { ); logger.expectNoOtherMessages(); }); + + it("Should correctly handle interfaces", () => { + const project = convertValidationFile("interface.ts"); + const logger = new TestLogger(); + validateDocumentation(project, logger, ["Method"]); + + logger.expectMessage( + "warn: Foo.method does not have any documentation." + ); + logger.expectNoOtherMessages(); + }); }); From d4d3b8f5de744b03720efe67260f0b9d1a6270af Mon Sep 17 00:00:00 2001 From: Gerrit Birkeland Date: Sat, 23 Jul 2022 15:09:35 -0600 Subject: [PATCH 17/20] Do not skip empty entry points Resolves #2007 --- CHANGELOG.md | 3 +++ src/lib/converter/converter.ts | 10 +--------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e3a0643f..85ce4f157 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ### Bug Fixes +- TypeDoc will no longer skip entry points which have no exports, #2007. + If using `"entryPointStrategy": "expand"`, this change may result in new pages being added to your documentation. + If this is not desired, you can use the `exclude` option to filter them out. - Fixed missing comments on callable variable-functions constructed indirectly, #2008. - Fixed multiple reflections mapping to the same file name on case insensitive file systems, #2012. diff --git a/src/lib/converter/converter.ts b/src/lib/converter/converter.ts index 5834016b6..adee92908 100644 --- a/src/lib/converter/converter.ts +++ b/src/lib/converter/converter.ts @@ -240,15 +240,6 @@ export class Converter extends ChildableComponent< const symbol = getSymbolForModuleLike(context, node); let moduleContext: Context; - const allExports = getExports(context, node, symbol); - - if (allExports.every((exp) => this.shouldIgnore(exp))) { - this.owner.logger.verbose( - `All members of ${entryName} are excluded, ignoring entry point.` - ); - return; - } - if (singleEntryPoint) { // Special case for when we're giving a single entry point, we don't need to // create modules for each entry. Register the project as this module. @@ -302,6 +293,7 @@ export class Converter extends ChildableComponent< moduleContext = context.withScope(reflection); } + const allExports = getExports(context, node, symbol); for (const exp of allExports.filter((exp) => isDirectExport(context.resolveAliasedSymbol(exp), node) )) { From ba9c5befb095879597aee54c9e77a9a939599249 Mon Sep 17 00:00:00 2001 From: Gerrit Birkeland Date: Sat, 23 Jul 2022 15:47:48 -0600 Subject: [PATCH 18/20] Only set version if includeVersion is specified Resolves #2010 --- CHANGELOG.md | 1 + src/lib/utils/entry-point.ts | 4 +++- src/test/slow/entry-point.test.ts | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85ce4f157..7d8269489 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ If using `"entryPointStrategy": "expand"`, this change may result in new pages being added to your documentation. If this is not desired, you can use the `exclude` option to filter them out. - Fixed missing comments on callable variable-functions constructed indirectly, #2008. +- Packages mode will now respect the `--includeVersion` flag, #2010. - Fixed multiple reflections mapping to the same file name on case insensitive file systems, #2012. ## v0.23.8 (2022-07-17) diff --git a/src/lib/utils/entry-point.ts b/src/lib/utils/entry-point.ts index 3df6c28a2..b2efcd215 100644 --- a/src/lib/utils/entry-point.ts +++ b/src/lib/utils/entry-point.ts @@ -407,7 +407,9 @@ function getEntryPointsForPackages( displayName: typedocPackageConfig?.displayName ?? (packageJson["name"] as string), - version: packageJson["version"] as string | undefined, + version: includeVersion + ? (packageJson["version"] as string | undefined) + : void 0, readmeFile: typedocPackageConfig?.readmeFile ? Path.resolve( Path.join( diff --git a/src/test/slow/entry-point.test.ts b/src/test/slow/entry-point.test.ts index 5c1256dcf..adc89454b 100644 --- a/src/test/slow/entry-point.test.ts +++ b/src/test/slow/entry-point.test.ts @@ -84,5 +84,6 @@ describe("Entry Points", () => { const entryPoints = app.getEntryPoints(); ok(entryPoints); equal(entryPoints.length, 1); + equal(entryPoints[0].version, void 0); }); }); From 20ea81a35edd65a12c902482737220dde3feba58 Mon Sep 17 00:00:00 2001 From: Gerrit Birkeland Date: Sun, 24 Jul 2022 14:33:41 -0600 Subject: [PATCH 19/20] Bump version to 0.23.9 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8f1c50892..a084a94c9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "typedoc", - "version": "0.23.8", + "version": "0.23.9", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "typedoc", - "version": "0.23.8", + "version": "0.23.9", "license": "Apache-2.0", "dependencies": { "lunr": "^2.3.9", diff --git a/package.json b/package.json index fad69552a..7e0fa9e84 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "typedoc", "description": "Create api documentation for TypeScript projects.", - "version": "0.23.8", + "version": "0.23.9", "homepage": "https://typedoc.org", "main": "./dist/index.js", "exports": { From e50cd273366977d1e06eac782806a5c6bc49f223 Mon Sep 17 00:00:00 2001 From: TypeDoc Bot Date: Sun, 24 Jul 2022 20:34:49 +0000 Subject: [PATCH 20/20] Update changelog for release --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d8269489..5365bd3cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Unreleased +## v0.23.9 (2022-07-24) + ### Bug Fixes - TypeDoc will no longer skip entry points which have no exports, #2007.