Skip to content

Fix symbolCanBeReferencedAtTypeLocation for namespace that exports itself #28295

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
1 commit merged into from
Nov 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 7 additions & 17 deletions src/services/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 9 additions & 0 deletions tests/cases/fourslash/completionsRecursiveNamespace.ts
Original file line number Diff line number Diff line change
@@ -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 });