fix(52277): switch/case completions fail when has a negative literal type (#52278)
This commit is contained in:
Родитель
16c695cdbb
Коммит
8094007a1d
|
@ -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,
|
||||
},
|
||||
},
|
||||
);
|
Загрузка…
Ссылка в новой задаче