Skip to content

Commit 8463b1e

Browse files
author
Andy
authored
Fix bug: don't call addIndirectUser if we're not tracking indirect users (#22121)
1 parent d9bcee4 commit 8463b1e

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

src/services/importTracker.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ namespace ts.FindAllReferences {
109109
}
110110
else if (isDefaultImport(direct)) {
111111
const sourceFileLike = getSourceFileLikeForImportDeclaration(direct);
112-
addIndirectUser(sourceFileLike); // Add a check for indirect uses to handle synthetic default imports
112+
if (!isAvailableThroughGlobal) {
113+
addIndirectUser(sourceFileLike); // Add a check for indirect uses to handle synthetic default imports
114+
}
113115
directImports.push(direct);
114116
}
115117
else {
@@ -651,8 +653,8 @@ namespace ts.FindAllReferences {
651653
if (parent.kind === SyntaxKind.SourceFile) {
652654
return parent as SourceFile;
653655
}
654-
Debug.assert(parent.kind === SyntaxKind.ModuleBlock && isAmbientModuleDeclaration(parent.parent));
655-
return parent.parent as AmbientModuleDeclaration;
656+
Debug.assert(parent.kind === SyntaxKind.ModuleBlock);
657+
return cast(parent.parent, isAmbientModuleDeclaration);
656658
}
657659

658660
function isAmbientModuleDeclaration(node: Node): node is AmbientModuleDeclaration {
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/// <reference path="fourslash.ts"/>
2+
13
// @esModuleInterop: true
24

35
// @Filename: /abc.d.ts
@@ -6,7 +8,7 @@
68
////}
79

810
// @Filename: /b.ts
9-
////import * as a from "a";
11+
////import a from "a";
1012
////a.[|x|];
1113

1214
verify.rangesReferenceEachOther();
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
// Tests that we don't always add an indirect user, which causes problems if the module is already available globally.
4+
5+
// @esModuleInterop: true
6+
7+
// @Filename: /a.d.ts
8+
////export as namespace abc;
9+
////export const [|x|]: number;
10+
11+
// @Filename: /b.ts
12+
////import a from "./a";
13+
////a.[|x|];
14+
15+
verify.rangesReferenceEachOther();

0 commit comments

Comments
 (0)