Skip to content

Commit 2109350

Browse files
Respond to CR
1 parent 612616a commit 2109350

1 file changed

Lines changed: 8 additions & 20 deletions

File tree

src/services/jsDoc.ts

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,9 @@ namespace ts.JsDoc {
208208
return undefined;
209209
}
210210

211-
if (commentOwner.getStart() < position) {
212-
// if climbing the tree found a declaration with parameters but the request was made inside it, complete to a single line comment
213-
return singleLineTemplate;
214-
}
215-
216-
if (parameters.length === 0) {
217-
// if there are no parameters, complete to a single line comment
211+
if (commentOwner.getStart() < position || parameters.length === 0) {
212+
// if climbing the tree found a declaration with parameters but the request was made inside it
213+
// or if there are no parameters, complete to a single line comment
218214
return singleLineTemplate;
219215
}
220216

@@ -225,19 +221,11 @@ namespace ts.JsDoc {
225221
const indentationStr = sourceFile.text.substr(lineStart, posLineAndChar.character).replace(/\S/i, () => " ");
226222
const isJavaScriptFile = hasJavaScriptFileExtension(sourceFile.fileName);
227223

228-
let docParams = "";
229-
for (let i = 0; i < parameters.length; i++) {
230-
const currentName = parameters[i].name;
231-
const paramName = currentName.kind === SyntaxKind.Identifier ?
232-
(<Identifier>currentName).escapedText :
233-
"param" + i;
234-
if (isJavaScriptFile) {
235-
docParams += `${indentationStr} * @param {any} ${paramName}${newLine}`;
236-
}
237-
else {
238-
docParams += `${indentationStr} * @param ${paramName}${newLine}`;
239-
}
240-
}
224+
const docParams = parameters.map(({name}, i) => {
225+
const nameText = isIdentifier(name) ? name.text : `param${i}`;
226+
const type = isJavaScriptFile ? "{any} " : "";
227+
return `${indentationStr} * @param ${type}${nameText}${newLine}`;
228+
}).join("");
241229

242230
// A doc comment consists of the following
243231
// * The opening comment line

0 commit comments

Comments
 (0)