Cherry-pick PR #45399 into release-4.4 (#45404)

Component commits:
f7af8f4a4a fix(45393): show parameter name hints for unary literal expressions

Co-authored-by: Oleksandr T <oleksandr.tarasiuk@outlook.com>
This commit is contained in:
TypeScript Bot
2021-08-10 23:20:29 -07:00
committed by GitHub
co-authored by Oleksandr T
parent 0648de87a0
commit c82ccf1391
2 changed files with 46 additions and 1 deletions
+12 -1
View File
@@ -203,7 +203,18 @@ namespace ts.InlayHints {
}
function isHintableExpression(node: Node) {
return isLiteralExpression(node) || isBooleanLiteral(node) || isArrowFunction(node) || isFunctionExpression(node) || isObjectLiteralExpression(node) || isArrayLiteralExpression(node);
switch (node.kind) {
case SyntaxKind.PrefixUnaryExpression:
return isLiteralExpression((node as PrefixUnaryExpression).operand);
case SyntaxKind.TrueKeyword:
case SyntaxKind.FalseKeyword:
case SyntaxKind.ArrowFunction:
case SyntaxKind.FunctionExpression:
case SyntaxKind.ObjectLiteralExpression:
case SyntaxKind.ArrayLiteralExpression:
return true;
}
return isLiteralExpression(node);
}
function visitFunctionDeclarationLikeForReturnType(decl: FunctionDeclaration | ArrowFunction | FunctionExpression | MethodDeclaration | GetAccessorDeclaration) {
@@ -0,0 +1,34 @@
/// <reference path="fourslash.ts" />
////function foo(a: number, b: number, c: number, d: number) {}
////foo(/*a*/1, /*b*/+1, /*c*/-1, /*d*/+"1");
const [a, b, c, d] = test.markers();
verify.getInlayHints([
{
text: "a:",
position: a.position,
kind: ts.InlayHintKind.Parameter,
whitespaceAfter: true
},
{
text: "b:",
position: b.position,
kind: ts.InlayHintKind.Parameter,
whitespaceAfter: true
},
{
text: "c:",
position: c.position,
kind: ts.InlayHintKind.Parameter,
whitespaceAfter: true
},
{
text: "d:",
position: d.position,
kind: ts.InlayHintKind.Parameter,
whitespaceAfter: true
}
], undefined, {
includeInlayParameterNameHints: "literals"
});