Fix symbolCanBeReferencedAtTypeLocation for namespace that exports itself (#28295)

This commit is contained in:
Andy
2018-11-01 15:10:21 -07:00
committed by GitHub
parent 901476fae3
commit eabbaa415f
2 changed files with 16 additions and 17 deletions

View File

@@ -1128,23 +1128,13 @@ namespace ts.Completions {
return false;
}
function symbolCanBeReferencedAtTypeLocation(symbol: Symbol): boolean {
symbol = symbol.exportSymbol || symbol;
// This is an alias, follow what it aliases
symbol = skipAlias(symbol, typeChecker);
if (symbol.flags & SymbolFlags.Type) {
return true;
}
if (symbol.flags & SymbolFlags.Module) {
const exportedSymbols = typeChecker.getExportsOfModule(symbol);
// If the exported symbols contains type,
// symbol can be referenced at locations where type is allowed
return exportedSymbols.some(symbolCanBeReferencedAtTypeLocation);
}
return false;
/** True if symbol is a type or a module containing at least one type. */
function symbolCanBeReferencedAtTypeLocation(symbol: Symbol, seenModules = createMap<true>()): boolean {
const sym = skipAlias(symbol.exportSymbol || symbol, typeChecker);
return !!(sym.flags & SymbolFlags.Type) ||
!!(sym.flags & SymbolFlags.Module) &&
addToSeen(seenModules, getSymbolId(sym)) &&
typeChecker.getExportsOfModule(sym).some(e => symbolCanBeReferencedAtTypeLocation(e, seenModules));
}
function getSymbolsFromOtherSourceFileExports(symbols: Symbol[], tokenText: string, target: ScriptTarget): void {

View File

@@ -0,0 +1,9 @@
/// <reference path='fourslash.ts'/>
////declare namespace N {
//// export import M = N;
////}
////type T = N./**/
// Previously this would crash in `symbolCanBeReferencedAtTypeLocation` due to the namespace exporting itself.
verify.completions({ marker: "", exact: undefined });