Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃 Pick PR #45426 (fix(45417): null and literal-like i...) into release-4.4 #45445

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/compiler/checker.ts
Expand Up @@ -26284,10 +26284,6 @@ namespace ts {
return isTypeAssignableToKind(checkComputedPropertyName(name), TypeFlags.NumberLike);
}

function isInfinityOrNaNString(name: string | __String): boolean {
return name === "Infinity" || name === "-Infinity" || name === "NaN";
}

function isNumericLiteralName(name: string | __String) {
// The intent of numeric names is that
// - they are names with text in a numeric form, and that
Expand Down
5 changes: 5 additions & 0 deletions src/compiler/utilities.ts
Expand Up @@ -7367,4 +7367,9 @@ namespace ts {
}
return false;
}

/* @internal */
export function isInfinityOrNaNString(name: string | __String): boolean {
return name === "Infinity" || name === "-Infinity" || name === "NaN";
}
}
4 changes: 0 additions & 4 deletions src/services/classifier2020.ts
Expand Up @@ -225,10 +225,6 @@ namespace ts.classifier.v2020 {
return (isQualifiedName(node.parent) && node.parent.right === node) || (isPropertyAccessExpression(node.parent) && node.parent.name === node);
}

function isInfinityOrNaNString(name: __String): boolean {
return name === "Infinity" || name === "NaN";
}

const tokenFromDeclarationMapping = new Map<SyntaxKind, TokenType>([
[SyntaxKind.VariableDeclaration, TokenType.variable],
[SyntaxKind.Parameter, TokenType.parameter],
Expand Down
15 changes: 13 additions & 2 deletions src/services/inlayHints.ts
Expand Up @@ -204,15 +204,22 @@ namespace ts.InlayHints {

function isHintableExpression(node: Node) {
switch (node.kind) {
case SyntaxKind.PrefixUnaryExpression:
return isLiteralExpression((node as PrefixUnaryExpression).operand);
case SyntaxKind.PrefixUnaryExpression: {
const operand = (node as PrefixUnaryExpression).operand;
return isLiteralExpression(operand) || isIdentifier(operand) && isInfinityOrNaNString(operand.escapedText);
}
case SyntaxKind.TrueKeyword:
case SyntaxKind.FalseKeyword:
case SyntaxKind.ArrowFunction:
case SyntaxKind.FunctionExpression:
case SyntaxKind.ObjectLiteralExpression:
case SyntaxKind.ArrayLiteralExpression:
case SyntaxKind.NullKeyword:
return true;
case SyntaxKind.Identifier: {
const name = (node as Identifier).escapedText;
return isUndefined(name) || isInfinityOrNaNString(name);
}
}
return isLiteralExpression(node);
}
Expand Down Expand Up @@ -310,5 +317,9 @@ namespace ts.InlayHints {
printer.writeNode(EmitHint.Unspecified, typeNode, /*sourceFile*/ file, writer);
});
}

function isUndefined(name: __String) {
return name === "undefined";
}
}
}
94 changes: 94 additions & 0 deletions tests/cases/fourslash/inlayHintsShouldWork64.ts
@@ -0,0 +1,94 @@
/// <reference path="fourslash.ts" />

////function foo(
//// a: string,
//// b: undefined,
//// c: null,
//// d: boolean,
//// e: boolean,
//// f: number,
//// g: number,
//// h: number,
//// i: RegExp,
//// j: bigint,
////) {
////}
////
////foo(
//// /*a*/"hello",
//// /*b*/undefined,
//// /*c*/null,
//// /*d*/true,
//// /*e*/false,
//// /*f*/Infinity,
//// /*g*/-Infinity,
//// /*h*/NaN,
//// /*i*//hello/g,
//// /*j*/123n,
////);

const [a, b, c, d, e, f, g, h, i, j] = 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
},
{
text: "e:",
position: e.position,
kind: ts.InlayHintKind.Parameter,
whitespaceAfter: true
},
{
text: "f:",
position: f.position,
kind: ts.InlayHintKind.Parameter,
whitespaceAfter: true
},
{
text: "g:",
position: g.position,
kind: ts.InlayHintKind.Parameter,
whitespaceAfter: true
},
{
text: "h:",
position: h.position,
kind: ts.InlayHintKind.Parameter,
whitespaceAfter: true
},
{
text: "i:",
position: i.position,
kind: ts.InlayHintKind.Parameter,
whitespaceAfter: true
},
{
text: "j:",
position: j.position,
kind: ts.InlayHintKind.Parameter,
whitespaceAfter: true
}
], undefined, {
includeInlayParameterNameHints: "literals"
});