Don't assume that all symbols have declarations

...in Find All References.  For example, global `this` doesn't in
modules.

Part of #34404
This commit is contained in:
Andrew Casey 2019-10-22 15:00:30 -07:00
parent 1cbbe288ac
commit 590fd3f2a2
2 changed files with 9 additions and 1 deletions

View File

@ -584,7 +584,7 @@ namespace ts.FindAllReferences.Core {
}
function getReferencedSymbolsForModuleIfDeclaredBySourceFile(symbol: Symbol, program: Program, sourceFiles: readonly SourceFile[], cancellationToken: CancellationToken, options: Options, sourceFilesSet: ReadonlyMap<true>) {
const moduleSourceFile = symbol.flags & SymbolFlags.Module ? find(symbol.declarations, isSourceFile) : undefined;
const moduleSourceFile = (symbol.flags & SymbolFlags.Module) && symbol.declarations && find(symbol.declarations, isSourceFile);
if (!moduleSourceFile) return undefined;
const exportEquals = symbol.exports!.get(InternalSymbolName.ExportEquals);
// If !!exportEquals, we're about to add references to `import("mod")` anyway, so don't double-count them.

View File

@ -0,0 +1,8 @@
/// <reference path='fourslash.ts' />
// @noLib: true
////[|this|];
////export const c = 1;
const [glob] = test.ranges();
verify.referenceGroups(glob, undefined);