Skip to content

Commit

Permalink
Recognize @defaultValue as text in more situations
Browse files Browse the repository at this point in the history
Resolves #2601
  • Loading branch information
Gerrit0 committed Jun 21, 2024
1 parent 1b55285 commit a61cdcb
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<head>` 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.
Expand Down
6 changes: 5 additions & 1 deletion src/lib/converter/comments/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
91 changes: 90 additions & 1 deletion src/test/comments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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, "<memory>"),
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, "<memory>"),
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, "<memory>"),
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();
Expand Down

0 comments on commit a61cdcb

Please sign in to comment.