mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
fix(55945): Inlay hints don't work for bigint literals (#55947)
This commit is contained in:
@@ -3,6 +3,7 @@ import {
|
||||
ArrayTypeNode,
|
||||
ArrowFunction,
|
||||
CallExpression,
|
||||
CharacterCodes,
|
||||
ConditionalTypeNode,
|
||||
ConstructorTypeNode,
|
||||
createPrinterWithRemoveComments,
|
||||
@@ -12,6 +13,7 @@ import {
|
||||
EmitHint,
|
||||
EnumMember,
|
||||
equateStringsCaseInsensitive,
|
||||
escapeString,
|
||||
Expression,
|
||||
findChildOfKind,
|
||||
findIndex,
|
||||
@@ -26,6 +28,7 @@ import {
|
||||
getLanguageVariant,
|
||||
getLeadingCommentRanges,
|
||||
getNameOfDeclaration,
|
||||
getQuotePreference,
|
||||
hasContextSensitiveParameters,
|
||||
Identifier,
|
||||
idText,
|
||||
@@ -59,9 +62,11 @@ import {
|
||||
isPropertyAccessExpression,
|
||||
isPropertyDeclaration,
|
||||
isSpreadElement,
|
||||
isStringLiteral,
|
||||
isTypeNode,
|
||||
isVarConst,
|
||||
isVariableDeclaration,
|
||||
LiteralExpression,
|
||||
LiteralTypeNode,
|
||||
MappedTypeNode,
|
||||
MethodDeclaration,
|
||||
@@ -70,7 +75,6 @@ import {
|
||||
Node,
|
||||
NodeArray,
|
||||
NodeBuilderFlags,
|
||||
NumericLiteral,
|
||||
OptionalTypeNode,
|
||||
ParameterDeclaration,
|
||||
ParenthesizedTypeNode,
|
||||
@@ -78,11 +82,11 @@ import {
|
||||
PropertyDeclaration,
|
||||
PropertySignature,
|
||||
QualifiedName,
|
||||
QuotePreference,
|
||||
RestTypeNode,
|
||||
Signature,
|
||||
skipParentheses,
|
||||
some,
|
||||
StringLiteral,
|
||||
Symbol,
|
||||
SymbolFlags,
|
||||
SyntaxKind,
|
||||
@@ -125,6 +129,7 @@ export function provideInlayHints(context: InlayHintsContext): InlayHint[] {
|
||||
const { file, program, span, cancellationToken, preferences } = context;
|
||||
const sourceFileText = file.text;
|
||||
const compilerOptions = program.getCompilerOptions();
|
||||
const quotePreference = getQuotePreference(file, preferences);
|
||||
|
||||
const checker = program.getTypeChecker();
|
||||
const result: InlayHint[] = [];
|
||||
@@ -473,6 +478,11 @@ export function provideInlayHints(context: InlayHintsContext): InlayHint[] {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isLiteralExpression(node)) {
|
||||
parts.push({ text: getLiteralText(node) });
|
||||
return;
|
||||
}
|
||||
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.Identifier:
|
||||
const identifier = node as Identifier;
|
||||
@@ -485,12 +495,6 @@ export function provideInlayHints(context: InlayHintsContext): InlayHint[] {
|
||||
parts.push({ text: identifierText });
|
||||
}
|
||||
break;
|
||||
case SyntaxKind.NumericLiteral:
|
||||
parts.push({ text: (node as NumericLiteral).text });
|
||||
break;
|
||||
case SyntaxKind.StringLiteral:
|
||||
parts.push({ text: `"${(node as StringLiteral).text}"` });
|
||||
break;
|
||||
case SyntaxKind.QualifiedName:
|
||||
const qualifiedName = node as QualifiedName;
|
||||
visitForDisplayParts(qualifiedName.left);
|
||||
@@ -749,6 +753,13 @@ export function provideInlayHints(context: InlayHintsContext): InlayHint[] {
|
||||
visitForDisplayParts(node);
|
||||
});
|
||||
}
|
||||
|
||||
function getLiteralText(node: LiteralExpression) {
|
||||
if (isStringLiteral(node)) {
|
||||
return quotePreference === QuotePreference.Single ? `'${escapeString(node.text, CharacterCodes.singleQuote)}'` : `"${escapeString(node.text, CharacterCodes.doubleQuote)}"`;
|
||||
}
|
||||
return node.text;
|
||||
}
|
||||
}
|
||||
|
||||
function isUndefined(name: __String) {
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
export function fn(b = foo) {}
|
||||
^
|
||||
{
|
||||
"text": "",
|
||||
"displayParts": [
|
||||
{
|
||||
"text": ": "
|
||||
},
|
||||
{
|
||||
"text": "1n"
|
||||
}
|
||||
],
|
||||
"position": 40,
|
||||
"kind": "Type",
|
||||
"whitespaceBefore": true
|
||||
}
|
||||
@@ -60,7 +60,7 @@ function bar () { return import('./a') }
|
||||
"text": "import("
|
||||
},
|
||||
{
|
||||
"text": "\"/a\""
|
||||
"text": "'/a'"
|
||||
},
|
||||
{
|
||||
"text": ")"
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
export function fn(a = a1, b = b1) {}
|
||||
^
|
||||
{
|
||||
"text": "",
|
||||
"displayParts": [
|
||||
{
|
||||
"text": ": "
|
||||
},
|
||||
{
|
||||
"text": "\"\\\"\""
|
||||
}
|
||||
],
|
||||
"position": 64,
|
||||
"kind": "Type",
|
||||
"whitespaceBefore": true
|
||||
}
|
||||
|
||||
export function fn(a = a1, b = b1) {}
|
||||
^
|
||||
{
|
||||
"text": "",
|
||||
"displayParts": [
|
||||
{
|
||||
"text": ": "
|
||||
},
|
||||
{
|
||||
"text": "\"\\\\\""
|
||||
}
|
||||
],
|
||||
"position": 72,
|
||||
"kind": "Type",
|
||||
"whitespaceBefore": true
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
export function fn(a = a1, b = b1) {}
|
||||
^
|
||||
{
|
||||
"text": "",
|
||||
"displayParts": [
|
||||
{
|
||||
"text": ": "
|
||||
},
|
||||
{
|
||||
"text": "'\\''"
|
||||
}
|
||||
],
|
||||
"position": 64,
|
||||
"kind": "Type",
|
||||
"whitespaceBefore": true
|
||||
}
|
||||
|
||||
export function fn(a = a1, b = b1) {}
|
||||
^
|
||||
{
|
||||
"text": "",
|
||||
"displayParts": [
|
||||
{
|
||||
"text": ": "
|
||||
},
|
||||
{
|
||||
"text": "'\\\\'"
|
||||
}
|
||||
],
|
||||
"position": 72,
|
||||
"kind": "Type",
|
||||
"whitespaceBefore": true
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
////const foo: 1n = 1n;
|
||||
////export function fn(b = foo) {}
|
||||
|
||||
verify.baselineInlayHints(undefined, {
|
||||
includeInlayFunctionParameterTypeHints: true,
|
||||
interactiveInlayHints: true
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
////const a1: '"' = '"';
|
||||
////const b1: '\\' = '\\';
|
||||
////export function fn(a = a1, b = b1) {}
|
||||
|
||||
verify.baselineInlayHints(undefined, {
|
||||
includeInlayFunctionParameterTypeHints: true,
|
||||
interactiveInlayHints: true,
|
||||
quotePreference: "double"
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
////const a1: "'" = "'";
|
||||
////const b1: "\\" = "\\";
|
||||
////export function fn(a = a1, b = b1) {}
|
||||
|
||||
verify.baselineInlayHints(undefined, {
|
||||
includeInlayFunctionParameterTypeHints: true,
|
||||
interactiveInlayHints: true,
|
||||
quotePreference: "single"
|
||||
});
|
||||
Reference in New Issue
Block a user