Skip to content

Commit 2b69b22

Browse files
Properly handle both special export forms when renaming (#36914)
* Properly handle both special export forms when renaming Fixes #36713 * Lint
1 parent 3bec9ad commit 2b69b22

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

src/compiler/utilities.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5009,6 +5009,14 @@ namespace ts {
50095009
return node.kind === SyntaxKind.PropertyAccessExpression || node.kind === SyntaxKind.ElementAccessExpression;
50105010
}
50115011

5012+
export function getNameOfAccessExpression(node: AccessExpression) {
5013+
if (node.kind === SyntaxKind.PropertyAccessExpression) {
5014+
return node.name;
5015+
}
5016+
Debug.assert(node.kind === SyntaxKind.ElementAccessExpression);
5017+
return node.argumentExpression;
5018+
}
5019+
50125020
export function isBundleFileTextLike(section: BundleFileSection): section is BundleFileTextLike {
50135021
switch (section.kind) {
50145022
case BundleFileSectionKind.Text:

src/services/importTracker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ namespace ts.FindAllReferences {
517517
return undefined;
518518
}
519519

520-
const sym = useLhsSymbol ? checker.getSymbolAtLocation(cast(node.left, isPropertyAccessExpression).name) : symbol;
520+
const sym = useLhsSymbol ? checker.getSymbolAtLocation(getNameOfAccessExpression(cast(node.left, isAccessExpression))) : symbol;
521521
// Better detection for GH#20803
522522
if (sym && !(checker.getMergedSymbol(sym.parent!).flags & SymbolFlags.Module)) {
523523
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!)}`);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/*====== /tests/cases/fourslash/Foo.js ======*/
2+
3+
let RENAME;
4+
module.exports = [|RENAME|];
5+
exports["foo"] = RENAME;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
///<reference path="fourslash.ts" />
2+
3+
// @allowNonTsExtensions: true
4+
// @Filename: Foo.js
5+
//// let a;
6+
//// module.exports = /**/a;
7+
//// exports["foo"] = a;
8+
9+
verify.baselineRename("", { });

0 commit comments

Comments
 (0)