Skip to content

Commit af2b127

Browse files
author
Andy Hanson
committed
Fix symbolCanBeReferencedAtTypeLocation for namespace that exports itself
1 parent deeee77 commit af2b127

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

src/services/completions.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,23 +1128,13 @@ namespace ts.Completions {
11281128
return false;
11291129
}
11301130

1131-
function symbolCanBeReferencedAtTypeLocation(symbol: Symbol): boolean {
1132-
symbol = symbol.exportSymbol || symbol;
1133-
1134-
// This is an alias, follow what it aliases
1135-
symbol = skipAlias(symbol, typeChecker);
1136-
1137-
if (symbol.flags & SymbolFlags.Type) {
1138-
return true;
1139-
}
1140-
1141-
if (symbol.flags & SymbolFlags.Module) {
1142-
const exportedSymbols = typeChecker.getExportsOfModule(symbol);
1143-
// If the exported symbols contains type,
1144-
// symbol can be referenced at locations where type is allowed
1145-
return exportedSymbols.some(symbolCanBeReferencedAtTypeLocation);
1146-
}
1147-
return false;
1131+
/** True if symbol is a type or a module containing at least one type. */
1132+
function symbolCanBeReferencedAtTypeLocation(symbol: Symbol, seenModules = createMap<true>()): boolean {
1133+
const sym = skipAlias(symbol.exportSymbol || symbol, typeChecker);
1134+
return !!(sym.flags & SymbolFlags.Type) ||
1135+
!!(sym.flags & SymbolFlags.Module) &&
1136+
addToSeen(seenModules, getSymbolId(sym)) &&
1137+
typeChecker.getExportsOfModule(sym).some(e => symbolCanBeReferencedAtTypeLocation(e, seenModules));
11481138
}
11491139

11501140
function getSymbolsFromOtherSourceFileExports(symbols: Symbol[], tokenText: string, target: ScriptTarget): void {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
////declare namespace N {
4+
//// export import M = N;
5+
////}
6+
////type T = N./**/
7+
8+
// Previously this would crash in `symbolCanBeReferencedAtTypeLocation` due to the namespace exporting itself.
9+
verify.completions({ marker: "", exact: undefined });

0 commit comments

Comments
 (0)