Skip to content

Commit

Permalink
fix(52277): switch/case completions fail when has a negative literal …
Browse files Browse the repository at this point in the history
…type (#52278)
  • Loading branch information
a-tarasyuk authored Jan 17, 2023
1 parent 16c695c commit 8094007
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/services/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
29 changes: 29 additions & 0 deletions tests/cases/fourslash/exhaustiveCaseCompletions7.ts
Original file line number Diff line number Diff line change
@@ -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 changes: 28 additions & 0 deletions tests/cases/fourslash/exhaustiveCaseCompletions8.ts
Original file line number Diff line number Diff line change
@@ -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,
},
},
);

0 comments on commit 8094007

Please sign in to comment.