Skip to content

Commit 7c00cd7

Browse files
committed
Merge upstream changes
2 parents 0f1d899 + 4fb58be commit 7c00cd7

File tree

47 files changed

+863
-393
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+863
-393
lines changed

internal/checker/checker.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9872,7 +9872,7 @@ func (c *Checker) contextuallyCheckFunctionExpressionOrObjectLiteralMethod(node
98729872
inferenceContext := c.getInferenceContext(node)
98739873
var instantiatedContextualSignature *Signature
98749874
if checkMode&CheckModeInferential != 0 {
9875-
c.inferFromAnnotatedParameters(signature, contextualSignature, inferenceContext)
9875+
c.inferFromAnnotatedParametersAndReturn(signature, contextualSignature, inferenceContext)
98769876
restType := c.getEffectiveRestType(contextualSignature)
98779877
if restType != nil && restType.flags&TypeFlagsTypeParameter != 0 {
98789878
instantiatedContextualSignature = c.instantiateSignature(contextualSignature, inferenceContext.nonFixingMapper)
@@ -9893,7 +9893,7 @@ func (c *Checker) contextuallyCheckFunctionExpressionOrObjectLiteralMethod(node
98939893
} else if contextualSignature != nil && node.TypeParameters() == nil && len(contextualSignature.parameters) > len(node.Parameters()) {
98949894
inferenceContext := c.getInferenceContext(node)
98959895
if checkMode&CheckModeInferential != 0 {
9896-
c.inferFromAnnotatedParameters(signature, contextualSignature, inferenceContext)
9896+
c.inferFromAnnotatedParametersAndReturn(signature, contextualSignature, inferenceContext)
98979897
}
98989898
}
98999899
if contextualSignature != nil && c.getReturnTypeFromAnnotation(node) == nil && signature.resolvedReturnType == nil {
@@ -9940,7 +9940,7 @@ func (c *Checker) checkFunctionExpressionOrObjectLiteralMethodDeferred(node *ast
99409940
}
99419941
}
99429942

9943-
func (c *Checker) inferFromAnnotatedParameters(sig *Signature, context *Signature, inferenceContext *InferenceContext) {
9943+
func (c *Checker) inferFromAnnotatedParametersAndReturn(sig *Signature, context *Signature, inferenceContext *InferenceContext) {
99449944
length := len(sig.parameters) - core.IfElse(signatureHasRestParameter(sig), 1, 0)
99459945
for i := range length {
99469946
declaration := sig.parameters[i].ValueDeclaration
@@ -9951,6 +9951,13 @@ func (c *Checker) inferFromAnnotatedParameters(sig *Signature, context *Signatur
99519951
c.inferTypes(inferenceContext.inferences, source, target, InferencePriorityNone, false)
99529952
}
99539953
}
9954+
if declaration := sig.Declaration(); declaration != nil {
9955+
if returnTypeNode := declaration.Type(); returnTypeNode != nil {
9956+
source := c.getTypeFromTypeNode(returnTypeNode)
9957+
target := c.getReturnTypeOfSignature(context)
9958+
c.inferTypes(inferenceContext.inferences, source, target, InferencePriorityNone, false)
9959+
}
9960+
}
99549961
}
99559962

99569963
// Return the contextual signature for a given expression node. A contextual type provides a

internal/checker/flow.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1427,7 +1427,7 @@ func (c *Checker) getCandidateDiscriminantPropertyAccess(f *FlowState, expr *ast
14271427
// parameter declared in the same parameter list is a candidate.
14281428
if ast.IsIdentifier(expr) {
14291429
symbol := c.getResolvedSymbol(expr)
1430-
declaration := symbol.ValueDeclaration
1430+
declaration := c.getExportSymbolOfValueSymbolIfExported(symbol).ValueDeclaration
14311431
if declaration != nil && (ast.IsBindingElement(declaration) || ast.IsParameter(declaration)) && f.reference == declaration.Parent && declaration.Initializer() == nil && !hasDotDotDotToken(declaration) {
14321432
return declaration
14331433
}

internal/checker/relater.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3298,6 +3298,22 @@ func (r *Relater) structuredTypeRelatedToWorker(source *Type, target *Type, repo
32983298
return result
32993299
}
33003300
}
3301+
case source.flags&TypeFlagsTemplateLiteral != 0:
3302+
if slices.Equal(source.AsTemplateLiteralType().texts, target.AsTemplateLiteralType().texts) {
3303+
result = TernaryTrue
3304+
for i, sourceType := range source.AsTemplateLiteralType().types {
3305+
targetType := target.AsTemplateLiteralType().types[i]
3306+
result &= r.isRelatedTo(sourceType, targetType, RecursionFlagsBoth, false /*reportErrors*/)
3307+
if result == TernaryFalse {
3308+
return result
3309+
}
3310+
}
3311+
return result
3312+
}
3313+
case source.flags&TypeFlagsStringMapping != 0:
3314+
if source.AsStringMappingType().Symbol() == target.AsStringMappingType().Symbol() {
3315+
return r.isRelatedTo(source.AsStringMappingType().target, target.AsStringMappingType().target, RecursionFlagsBoth, false /*reportErrors*/)
3316+
}
33013317
}
33023318
if source.flags&TypeFlagsObject == 0 {
33033319
return TernaryFalse

internal/fourslash/_scripts/failingTests.txt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,9 @@ TestDoubleUnderscoreCompletions
168168
TestEditJsdocType
169169
TestExportDefaultClass
170170
TestExportDefaultFunction
171-
TestFindAllReferencesDynamicImport1
172-
TestFindAllReferencesUmdModuleAsGlobalConst
173-
TestFindAllRefsExportEquals
174171
TestFindAllRefsForDefaultExport03
175172
TestFindAllRefsForModule
176173
TestFindAllRefsModuleDotExports
177-
TestFindAllRefs_importType_typeofImport
178174
TestFindReferencesBindingPatternInJsdocNoCrash1
179175
TestFindReferencesBindingPatternInJsdocNoCrash2
180176
TestGenericCombinatorWithConstraints1
@@ -262,7 +258,6 @@ TestJsdocTypedefTag
262258
TestJsdocTypedefTag2
263259
TestJsdocTypedefTagNamespace
264260
TestJsdocTypedefTagServices
265-
TestJsxFindAllReferencesOnRuntimeImportWithPaths1
266261
TestLetQuickInfoAndCompletionList
267262
TestLocalFunction
268263
TestMemberListInReopenedEnum
@@ -436,7 +431,6 @@ TestQuickinfoWrongComment
436431
TestRecursiveInternalModuleImport
437432
TestReferencesForStatementKeywords
438433
TestReferencesInEmptyFile
439-
TestReferencesIsAvailableThroughGlobalNoCrash
440434
TestRegexDetection
441435
TestRenameForAliasingExport02
442436
TestRenameFromNodeModulesDep1
@@ -461,7 +455,6 @@ TestTripleSlashRefPathCompletionExtensionsAllowJSFalse
461455
TestTripleSlashRefPathCompletionExtensionsAllowJSTrue
462456
TestTripleSlashRefPathCompletionHiddenFile
463457
TestTripleSlashRefPathCompletionRootdirs
464-
TestTslibFindAllReferencesOnRuntimeImportWithPaths1
465458
TestTsxCompletion14
466459
TestTsxCompletion15
467460
TestTsxCompletionNonTagLessThan
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package fourslash_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/microsoft/typescript-go/internal/fourslash"
7+
"github.com/microsoft/typescript-go/internal/testutil"
8+
)
9+
10+
func TestDocumentHighlightImportPath(t *testing.T) {
11+
t.Parallel()
12+
13+
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
14+
const content = `// @Filename: /a.ts
15+
export const x = 0;
16+
17+
// @Filename: /b.ts
18+
import { x } from "[|./a|]";`
19+
f := fourslash.NewFourslash(t, nil /*capabilities*/, content)
20+
f.VerifyBaselineDocumentHighlights(t, nil /*preferences*/, f.Ranges()[0])
21+
}

internal/fourslash/tests/gen/findAllReferencesDynamicImport1_test.go

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

1010
func TestFindAllReferencesDynamicImport1(t *testing.T) {
1111
t.Parallel()
12-
t.Skip()
12+
1313
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
1414
const content = `// @Filename: foo.ts
1515
export function foo() { return "foo"; }

internal/fourslash/tests/gen/findAllReferencesUmdModuleAsGlobalConst_test.go

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

1010
func TestFindAllReferencesUmdModuleAsGlobalConst(t *testing.T) {
1111
t.Parallel()
12-
t.Skip()
12+
1313
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
1414
const content = `// @Filename: /node_modules/@types/three/three-core.d.ts
1515
export class Vector3 {

internal/fourslash/tests/gen/findAllRefsExportEquals_test.go

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

1010
func TestFindAllRefsExportEquals(t *testing.T) {
1111
t.Parallel()
12-
t.Skip()
12+
1313
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
1414
const content = `// @Filename: /a.ts
1515
type /*0*/T = number;

internal/fourslash/tests/gen/findAllRefs_importType_typeofImport_test.go

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

1010
func TestFindAllRefs_importType_typeofImport(t *testing.T) {
1111
t.Parallel()
12-
t.Skip()
12+
1313
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
1414
const content = `// @Filename: /a.ts
1515
export const x = 0;

internal/fourslash/tests/gen/jsxFindAllReferencesOnRuntimeImportWithPaths1_test.go

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

1010
func TestJsxFindAllReferencesOnRuntimeImportWithPaths1(t *testing.T) {
1111
t.Parallel()
12-
t.Skip()
12+
1313
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
1414
const content = `// @Filename: project/src/foo.ts
1515
import * as x from /**/"@foo/dir/jsx-runtime";

0 commit comments

Comments
 (0)