mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
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:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @allowJs: true
|
||||
// @checkJs: true
|
||||
// @noEmit: true
|
||||
// @noImplicitAny: true
|
||||
// @Filename: important.js
|
||||
|
||||
|
||||
////function coll(callback /*, name1, name2, ... */) {
|
||||
//// return callback(this);
|
||||
////}
|
||||
|
||||
verify.codeFix({
|
||||
description: "Infer parameter types from usage",
|
||||
index: 2,
|
||||
newFileContent:
|
||||
`/**
|
||||
* @param {(arg0: any) => void} callback
|
||||
*/
|
||||
function coll(callback /*, name1, name2, ... */) {
|
||||
return callback(this);
|
||||
}`,
|
||||
});
|
||||
Reference in New Issue
Block a user