Skip to content

Commit 61d8a8d

Browse files
authored
fix(49629): fix crash in find-all-refs when using module.exports/export= with arrays/primitives (#50291)
1 parent bc52ff6 commit 61d8a8d

File tree

3 files changed

+522
-6
lines changed

3 files changed

+522
-6
lines changed

src/services/importTracker.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@ namespace ts.FindAllReferences {
555555
// Similarly, skip past the symbol for 'export ='
556556
if (importedSymbol.escapedName === "export=") {
557557
importedSymbol = getExportEqualsLocalSymbol(importedSymbol, checker);
558+
if (importedSymbol === undefined) return undefined;
558559
}
559560

560561
// If the import has a different name than the export, do not continue searching.
@@ -577,22 +578,22 @@ namespace ts.FindAllReferences {
577578
}
578579
}
579580

580-
function getExportEqualsLocalSymbol(importedSymbol: Symbol, checker: TypeChecker): Symbol {
581+
function getExportEqualsLocalSymbol(importedSymbol: Symbol, checker: TypeChecker): Symbol | undefined {
581582
if (importedSymbol.flags & SymbolFlags.Alias) {
582-
return Debug.checkDefined(checker.getImmediateAliasedSymbol(importedSymbol));
583+
return checker.getImmediateAliasedSymbol(importedSymbol);
583584
}
584585

585586
const decl = Debug.checkDefined(importedSymbol.valueDeclaration);
586587
if (isExportAssignment(decl)) { // `export = class {}`
587-
return Debug.checkDefined(decl.expression.symbol);
588+
return decl.expression.symbol;
588589
}
589590
else if (isBinaryExpression(decl)) { // `module.exports = class {}`
590-
return Debug.checkDefined(decl.right.symbol);
591+
return decl.right.symbol;
591592
}
592593
else if (isSourceFile(decl)) { // json module
593-
return Debug.checkDefined(decl.symbol);
594+
return decl.symbol;
594595
}
595-
return Debug.fail();
596+
return undefined;
596597
}
597598

598599
// If a reference is a class expression, the exported node would be its parent.

0 commit comments

Comments
 (0)