Skip to content

Commit

Permalink
Support property declarations in jsdoc template generation (#36658)
Browse files Browse the repository at this point in the history
* Support property declarations in jsdoc template generation

* fix lint and add test
  • Loading branch information
sandersn authored Feb 6, 2020
1 parent b8b5948 commit 2cc5856
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
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) => {
//// 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
*/`);


0 comments on commit 2cc5856

Please sign in to comment.