Assert exportingModuleSymbol is defined (#21340)

* Assert `exportingModuleSymbol` is defined

* Add assert message

* Add message in both places
This commit is contained in:
Andy
2018-02-02 10:49:34 -08:00
committed by GitHub
parent b3ec8cce00
commit 78f217bdd6
3 changed files with 7 additions and 3 deletions

View File

@@ -2882,6 +2882,11 @@ namespace ts {
throw e;
}
export function assertDefined<T>(value: T | null | undefined, message?: string): T {
assert(value !== undefined && value !== null, message);
return value;
}
export function assertNever(member: never, message?: string, stackCrawlMark?: AnyFunction): never {
return fail(message || `Illegal value: ${member}`, stackCrawlMark || assertNever);
}

View File

@@ -366,7 +366,7 @@ namespace ts.FindAllReferences.Core {
if (node.kind === SyntaxKind.DefaultKeyword) {
addReference(node, symbol, node, state);
searchForImportsOfExport(node, symbol, { exportingModuleSymbol: symbol.parent, exportKind: ExportKind.Default }, state);
searchForImportsOfExport(node, symbol, { exportingModuleSymbol: Debug.assertDefined(symbol.parent, "Expected export symbol to have a parent"), exportKind: ExportKind.Default }, state);
}
else {
const search = state.createSearch(node, symbol, /*comingFrom*/ undefined, { allSearchSymbols: populateSearchSymbolSet(symbol, node, checker, options.implementations) });

View File

@@ -491,8 +491,7 @@ namespace ts.FindAllReferences {
function getExportAssignmentExport(ex: ExportAssignment): ExportedSymbol {
// Get the symbol for the `export =` node; its parent is the module it's the export of.
const exportingModuleSymbol = ex.symbol.parent;
Debug.assert(!!exportingModuleSymbol);
const exportingModuleSymbol = Debug.assertDefined(ex.symbol.parent, "Expected export symbol to have a parent");
const exportKind = ex.isExportEquals ? ExportKind.ExportEquals : ExportKind.Default;
return { kind: ImportExport.Export, symbol, exportInfo: { exportingModuleSymbol, exportKind } };
}