diff --git a/CHANGELOG.md b/CHANGELOG.md index 994da0f10..02f81e920 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Unreleased +### Bug Fixes + +- TypeDoc will no longer crash if a comment contains an empty `@example` tag, #1967. + ## v0.23.2 (2022-06-28) ### Bug Fixes diff --git a/src/lib/converter/comments/parser.ts b/src/lib/converter/comments/parser.ts index 8e9ac80ed..3dc0a96e2 100644 --- a/src/lib/converter/comments/parser.ts +++ b/src/lib/converter/comments/parser.ts @@ -109,7 +109,7 @@ function postProcessComment(comment: Comment, warning: (msg: string) => void) { tag.tag === "@example" && !tag.content.some((part) => part.kind === "code") ) { - const caption = tag.content[0].text.match( + const caption = tag.content[0]?.text.match( /^\s*(.*?)<\/caption>\s*(\n|$)/ ); if (caption) { diff --git a/src/test/converter2/issues/gh1967.ts b/src/test/converter2/issues/gh1967.ts new file mode 100644 index 000000000..e46ab60f2 --- /dev/null +++ b/src/test/converter2/issues/gh1967.ts @@ -0,0 +1,4 @@ +/** + * @example + */ +export const abc = 123; diff --git a/src/test/issueTests.ts b/src/test/issueTests.ts index 2b72b3fa9..7f54bb49e 100644 --- a/src/test/issueTests.ts +++ b/src/test/issueTests.ts @@ -539,4 +539,13 @@ export const issueTests: { gh1963(project) { ok(project.hasComment(), "Missing module comment"); }, + + gh1967(project) { + equal(query(project, "abc").comment?.getTag("@example")?.content, [ + { + kind: "code", + text: "```ts\n\n```", + }, + ]); + }, };