Fix this-parameter emit for JSDocFunction types (#39814)

* Fix this parameter emit for JSDocFunction types

Previously, parameters with names that were not `new` were treated like
rest parameters. This is incorrect: parameters with the name `this`
should emit a `this` parameter.

Fixes #38550

* ❤️ quote style
This commit is contained in:
Nathan Shively-Sanders
2020-07-29 14:11:59 -07:00
committed by GitHub
parent f2d1531768
commit 9b2d487392
7 changed files with 79 additions and 4 deletions

View File

@@ -5777,7 +5777,7 @@ namespace ts {
/*decorators*/ undefined,
/*modifiers*/ undefined,
getEffectiveDotDotDotForParameter(p),
p.name || getEffectiveDotDotDotForParameter(p) ? `args` : `arg${i}`,
getNameForJSDocFunctionParameter(p, i),
p.questionToken,
visitNode(p.type, visitExistingNodeTreeSymbols),
/*initializer*/ undefined
@@ -5792,7 +5792,7 @@ namespace ts {
/*decorators*/ undefined,
/*modifiers*/ undefined,
getEffectiveDotDotDotForParameter(p),
p.name || getEffectiveDotDotDotForParameter(p) ? `args` : `arg${i}`,
getNameForJSDocFunctionParameter(p, i),
p.questionToken,
visitNode(p.type, visitExistingNodeTreeSymbols),
/*initializer*/ undefined
@@ -5847,6 +5847,13 @@ namespace ts {
return p.dotDotDotToken || (p.type && isJSDocVariadicType(p.type) ? factory.createToken(SyntaxKind.DotDotDotToken) : undefined);
}
/** Note that `new:T` parameters are not handled, but should be before calling this function. */
function getNameForJSDocFunctionParameter(p: ParameterDeclaration, index: number) {
return p.name && isIdentifier(p.name) && p.name.escapedText === "this" ? "this"
: getEffectiveDotDotDotForParameter(p) ? `args`
: `arg${index}`;
}
function rewriteModuleSpecifier(parent: ImportTypeNode, lit: StringLiteral) {
if (bundled) {
if (context.tracker && context.tracker.moduleResolverHost) {