fix(55258): JSDoc render with @param Object properties (#55264)

This commit is contained in:
Oleksandr T 2023-09-20 00:00:32 +03:00 committed by GitHub
parent 1f88596bb1
commit 79736eff89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 210 additions and 0 deletions

View File

@ -44,6 +44,8 @@ import {
isIdentifier,
isJSDoc,
isJSDocParameterTag,
isJSDocPropertyLikeTag,
isJSDocTypeLiteral,
isWhiteSpaceSingleLine,
JSDoc,
JSDocAugmentsTag,
@ -250,6 +252,12 @@ export function getJsDocTagsFromDeclarations(declarations?: Declaration[], check
}
for (const tag of tags) {
infos.push({ name: tag.tagName.text, text: getCommentDisplayParts(tag, checker) });
if (isJSDocPropertyLikeTag(tag) && tag.isNameFirst && tag.typeExpression && isJSDocTypeLiteral(tag.typeExpression.type)) {
forEach(tag.typeExpression.type.jsDocPropertyTags, propTag => {
infos.push({ name: propTag.tagName.text, text: getCommentDisplayParts(propTag, checker) });
});
}
}
});
return infos;

View File

@ -0,0 +1,189 @@
=== /tests/cases/fourslash/quickInfoJsDocTags12.ts ===
// /**
// * @param {Object} options the args object
// * @param {number} options.a first number
// * @param {number} options.b second number
// * @param {Function} callback the callback function
// * @returns {number}
// */
// function f(options, callback = null) {
// ^
// | ----------------------------------------------------------------------
// | function f(options: any, callback?: any): void
// | @param options the args object
// | @param options.a first number
// | @param options.b second number
// | @param callback the callback function
// | @returns
// | ----------------------------------------------------------------------
// }
[
{
"marker": {
"fileName": "/tests/cases/fourslash/quickInfoJsDocTags12.ts",
"position": 218,
"name": ""
},
"item": {
"kind": "function",
"kindModifiers": "",
"textSpan": {
"start": 218,
"length": 1
},
"displayParts": [
{
"text": "function",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "f",
"kind": "functionName"
},
{
"text": "(",
"kind": "punctuation"
},
{
"text": "options",
"kind": "parameterName"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "any",
"kind": "keyword"
},
{
"text": ",",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "callback",
"kind": "parameterName"
},
{
"text": "?",
"kind": "punctuation"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "any",
"kind": "keyword"
},
{
"text": ")",
"kind": "punctuation"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "void",
"kind": "keyword"
}
],
"documentation": [],
"tags": [
{
"name": "param",
"text": [
{
"text": "options",
"kind": "parameterName"
},
{
"text": " ",
"kind": "space"
},
{
"text": "the args object",
"kind": "text"
}
]
},
{
"name": "param",
"text": [
{
"text": "options.a",
"kind": "parameterName"
},
{
"text": " ",
"kind": "space"
},
{
"text": "first number",
"kind": "text"
}
]
},
{
"name": "param",
"text": [
{
"text": "options.b",
"kind": "parameterName"
},
{
"text": " ",
"kind": "space"
},
{
"text": "second number",
"kind": "text"
}
]
},
{
"name": "param",
"text": [
{
"text": "callback",
"kind": "parameterName"
},
{
"text": " ",
"kind": "space"
},
{
"text": "the callback function",
"kind": "text"
}
]
},
{
"name": "returns"
}
]
}
}
]

View File

@ -0,0 +1,13 @@
/// <reference path="fourslash.ts" />
/////**
//// * @param {Object} options the args object
//// * @param {number} options.a first number
//// * @param {number} options.b second number
//// * @param {Function} callback the callback function
//// * @returns {number}
//// */
////function /**/f(options, callback = null) {
////}
verify.baselineQuickInfo();