Skip to content

Properly handle both special export forms when renaming #36914

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/services/importTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!)}`);
Expand Down
5 changes: 5 additions & 0 deletions tests/baselines/reference/renameExportCrash.baseline
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/*====== /tests/cases/fourslash/Foo.js ======*/

let RENAME;
module.exports = [|RENAME|];
exports["foo"] = RENAME;
9 changes: 9 additions & 0 deletions tests/cases/fourslash/renameExportCrash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
///<reference path="fourslash.ts" />

// @allowNonTsExtensions: true
// @Filename: Foo.js
//// let a;
//// module.exports = /**/a;
//// exports["foo"] = a;

verify.baselineRename("", { });