mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
fix(42238): emit this parameter in function declaration (#46511)
This commit is contained in:
+21
-2
@@ -5657,8 +5657,8 @@ namespace ts {
|
||||
const expandedParams = getExpandedParameters(signature, /*skipUnionExpanding*/ true)[0];
|
||||
// If the expanded parameter list had a variadic in a non-trailing position, don't expand it
|
||||
const parameters = (some(expandedParams, p => p !== expandedParams[expandedParams.length - 1] && !!(getCheckFlags(p) & CheckFlags.RestParameter)) ? signature.parameters : expandedParams).map(parameter => symbolToParameterDeclaration(parameter, context, kind === SyntaxKind.Constructor, options?.privateSymbolVisitor, options?.bundledImports));
|
||||
if (signature.thisParameter) {
|
||||
const thisParameter = symbolToParameterDeclaration(signature.thisParameter, context);
|
||||
const thisParameter = tryGetThisParameterDeclaration(signature, context);
|
||||
if (thisParameter) {
|
||||
parameters.unshift(thisParameter);
|
||||
}
|
||||
|
||||
@@ -5713,6 +5713,25 @@ namespace ts {
|
||||
return node;
|
||||
}
|
||||
|
||||
function tryGetThisParameterDeclaration(signature: Signature, context: NodeBuilderContext) {
|
||||
if (signature.thisParameter) {
|
||||
return symbolToParameterDeclaration(signature.thisParameter, context);
|
||||
}
|
||||
if (signature.declaration) {
|
||||
const thisTag = getJSDocThisTag(signature.declaration);
|
||||
if (thisTag && thisTag.typeExpression) {
|
||||
return factory.createParameterDeclaration(
|
||||
/* decorators */ undefined,
|
||||
/* modifiers */ undefined,
|
||||
/* dotDotDotToken */ undefined,
|
||||
"this",
|
||||
/* questionToken */ undefined,
|
||||
typeToTypeNodeHelper(getTypeFromTypeNode(thisTag.typeExpression), context)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function typeParameterToDeclarationWithConstraint(type: TypeParameter, context: NodeBuilderContext, constraintNode: TypeNode | undefined): TypeParameterDeclaration {
|
||||
const savedContextFlags = context.flags;
|
||||
context.flags &= ~NodeBuilderFlags.WriteTypeParametersInQualifiedName; // Avoids potential infinite loop when building for a claimspace with a generic
|
||||
|
||||
Reference in New Issue
Block a user