mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-17 21:06:50 -05:00
fix(45417): show inlay hints for null and literal-like identifiers (#45426)
This commit is contained in:
@@ -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],
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -310,5 +317,9 @@ namespace ts.InlayHints {
|
||||
printer.writeNode(EmitHint.Unspecified, typeNode, /*sourceFile*/ file, writer);
|
||||
});
|
||||
}
|
||||
|
||||
function isUndefined(name: __String) {
|
||||
return name === "undefined";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user