diff --git a/tsc/internal/compiler/program.go b/tsc/internal/compiler/program.go
index 34f713918a6ad..ccdabc2f3e8df 100644
--- a/tsc/internal/compiler/program.go
+++ b/tsc/internal/compiler/program.go
@@ -2087,12 +2087,14 @@ func (p *Program) ExplainFiles(w io.Writer, locale locale.Locale) {
}
func (p *Program) GetLibFileFromReference(ref *ast.FileReference) *ast.SourceFile {
- path, ok := tsoptions.GetLibFileName(ref.FileName)
+ name, ok := tsoptions.GetLibFileName(ref.FileName)
if !ok {
return nil
}
- if sourceFile, ok := p.filesByPath[tspath.Path(path)]; ok {
- return sourceFile
+ for path, libFile := range p.libFiles {
+ if libFile.Name == name {
+ return p.filesByPath[path]
+ }
}
return nil
}
diff --git a/tsc/internal/fourslash/tests/goToDefinitionTypeReferenceDirective_test.go b/tsc/internal/fourslash/tests/goToDefinitionTypeReferenceDirective_test.go
index 678d01f70b5b2..5b5ad50887189 100644
--- a/tsc/internal/fourslash/tests/goToDefinitionTypeReferenceDirective_test.go
+++ b/tsc/internal/fourslash/tests/goToDefinitionTypeReferenceDirective_test.go
@@ -20,3 +20,13 @@ func TestGoToDefinitionTypeReferenceDirective(t *testing.T) {
defer done()
f.VerifyBaselineGoToDefinition(t, true, "1")
}
+
+func TestGoToDefinitionLibReferenceDirective(t *testing.T) {
+ t.Parallel()
+ defer testutil.RecoverAndFail(t, "Panic on fourslash test")
+ const content = `// @Filename: /src/app.ts
+/// `
+ f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
+ defer done()
+ f.VerifyBaselineGoToDefinition(t, true, "start", "middle", "end")
+}
diff --git a/tsc/internal/ls/definition.go b/tsc/internal/ls/definition.go
index bb86c998257af..ffb3a8a97a22c 100644
--- a/tsc/internal/ls/definition.go
+++ b/tsc/internal/ls/definition.go
@@ -51,14 +51,13 @@ func (l *LanguageService) provideDefinitionAtPosition(ctx context.Context, progr
node := astnav.GetTouchingPropertyName(file, pos)
reference := getReferenceAtPosition(file, pos, program)
- if node.Kind == ast.KindSourceFile {
- return lsproto.LocationOrLocationsOrDefinitionLinksOrNull{}
- }
-
originSelectionRange, _ := l.createLspRangeFromNode(node, file)
if reference != nil && reference.file != nil {
return l.createDefinitionLocations(originSelectionRange, clientSupportsLink, []*ast.Node{}, reference, spanmap.FeatureDefinition)
}
+ if node.Kind == ast.KindSourceFile {
+ return lsproto.LocationOrLocationsOrDefinitionLinksOrNull{}
+ }
c, done := program.GetTypeCheckerForFile(ctx, file)
defer done()
diff --git a/tsc/testdata/baselines/reference/fourslash/goToDefinition/goToDefinitionLibReferenceDirective.baseline.jsonc b/tsc/testdata/baselines/reference/fourslash/goToDefinition/goToDefinitionLibReferenceDirective.baseline.jsonc
new file mode 100644
index 0000000000000..07e718205d129
--- /dev/null
+++ b/tsc/testdata/baselines/reference/fourslash/goToDefinition/goToDefinitionLibReferenceDirective.baseline.jsonc
@@ -0,0 +1,39 @@
+// === goToDefinition ===
+// === bundled:///libs/lib.es2025.d.ts ===
+// [||]/*! *****************************************************************************
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not use
+// this file except in compliance with the License. You may obtain a copy of the
+// --- (line: --) skipped ---
+//
+
+// === /src/app.ts ===
+// /// [||]
+
+
+
+// === goToDefinition ===
+// === bundled:///libs/lib.es2025.d.ts ===
+// [||]/*! *****************************************************************************
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not use
+// this file except in compliance with the License. You may obtain a copy of the
+// --- (line: --) skipped ---
+//
+
+// === /src/app.ts ===
+// /// [||]
+
+
+
+// === goToDefinition ===
+// === bundled:///libs/lib.es2025.d.ts ===
+// [||]/*! *****************************************************************************
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not use
+// this file except in compliance with the License. You may obtain a copy of the
+// --- (line: --) skipped ---
+//
+
+// === /src/app.ts ===
+// /// [||]
\ No newline at end of file
diff --git a/tsc/testdata/baselines/reference/fourslash/goToDefinition/goToDefinitionSourceUnit.baseline.jsonc b/tsc/testdata/baselines/reference/fourslash/goToDefinition/goToDefinitionSourceUnit.baseline.jsonc
index a1e48898c0b76..ce010c4c54876 100644
--- a/tsc/testdata/baselines/reference/fourslash/goToDefinition/goToDefinitionSourceUnit.baseline.jsonc
+++ b/tsc/testdata/baselines/reference/fourslash/goToDefinition/goToDefinitionSourceUnit.baseline.jsonc
@@ -11,12 +11,18 @@
// === goToDefinition ===
+// === /b.ts ===
+// [||]
+
// === /a.ts ===
// //MyFile Comments
// //more comments
// ///
// ///
//
-// class clsInOverload {
+// [|class clsInOverload {
// static fnOverload();
-// --- (line: 8) skipped ---
\ No newline at end of file
+// static fnOverload(foo: string);
+// static fnOverload(foo: any) { }
+// }
+// |]
\ No newline at end of file
diff --git a/tsc/testdata/baselines/reference/fourslash/goToDefinition/goToDefinitionTypeReferenceDirective.baseline.jsonc b/tsc/testdata/baselines/reference/fourslash/goToDefinition/goToDefinitionTypeReferenceDirective.baseline.jsonc
index 7899d3b35f156..b8723591b75fc 100644
--- a/tsc/testdata/baselines/reference/fourslash/goToDefinition/goToDefinitionTypeReferenceDirective.baseline.jsonc
+++ b/tsc/testdata/baselines/reference/fourslash/goToDefinition/goToDefinitionTypeReferenceDirective.baseline.jsonc
@@ -1,4 +1,7 @@
// === goToDefinition ===
+// === /src/types/lib/index.d.ts ===
+// [||]declare let $: {x: number};
+
// === /src/app.ts ===
// ///
-// $.x;
\ No newline at end of file
+// [|$.x;|]
\ No newline at end of file