Properly handle both special export forms when renaming (#36914)

* Properly handle both special export forms when renaming

Fixes #36713

* Lint
This commit is contained in:
Ryan Cavanaugh 2020-02-24 13:17:02 -08:00 committed by GitHub
parent 3bec9ad2c5
commit 2b69b2281a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 1 deletions

View File

@ -5009,6 +5009,14 @@ namespace ts {
return node.kind === SyntaxKind.PropertyAccessExpression || node.kind === SyntaxKind.ElementAccessExpression;
}
export function getNameOfAccessExpression(node: AccessExpression) {
if (node.kind === SyntaxKind.PropertyAccessExpression) {
return node.name;
}
Debug.assert(node.kind === SyntaxKind.ElementAccessExpression);
return node.argumentExpression;
}
export function isBundleFileTextLike(section: BundleFileSection): section is BundleFileTextLike {
switch (section.kind) {
case BundleFileSectionKind.Text:

View File

@ -517,7 +517,7 @@ namespace ts.FindAllReferences {
return undefined;
}
const sym = useLhsSymbol ? checker.getSymbolAtLocation(cast(node.left, isPropertyAccessExpression).name) : symbol;
const sym = useLhsSymbol ? checker.getSymbolAtLocation(getNameOfAccessExpression(cast(node.left, isAccessExpression))) : symbol;
// Better detection for GH#20803
if (sym && !(checker.getMergedSymbol(sym.parent!).flags & SymbolFlags.Module)) {
Debug.fail(`Special property assignment kind does not have a module as its parent. Assignment is ${Debug.formatSymbol(sym)}, parent is ${Debug.formatSymbol(sym.parent!)}`);

View File

@ -0,0 +1,5 @@
/*====== /tests/cases/fourslash/Foo.js ======*/
let RENAME;
module.exports = [|RENAME|];
exports["foo"] = RENAME;

View File

@ -0,0 +1,9 @@
///<reference path="fourslash.ts" />
// @allowNonTsExtensions: true
// @Filename: Foo.js
//// let a;
//// module.exports = /**/a;
//// exports["foo"] = a;
verify.baselineRename("", { });