mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-16 07:13:45 -05:00
Support property declarations in jsdoc template generation (#36658)
* Support property declarations in jsdoc template generation * fix lint and add test
This commit is contained in:
committed by
GitHub
parent
b8b59489e1
commit
2cc585668d
@@ -251,7 +251,6 @@ namespace ts.JsDoc {
|
||||
* @param position The (character-indexed) position in the file where the check should
|
||||
* be performed.
|
||||
*/
|
||||
|
||||
export function getDocCommentTemplateAtPosition(newLine: string, sourceFile: SourceFile, position: number): TextInsertion | undefined {
|
||||
const tokenAtPos = getTokenAtPosition(sourceFile, position);
|
||||
const existingDocComment = findAncestor(tokenAtPos, isJSDoc);
|
||||
@@ -370,6 +369,11 @@ namespace ts.JsDoc {
|
||||
const parameters = isFunctionLike(be.right) ? be.right.parameters : emptyArray;
|
||||
return { commentOwner, parameters };
|
||||
}
|
||||
case SyntaxKind.PropertyDeclaration:
|
||||
const init = (commentOwner as PropertyDeclaration).initializer;
|
||||
if (init && (isFunctionExpression(init) || isArrowFunction(init))) {
|
||||
return { commentOwner, parameters: init.parameters };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
const singleLineOffset = 3;
|
||||
const multiLineOffset = 12;
|
||||
|
||||
|
||||
////class C {
|
||||
//// /** /*0*/ */
|
||||
//// foo = (p0) => {
|
||||
//// return p0;
|
||||
//// };
|
||||
//// /*1*/
|
||||
//// bar = (p1) => {
|
||||
//// return p1;
|
||||
//// }
|
||||
//// /*2*/
|
||||
//// baz = function (p2, p3) {
|
||||
//// return p2;
|
||||
//// }
|
||||
////}
|
||||
|
||||
verify.docCommentTemplateAt("0", multiLineOffset,
|
||||
`/**
|
||||
*
|
||||
* @param p0
|
||||
*/`);
|
||||
verify.docCommentTemplateAt("1", multiLineOffset,
|
||||
`/**
|
||||
*
|
||||
* @param p1
|
||||
*/`);
|
||||
verify.docCommentTemplateAt("2", multiLineOffset,
|
||||
`/**
|
||||
*
|
||||
* @param p2
|
||||
* @param p3
|
||||
*/`);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user