mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-30 01:04:49 -05:00
Fix the code that checks for variadic signatures
This code looks strange, like there's a typo in it (eg, using `lists` in the `parameterList` loop, etc) -- so I also refactored it a bit to look more intentional. The new format makes it clearer that `lists` is checked once *outside* the loop, as well as the role of `hasEffectiveRestParameter`. The actual bug fix is checking `pList.length` in the new `isVariadic()`. Fixes 41059.
This commit is contained in:
@@ -624,7 +624,6 @@ namespace ts.SignatureHelp {
|
||||
}
|
||||
|
||||
function itemInfoForParameters(candidateSignature: Signature, checker: TypeChecker, enclosingDeclaration: Node, sourceFile: SourceFile): SignatureHelpItemInfo[] {
|
||||
const isVariadic = checker.hasEffectiveRestParameter(candidateSignature);
|
||||
const printer = createPrinter({ removeComments: true });
|
||||
const typeParameterParts = mapToDisplayParts(writer => {
|
||||
if (candidateSignature.typeParameters && candidateSignature.typeParameters.length) {
|
||||
@@ -633,14 +632,16 @@ namespace ts.SignatureHelp {
|
||||
}
|
||||
});
|
||||
const lists = checker.getExpandedParameters(candidateSignature);
|
||||
return lists.map(parameterList => {
|
||||
return {
|
||||
isVariadic: isVariadic && (lists.length === 1 || !!((parameterList[parameterList.length - 1] as TransientSymbol).checkFlags & CheckFlags.RestParameter)),
|
||||
parameters: parameterList.map(p => createSignatureHelpParameterForParameter(p, checker, enclosingDeclaration, sourceFile, printer)),
|
||||
prefix: [...typeParameterParts, punctuationPart(SyntaxKind.OpenParenToken)],
|
||||
suffix: [punctuationPart(SyntaxKind.CloseParenToken)]
|
||||
};
|
||||
});
|
||||
const isVariadic: (parameterList: readonly Symbol[]) => boolean =
|
||||
!checker.hasEffectiveRestParameter(candidateSignature) ? _ => false
|
||||
: lists.length === 1 ? _ => true
|
||||
: pList => !!(pList.length && (pList[pList.length - 1] as TransientSymbol).checkFlags & CheckFlags.RestParameter);
|
||||
return lists.map(parameterList => ({
|
||||
isVariadic: isVariadic(parameterList),
|
||||
parameters: parameterList.map(p => createSignatureHelpParameterForParameter(p, checker, enclosingDeclaration, sourceFile, printer)),
|
||||
prefix: [...typeParameterParts, punctuationPart(SyntaxKind.OpenParenToken)],
|
||||
suffix: [punctuationPart(SyntaxKind.CloseParenToken)]
|
||||
}));
|
||||
}
|
||||
|
||||
function createSignatureHelpParameterForParameter(parameter: Symbol, checker: TypeChecker, enclosingDeclaration: Node, sourceFile: SourceFile, printer: Printer): SignatureHelpParameter {
|
||||
|
||||
10
tests/cases/fourslash/jsSignature-41059.ts
Normal file
10
tests/cases/fourslash/jsSignature-41059.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
// @lib: esnext
|
||||
// @allowNonTsExtensions: true
|
||||
|
||||
// @Filename: Foo.js
|
||||
//// a.next(/**/);
|
||||
|
||||
goTo.marker();
|
||||
verify.signatureHelp({ overloadsCount: 2, text: "Generator.next(): IteratorResult<T, TReturn>" });
|
||||
Reference in New Issue
Block a user