infer from usage JSDoc:Don't emit nested comments (#28161)

* infer from usage JSDoc:Don't emit nested comments

Previously, the trivia on a parameter name would show up inside the
emitted JSDoc comment. If the trivia contained a C-style comment, the
emitted JSDoc comment would be invalid. For example:

```js
function call(callback /*oh no*/) {
  return callback(this)
}
```

Emitted this comment:

```js
/**
 * @param {(arg0: any) => void} callback /*oh no*/
 */
```

* Remove misleading comment used for debugging.
This commit is contained in:
Nathan Shively-Sanders
2018-10-26 14:09:42 -07:00
committed by GitHub
parent 14c328e706
commit 372c7d9b0c
2 changed files with 27 additions and 1 deletions

View File

@@ -219,7 +219,9 @@ namespace ts.codefix {
if (param.initializer || getJSDocType(param) || !isIdentifier(param.name)) return;
const typeNode = inference.type && getTypeNodeIfAccessible(inference.type, param, program, host);
return typeNode && createJSDocParamTag(param.name, !!inference.isOptional, createJSDocTypeExpression(typeNode), "");
const name = getSynthesizedClone(param.name);
setEmitFlags(name, EmitFlags.NoComments | EmitFlags.NoNestedComments);
return typeNode && createJSDocParamTag(name, !!inference.isOptional, createJSDocTypeExpression(typeNode), "");
});
addJSDocTags(changes, sourceFile, signature, paramTags);
}