Fix sending correct symbol when using commonjs require and destructuring (#43511)

* Fix sending correct symbol when using commonjs require and destructuring

* Check BindingElement
This commit is contained in:
Armando Aguirre
2021-04-13 15:06:34 -07:00
committed by GitHub
parent 6002cff776
commit 5a6a499d0e
3 changed files with 110 additions and 1 deletions

View File

@@ -1477,7 +1477,7 @@ namespace ts.FindAllReferences {
if (!hasMatchingMeaning(referenceLocation, state)) return;
const referenceSymbol = state.checker.getSymbolAtLocation(referenceLocation);
let referenceSymbol = state.checker.getSymbolAtLocation(referenceLocation);
if (!referenceSymbol) {
return;
}
@@ -1514,6 +1514,11 @@ namespace ts.FindAllReferences {
Debug.assertNever(state.specialSearchKind);
}
// Use the parent symbol if the location is commonjs require syntax on javascript files only.
referenceSymbol = isInJSFile(referenceLocation) && referenceLocation.parent.kind === SyntaxKind.BindingElement && isRequireVariableDeclaration(referenceLocation.parent)
? referenceLocation.parent.symbol
: referenceSymbol;
getImportOrExportReferences(referenceLocation, referenceSymbol, search, state);
}