Skip to content

Commit a61cdcb

Browse files
committed
Recognize @defaultValue as text in more situations
Resolves #2601
1 parent 1b55285 commit a61cdcb

File tree

3 files changed

+96
-2
lines changed

3 files changed

+96
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
- Fixed very slow conversion on Windows where Msys git was used by typedoc to discover repository links, #2586.
8080
- Validation will now be run in watch mode, #2584.
8181
- Fixed an issue where custom themes which added dependencies in the `<head>` element could result in broken icons, #2589.
82+
- `@default` and `@defaultValue` blocks are now recognized as regular blocks if they include inline tags, #2601.
8283
- Navigation folders sharing a name will no longer be saved with a shared key to `localStorage`.
8384
- The `--hideParameterTypesInTitle` option no longer applies when rendering function types.
8485
- Broken `@link` tags in readme files will now cause a warning when link validation is enabled.

src/lib/converter/comments/parser.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,11 @@ function defaultBlockContent(
420420
const end = lexer.done() || lexer.peek();
421421
lexer.release();
422422

423-
if (content.some((part) => part.kind === "code")) {
423+
if (
424+
content.some(
425+
(part) => part.kind === "code" || part.kind === "inline-tag",
426+
)
427+
) {
424428
return blockContent(comment, lexer, config, i18n, warning, files);
425429
}
426430

src/test/comments.test.ts

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,13 @@ describe("Raw Lexer", () => {
10711071

10721072
describe("Comment Parser", () => {
10731073
const config: CommentParserConfig = {
1074-
blockTags: new Set(["@param", "@remarks", "@module", "@inheritDoc"]),
1074+
blockTags: new Set([
1075+
"@param",
1076+
"@remarks",
1077+
"@module",
1078+
"@inheritDoc",
1079+
"@defaultValue",
1080+
]),
10751081
inlineTags: new Set(["@link"]),
10761082
modifierTags: new Set([
10771083
"@public",
@@ -1090,6 +1096,89 @@ describe("Comment Parser", () => {
10901096
},
10911097
};
10921098

1099+
it("Should recognize @defaultValue as code", () => {
1100+
const files = new FileRegistry();
1101+
const logger = new TestLogger();
1102+
const file = "/** @defaultValue code */";
1103+
const content = lexBlockComment(file);
1104+
const comment = parseComment(
1105+
content,
1106+
config,
1107+
new MinimalSourceFile(file, "<memory>"),
1108+
logger,
1109+
files,
1110+
);
1111+
1112+
equal(
1113+
comment,
1114+
new Comment(
1115+
[],
1116+
[
1117+
new CommentTag("@defaultValue", [
1118+
{ kind: "code", text: "```ts\ncode\n```" },
1119+
]),
1120+
],
1121+
),
1122+
);
1123+
logger.expectNoOtherMessages();
1124+
});
1125+
1126+
it("Should recognize @defaultValue as not code if it contains an inline tag", () => {
1127+
const files = new FileRegistry();
1128+
const logger = new TestLogger();
1129+
const file = "/** @defaultValue text {@link foo} */";
1130+
const content = lexBlockComment(file);
1131+
const comment = parseComment(
1132+
content,
1133+
config,
1134+
new MinimalSourceFile(file, "<memory>"),
1135+
logger,
1136+
files,
1137+
);
1138+
1139+
equal(
1140+
comment,
1141+
new Comment(
1142+
[],
1143+
[
1144+
new CommentTag("@defaultValue", [
1145+
{ kind: "text", text: "text " },
1146+
{ kind: "inline-tag", tag: "@link", text: "foo" },
1147+
]),
1148+
],
1149+
),
1150+
);
1151+
logger.expectNoOtherMessages();
1152+
});
1153+
1154+
it("Should recognize @defaultValue as not code if it contains code", () => {
1155+
const files = new FileRegistry();
1156+
const logger = new TestLogger();
1157+
const file = "/** @defaultValue text `code` */";
1158+
const content = lexBlockComment(file);
1159+
const comment = parseComment(
1160+
content,
1161+
config,
1162+
new MinimalSourceFile(file, "<memory>"),
1163+
logger,
1164+
files,
1165+
);
1166+
1167+
equal(
1168+
comment,
1169+
new Comment(
1170+
[],
1171+
[
1172+
new CommentTag("@defaultValue", [
1173+
{ kind: "text", text: "text " },
1174+
{ kind: "code", text: "`code`" },
1175+
]),
1176+
],
1177+
),
1178+
);
1179+
logger.expectNoOtherMessages();
1180+
});
1181+
10931182
it("Should rewrite @inheritdoc to @inheritDoc", () => {
10941183
const files = new FileRegistry();
10951184
const logger = new TestLogger();

0 commit comments

Comments
 (0)