Skip to content

Commit 78f217b

Browse files
author
Andy
authored
Assert exportingModuleSymbol is defined (#21340)
* Assert `exportingModuleSymbol` is defined * Add assert message * Add message in both places
1 parent b3ec8cc commit 78f217b

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

src/compiler/core.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2882,6 +2882,11 @@ namespace ts {
28822882
throw e;
28832883
}
28842884

2885+
export function assertDefined<T>(value: T | null | undefined, message?: string): T {
2886+
assert(value !== undefined && value !== null, message);
2887+
return value;
2888+
}
2889+
28852890
export function assertNever(member: never, message?: string, stackCrawlMark?: AnyFunction): never {
28862891
return fail(message || `Illegal value: ${member}`, stackCrawlMark || assertNever);
28872892
}

src/services/findAllReferences.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ namespace ts.FindAllReferences.Core {
366366

367367
if (node.kind === SyntaxKind.DefaultKeyword) {
368368
addReference(node, symbol, node, state);
369-
searchForImportsOfExport(node, symbol, { exportingModuleSymbol: symbol.parent, exportKind: ExportKind.Default }, state);
369+
searchForImportsOfExport(node, symbol, { exportingModuleSymbol: Debug.assertDefined(symbol.parent, "Expected export symbol to have a parent"), exportKind: ExportKind.Default }, state);
370370
}
371371
else {
372372
const search = state.createSearch(node, symbol, /*comingFrom*/ undefined, { allSearchSymbols: populateSearchSymbolSet(symbol, node, checker, options.implementations) });

src/services/importTracker.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,7 @@ namespace ts.FindAllReferences {
491491

492492
function getExportAssignmentExport(ex: ExportAssignment): ExportedSymbol {
493493
// Get the symbol for the `export =` node; its parent is the module it's the export of.
494-
const exportingModuleSymbol = ex.symbol.parent;
495-
Debug.assert(!!exportingModuleSymbol);
494+
const exportingModuleSymbol = Debug.assertDefined(ex.symbol.parent, "Expected export symbol to have a parent");
496495
const exportKind = ex.isExportEquals ? ExportKind.ExportEquals : ExportKind.Default;
497496
return { kind: ImportExport.Export, symbol, exportInfo: { exportingModuleSymbol, exportKind } };
498497
}

0 commit comments

Comments
 (0)