Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/services/jsDoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 };
}
}
}

Expand Down
39 changes: 39 additions & 0 deletions tests/cases/fourslash/docCommentTemplateClassDeclProperty01.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/// <reference path='fourslash.ts' />

const singleLineOffset = 3;
const multiLineOffset = 12;


////class C {
//// /** /*0*/ */
//// foo = (p0) => {
//// return p0;
//// };
//// /*1*/
//// bar = (p1) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should you also test the function expression case?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes!

//// 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
*/`);