From a61cdcbddd72abc4f50162f65282c42520696014 Mon Sep 17 00:00:00 2001 From: Gerrit Birkeland Date: Fri, 21 Jun 2024 16:44:02 -0600 Subject: [PATCH] Recognize `@defaultValue` as text in more situations Resolves #2601 --- CHANGELOG.md | 1 + src/lib/converter/comments/parser.ts | 6 +- src/test/comments.test.ts | 91 +++++++++++++++++++++++++++- 3 files changed, 96 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index afbff9878..755295594 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -79,6 +79,7 @@ - Fixed very slow conversion on Windows where Msys git was used by typedoc to discover repository links, #2586. - Validation will now be run in watch mode, #2584. - Fixed an issue where custom themes which added dependencies in the `` element could result in broken icons, #2589. +- `@default` and `@defaultValue` blocks are now recognized as regular blocks if they include inline tags, #2601. - Navigation folders sharing a name will no longer be saved with a shared key to `localStorage`. - The `--hideParameterTypesInTitle` option no longer applies when rendering function types. - Broken `@link` tags in readme files will now cause a warning when link validation is enabled. diff --git a/src/lib/converter/comments/parser.ts b/src/lib/converter/comments/parser.ts index 9f8be7ea0..daf48cb75 100644 --- a/src/lib/converter/comments/parser.ts +++ b/src/lib/converter/comments/parser.ts @@ -420,7 +420,11 @@ function defaultBlockContent( const end = lexer.done() || lexer.peek(); lexer.release(); - if (content.some((part) => part.kind === "code")) { + if ( + content.some( + (part) => part.kind === "code" || part.kind === "inline-tag", + ) + ) { return blockContent(comment, lexer, config, i18n, warning, files); } diff --git a/src/test/comments.test.ts b/src/test/comments.test.ts index 9cc99b8b3..7f60d68e4 100644 --- a/src/test/comments.test.ts +++ b/src/test/comments.test.ts @@ -1071,7 +1071,13 @@ describe("Raw Lexer", () => { describe("Comment Parser", () => { const config: CommentParserConfig = { - blockTags: new Set(["@param", "@remarks", "@module", "@inheritDoc"]), + blockTags: new Set([ + "@param", + "@remarks", + "@module", + "@inheritDoc", + "@defaultValue", + ]), inlineTags: new Set(["@link"]), modifierTags: new Set([ "@public", @@ -1090,6 +1096,89 @@ describe("Comment Parser", () => { }, }; + it("Should recognize @defaultValue as code", () => { + const files = new FileRegistry(); + const logger = new TestLogger(); + const file = "/** @defaultValue code */"; + const content = lexBlockComment(file); + const comment = parseComment( + content, + config, + new MinimalSourceFile(file, ""), + logger, + files, + ); + + equal( + comment, + new Comment( + [], + [ + new CommentTag("@defaultValue", [ + { kind: "code", text: "```ts\ncode\n```" }, + ]), + ], + ), + ); + logger.expectNoOtherMessages(); + }); + + it("Should recognize @defaultValue as not code if it contains an inline tag", () => { + const files = new FileRegistry(); + const logger = new TestLogger(); + const file = "/** @defaultValue text {@link foo} */"; + const content = lexBlockComment(file); + const comment = parseComment( + content, + config, + new MinimalSourceFile(file, ""), + logger, + files, + ); + + equal( + comment, + new Comment( + [], + [ + new CommentTag("@defaultValue", [ + { kind: "text", text: "text " }, + { kind: "inline-tag", tag: "@link", text: "foo" }, + ]), + ], + ), + ); + logger.expectNoOtherMessages(); + }); + + it("Should recognize @defaultValue as not code if it contains code", () => { + const files = new FileRegistry(); + const logger = new TestLogger(); + const file = "/** @defaultValue text `code` */"; + const content = lexBlockComment(file); + const comment = parseComment( + content, + config, + new MinimalSourceFile(file, ""), + logger, + files, + ); + + equal( + comment, + new Comment( + [], + [ + new CommentTag("@defaultValue", [ + { kind: "text", text: "text " }, + { kind: "code", text: "`code`" }, + ]), + ], + ), + ); + logger.expectNoOtherMessages(); + }); + it("Should rewrite @inheritdoc to @inheritDoc", () => { const files = new FileRegistry(); const logger = new TestLogger();