fix(52277): switch/case completions fail when has a negative literal type (#52278)

This commit is contained in:
Oleksandr T 2023-01-18 00:10:29 +02:00 коммит произвёл GitHub
Родитель 16c695cdbb
Коммит 8094007a1d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 59 добавлений и 2 удалений

Просмотреть файл

@ -1050,10 +1050,10 @@ function getExhaustiveCaseSnippets(
else if (!tracker.hasValue(type.value)) {
switch (typeof type.value) {
case "object":
elements.push(factory.createBigIntLiteral(type.value));
elements.push(type.value.negative ? factory.createPrefixUnaryExpression(SyntaxKind.MinusToken, factory.createBigIntLiteral({ negative: false, base10Value: type.value.base10Value })) : factory.createBigIntLiteral(type.value));
break;
case "number":
elements.push(factory.createNumericLiteral(type.value));
elements.push(type.value < 0 ? factory.createPrefixUnaryExpression(SyntaxKind.MinusToken, factory.createNumericLiteral(-type.value)) : factory.createNumericLiteral(type.value));
break;
case "string":
elements.push(factory.createStringLiteral(type.value, quotePreference === QuotePreference.Single));

Просмотреть файл

@ -0,0 +1,29 @@
/// <reference path="fourslash.ts" />
// @newline: LF
////export function foo(position: -1 | 0 | 1) {
//// switch (position) {
//// /**/
//// }
////}
verify.completions(
{
marker: "",
isNewIdentifierLocation: false,
includes: [
{
name: "case 0: ...",
source: completion.CompletionSource.SwitchCases,
sortText: completion.SortText.GlobalsOrKeywords,
insertText:
`case 0:
case 1:
case -1:`,
},
],
preferences: {
includeCompletionsWithInsertText: true,
},
},
);

Просмотреть файл

@ -0,0 +1,28 @@
/// <reference path="fourslash.ts" />
// @newline: LF
////export function foo(position: -1n | 0n) {
//// switch (position) {
//// /**/
//// }
////}
verify.completions(
{
marker: "",
isNewIdentifierLocation: false,
includes: [
{
name: "case 0n: ...",
source: completion.CompletionSource.SwitchCases,
sortText: completion.SortText.GlobalsOrKeywords,
insertText:
`case 0n:
case -1n:`,
},
],
preferences: {
includeCompletionsWithInsertText: true,
},
},
);