Skip to content

Commit b7ca2d3

Browse files
authored
Handle blockedStringType (#1266)
1 parent 6e03d62 commit b7ca2d3

8 files changed

+15
-20
lines changed

internal/ast/nodeflags.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ const (
4343
NodeFlagsJsonFile NodeFlags = 1 << 25 // If node was parsed in a Json
4444
NodeFlagsDeprecated NodeFlags = 1 << 26 // If has '@deprecated' JSDoc tag
4545

46-
NodeFlagsSkipDirectInference NodeFlags = 1 << 27 // If the node should skip direct type inference.
47-
4846
NodeFlagsBlockScoped = NodeFlagsLet | NodeFlagsConst | NodeFlagsUsing
4947
NodeFlagsConstant = NodeFlagsConst | NodeFlagsUsing
5048
NodeFlagsAwaitUsing = NodeFlagsConst | NodeFlagsUsing // Variable declaration (NOTE: on a single node these flags would otherwise be mutually exclusive)

internal/checker/checker.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7352,7 +7352,9 @@ func (c *Checker) checkExpressionWorker(node *ast.Node, checkMode CheckMode) *Ty
73527352
case ast.KindNullKeyword:
73537353
return c.nullWideningType
73547354
case ast.KindStringLiteral, ast.KindNoSubstitutionTemplateLiteral:
7355-
// !!! Handle blockedStringType
7355+
if c.isSkipDirectInferenceNode(node) {
7356+
return c.blockedStringType
7357+
}
73567358
return c.getFreshTypeOfLiteralType(c.getStringLiteralType(node.Text()))
73577359
case ast.KindNumericLiteral:
73587360
c.checkGrammarNumericLiteral(node.AsNumericLiteral())

internal/checker/services.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -585,28 +585,27 @@ func (c *Checker) getResolvedSignatureWorker(node *ast.Node, checkMode CheckMode
585585
}
586586

587587
func (c *Checker) GetCandidateSignaturesForStringLiteralCompletions(call *ast.CallLikeExpression, editingArgument *ast.Node) []*Signature {
588-
candidatesSet := collections.Set[*Signature]{}
589-
590588
// first, get candidates when inference is blocked from the source node.
591589
candidates := runWithInferenceBlockedFromSourceNode(c, editingArgument, func() []*Signature {
592590
_, blockedInferenceCandidates := c.getResolvedSignatureWorker(call, CheckModeNormal, 0)
593591
return blockedInferenceCandidates
594592
})
595-
for _, candidate := range candidates {
596-
candidatesSet.Add(candidate)
597-
}
593+
candidatesSet := collections.NewSetFromItems(candidates...)
598594

599595
// next, get candidates where the source node is considered for inference.
600-
candidates = runWithoutResolvedSignatureCaching(c, editingArgument, func() []*Signature {
596+
otherCandidates := runWithoutResolvedSignatureCaching(c, editingArgument, func() []*Signature {
601597
_, inferenceCandidates := c.getResolvedSignatureWorker(call, CheckModeNormal, 0)
602598
return inferenceCandidates
603599
})
604600

605-
for _, candidate := range candidates {
606-
candidatesSet.Add(candidate)
601+
for _, candidate := range otherCandidates {
602+
if candidatesSet.Has(candidate) {
603+
continue
604+
}
605+
candidates = append(candidates, candidate)
607606
}
608607

609-
return slices.Collect(maps.Keys(candidatesSet.Keys()))
608+
return candidates
610609
}
611610

612611
func (c *Checker) GetTypeParameterAtPosition(s *Signature, pos int) *Type {

internal/fourslash/_scripts/failingTests.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ TestCompletionsJsPropertyAssignment
115115
TestCompletionsJsxAttribute2
116116
TestCompletionsKeyof
117117
TestCompletionsLiteralFromInferenceWithinInferredType3
118-
TestCompletionsLiteralMatchingGenericSignature
119118
TestCompletionsNamespaceName
120119
TestCompletionsNewTarget
121120
TestCompletionsNonExistentImport
@@ -237,11 +236,8 @@ TestPathCompletionsPackageJsonImportsWildcard9
237236
TestPathCompletionsTypesVersionsLocal
238237
TestPathCompletionsTypesVersionsWildcard2
239238
TestSatisfiesOperatorCompletion
240-
TestStringCompletionsFromGenericConditionalTypesUsingTemplateLiteralTypes
241239
TestStringCompletionsImportOrExportSpecifier
242240
TestStringCompletionsVsEscaping
243-
TestStringLiteralCompletionsForGenericConditionalTypesUsingTemplateLiteralTypes
244-
TestStringLiteralCompletionsInPositionTypedUsingRest
245241
TestStringLiteralTypeCompletionsInTypeArgForNonGeneric1
246242
TestTripleSlashRefPathCompletionAbsolutePaths
247243
TestTripleSlashRefPathCompletionContext

internal/fourslash/tests/gen/completionsLiteralMatchingGenericSignature_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
func TestCompletionsLiteralMatchingGenericSignature(t *testing.T) {
1212
t.Parallel()
13-
t.Skip()
13+
1414
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
1515
const content = `// @Filename: /a.tsx
1616
declare function bar1<P extends "" | "bar" | "baz">(p: P): void;

internal/fourslash/tests/gen/stringCompletionsFromGenericConditionalTypesUsingTemplateLiteralTypes_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
func TestStringCompletionsFromGenericConditionalTypesUsingTemplateLiteralTypes(t *testing.T) {
1212
t.Parallel()
13-
t.Skip()
13+
1414
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
1515
const content = `// @strict: true
1616
type keyword = "foo" | "bar" | "baz"

internal/fourslash/tests/gen/stringLiteralCompletionsForGenericConditionalTypesUsingTemplateLiteralTypes_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
func TestStringLiteralCompletionsForGenericConditionalTypesUsingTemplateLiteralTypes(t *testing.T) {
1212
t.Parallel()
13-
t.Skip()
13+
1414
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
1515
const content = ` type PathOf<T, K extends string, P extends string = ""> =
1616
K extends ` + "`" + `${infer U}.${infer V}` + "`" + `

internal/fourslash/tests/gen/stringLiteralCompletionsInPositionTypedUsingRest_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
func TestStringLiteralCompletionsInPositionTypedUsingRest(t *testing.T) {
1212
t.Parallel()
13-
t.Skip()
13+
1414
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
1515
const content = `declare function pick<T extends object, K extends keyof T>(obj: T, ...keys: K[]): Pick<T, K>;
1616
declare function pick2<T extends object, K extends (keyof T)[]>(obj: T, ...keys: K): Pick<T, K[number]>;

0 commit comments

Comments
 (0)