Skip to content

Commit

Permalink
Fix JSDoc property comments
Browse files Browse the repository at this point in the history
Resolves #2020
  • Loading branch information
Gerrit0 committed Jul 30, 2022
1 parent 5687934 commit 5f1a7d8
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Unreleased

### Bug Fixes

- Fixed schema URL for TSDoc preventing the use of `typedoc/tsdoc.json` in TSDoc extends, #2016.
- Fixed missing JSDoc style `@typedef` comments for properties, #2020.

## v0.23.9 (2022-07-24)

### Bug Fixes
Expand Down
22 changes: 21 additions & 1 deletion src/lib/converter/comments/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ export interface CommentParserConfig {
modifierTags: Set<string>;
}

const jsDocCommentKinds = [
ts.SyntaxKind.JSDocPropertyTag,
ts.SyntaxKind.JSDocCallbackTag,
ts.SyntaxKind.JSDocTypedefTag,
ts.SyntaxKind.JSDocTemplateTag,
ts.SyntaxKind.JSDocEnumTag,
];

const commentCache = new WeakMap<ts.SourceFile, Map<number, Comment>>();

function getCommentWithCache(
Expand Down Expand Up @@ -95,6 +103,18 @@ export function getComment(
logger: Logger,
commentStyle: CommentStyle
): Comment | undefined {
if (
symbol
.getDeclarations()
?.every((d) => jsDocCommentKinds.includes(d.kind))
) {
return getJsDocComment(
symbol.declarations![0] as ts.JSDocPropertyLikeTag,
config,
logger
);
}

return getCommentImpl(
discoverComment(symbol, kind, logger, commentStyle),
config,
Expand Down Expand Up @@ -191,6 +211,6 @@ export function getJsDocComment(
declaration
);
} else {
return new Comment(tag.content.slice());
return new Comment(Comment.cloneDisplayParts(tag.content));
}
}
24 changes: 24 additions & 0 deletions src/test/converter/js/specs.json
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,14 @@
"kind": 1024,
"kindString": "Property",
"flags": {},
"comment": {
"summary": [
{
"kind": "text",
"text": "can also use prop tag"
}
]
},
"sources": [
{
"fileName": "index.js",
Expand All @@ -220,6 +228,14 @@
"kind": 1024,
"kindString": "Property",
"flags": {},
"comment": {
"summary": [
{
"kind": "text",
"text": "docs for property"
}
]
},
"sources": [
{
"fileName": "index.js",
Expand Down Expand Up @@ -265,6 +281,14 @@
"kind": 1024,
"kindString": "Property",
"flags": {},
"comment": {
"summary": [
{
"kind": "text",
"text": "docs for property\nmore docs for property"
}
]
},
"sources": [
{
"fileName": "index.js",
Expand Down
7 changes: 7 additions & 0 deletions src/test/converter2/issues/gh2020.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// @ts-check

/**
* @typedef {Object} Options Desc
* @property {string} url - Desc2
* @property {string} [apiKey] - Desc3
*/
17 changes: 17 additions & 0 deletions src/test/issueTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -678,4 +678,21 @@ export const issueTests: {
equal(model.getAlias(), "model");
equal(Model.getAlias(), "Model-1");
},

gh2020(project) {
const opt = query(project, "Options");
equal(Comment.combineDisplayParts(opt.comment?.summary), "Desc");
equal(
Comment.combineDisplayParts(
opt.getChildByName("url")?.comment?.summary
),
"Desc2"
);
equal(
Comment.combineDisplayParts(
opt.getChildByName("apiKey")?.comment?.summary
),
"Desc3"
);
},
};

0 comments on commit 5f1a7d8

Please sign in to comment.