Skip to content

Commit

Permalink
fix(49629): fix crash in find-all-refs when using module.exports/expo…
Browse files Browse the repository at this point in the history
…rt= with arrays/primitives (#50291)
  • Loading branch information
a-tarasyuk committed Aug 15, 2022
1 parent bc52ff6 commit 61d8a8d
Show file tree
Hide file tree
Showing 3 changed files with 522 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/services/importTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ namespace ts.FindAllReferences {
// Similarly, skip past the symbol for 'export ='
if (importedSymbol.escapedName === "export=") {
importedSymbol = getExportEqualsLocalSymbol(importedSymbol, checker);
if (importedSymbol === undefined) return undefined;
}

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

function getExportEqualsLocalSymbol(importedSymbol: Symbol, checker: TypeChecker): Symbol {
function getExportEqualsLocalSymbol(importedSymbol: Symbol, checker: TypeChecker): Symbol | undefined {
if (importedSymbol.flags & SymbolFlags.Alias) {
return Debug.checkDefined(checker.getImmediateAliasedSymbol(importedSymbol));
return checker.getImmediateAliasedSymbol(importedSymbol);
}

const decl = Debug.checkDefined(importedSymbol.valueDeclaration);
if (isExportAssignment(decl)) { // `export = class {}`
return Debug.checkDefined(decl.expression.symbol);
return decl.expression.symbol;
}
else if (isBinaryExpression(decl)) { // `module.exports = class {}`
return Debug.checkDefined(decl.right.symbol);
return decl.right.symbol;
}
else if (isSourceFile(decl)) { // json module
return Debug.checkDefined(decl.symbol);
return decl.symbol;
}
return Debug.fail();
return undefined;
}

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

0 comments on commit 61d8a8d

Please sign in to comment.