mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-10 18:04:18 -05:00
fix(52277): switch/case completions fail when has a negative literal type (#52278)
This commit is contained in:
@@ -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));
|
||||
|
||||
29
tests/cases/fourslash/exhaustiveCaseCompletions7.ts
Normal file
29
tests/cases/fourslash/exhaustiveCaseCompletions7.ts
Normal file
@@ -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,
|
||||
},
|
||||
},
|
||||
);
|
||||
28
tests/cases/fourslash/exhaustiveCaseCompletions8.ts
Normal file
28
tests/cases/fourslash/exhaustiveCaseCompletions8.ts
Normal file
@@ -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,
|
||||
},
|
||||
},
|
||||
);
|
||||
Reference in New Issue
Block a user