mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-08 12:55:49 -05:00
Fix symbolCanBeReferencedAtTypeLocation for namespace that exports itself (#28295)
This commit is contained in:
@@ -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 {
|
||||
|
||||
9
tests/cases/fourslash/completionsRecursiveNamespace.ts
Normal file
9
tests/cases/fourslash/completionsRecursiveNamespace.ts
Normal 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 });
|
||||
Reference in New Issue
Block a user