Skip to content

Commit 2cc5856

Browse files
authoredFeb 6, 2020
Support property declarations in jsdoc template generation (#36658)
* Support property declarations in jsdoc template generation * fix lint and add test
1 parent b8b5948 commit 2cc5856

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed
 

Diff for: ‎src/services/jsDoc.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@ namespace ts.JsDoc {
251251
* @param position The (character-indexed) position in the file where the check should
252252
* be performed.
253253
*/
254-
255254
export function getDocCommentTemplateAtPosition(newLine: string, sourceFile: SourceFile, position: number): TextInsertion | undefined {
256255
const tokenAtPos = getTokenAtPosition(sourceFile, position);
257256
const existingDocComment = findAncestor(tokenAtPos, isJSDoc);
@@ -370,6 +369,11 @@ namespace ts.JsDoc {
370369
const parameters = isFunctionLike(be.right) ? be.right.parameters : emptyArray;
371370
return { commentOwner, parameters };
372371
}
372+
case SyntaxKind.PropertyDeclaration:
373+
const init = (commentOwner as PropertyDeclaration).initializer;
374+
if (init && (isFunctionExpression(init) || isArrowFunction(init))) {
375+
return { commentOwner, parameters: init.parameters };
376+
}
373377
}
374378
}
375379

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
const singleLineOffset = 3;
4+
const multiLineOffset = 12;
5+
6+
7+
////class C {
8+
//// /** /*0*/ */
9+
//// foo = (p0) => {
10+
//// return p0;
11+
//// };
12+
//// /*1*/
13+
//// bar = (p1) => {
14+
//// return p1;
15+
//// }
16+
//// /*2*/
17+
//// baz = function (p2, p3) {
18+
//// return p2;
19+
//// }
20+
////}
21+
22+
verify.docCommentTemplateAt("0", multiLineOffset,
23+
`/**
24+
*
25+
* @param p0
26+
*/`);
27+
verify.docCommentTemplateAt("1", multiLineOffset,
28+
`/**
29+
*
30+
* @param p1
31+
*/`);
32+
verify.docCommentTemplateAt("2", multiLineOffset,
33+
`/**
34+
*
35+
* @param p2
36+
* @param p3
37+
*/`);
38+
39+

0 commit comments

Comments
 (0)
Please sign in to comment.