From f7ca43917fe4739a0f48d8ea74a3904864aa5945 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 8 Apr 2016 10:19:02 -0700 Subject: [PATCH] Handle the rename locations for default import Handles #7024 --- src/services/services.ts | 11 +++++---- tests/cases/fourslash/renameDefaultImport.ts | 19 +++++++++++++++ .../renameDefaultImportDifferentName.ts | 23 +++++++++++++++++++ 3 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 tests/cases/fourslash/renameDefaultImport.ts create mode 100644 tests/cases/fourslash/renameDefaultImportDifferentName.ts diff --git a/src/services/services.ts b/src/services/services.ts index 2d27516956e..cb062a0fc9f 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -6116,15 +6116,18 @@ namespace ts { // If the symbol is an alias, add what it aliases to the list // import {a} from "mod"; // export {a} + // If the symbol is an alias to default declaration, add what it aliases to the list + // declare "mod" { export default class B { } } + // import B from "mod"; //// For export specifiers, the exported name can be referring to a local symbol, e.g.: //// import {a} from "mod"; //// export {a as somethingElse} //// We want the *local* declaration of 'a' as declared in the import, //// *not* as declared within "mod" (or farther) const importOrExportSpecifier = getImportOrExportSpecifierPropertyNameSymbolSpecifier(symbol, location); - if (importOrExportSpecifier) { + if (importOrExportSpecifier || getDeclarationOfKind(symbol, SyntaxKind.ImportClause)) { result = result.concat(populateSearchSymbolSet( - importOrExportSpecifier.kind === SyntaxKind.ImportSpecifier ? + !importOrExportSpecifier || importOrExportSpecifier.kind === SyntaxKind.ImportSpecifier ? typeChecker.getAliasedSymbol(symbol) : typeChecker.getExportSpecifierLocalTargetSymbol(importOrExportSpecifier), location)); } @@ -6253,8 +6256,8 @@ namespace ts { // If the reference symbol is an alias, check if what it is aliasing is one of the search // symbols but by looking up for related symbol of this alias so it can handle multiple level of indirectness. const importOrExportSpecifier = getImportOrExportSpecifierPropertyNameSymbolSpecifier(referenceSymbol, referenceLocation); - if (importOrExportSpecifier) { - const aliasedSymbol = importOrExportSpecifier.kind === SyntaxKind.ImportSpecifier ? + if (importOrExportSpecifier || getDeclarationOfKind(referenceSymbol, SyntaxKind.ImportClause)) { + const aliasedSymbol = !importOrExportSpecifier || importOrExportSpecifier.kind === SyntaxKind.ImportSpecifier ? typeChecker.getAliasedSymbol(referenceSymbol) : typeChecker.getExportSpecifierLocalTargetSymbol(importOrExportSpecifier); return getRelatedSymbol(searchSymbols, aliasedSymbol, referenceLocation); diff --git a/tests/cases/fourslash/renameDefaultImport.ts b/tests/cases/fourslash/renameDefaultImport.ts new file mode 100644 index 00000000000..fd9534e65f7 --- /dev/null +++ b/tests/cases/fourslash/renameDefaultImport.ts @@ -0,0 +1,19 @@ +/// + +// @Filename: B.ts +////export default class [|B|] { +//// test() { +//// } +////} + +// @Filename: A.ts +////import [|B|] from "./B"; +////let b = new [|B|](); +////b.test(); + +let ranges = test.ranges() +for (let range of ranges) { + goTo.file(range.fileName); + goTo.position(range.start); + verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false); +} diff --git a/tests/cases/fourslash/renameDefaultImportDifferentName.ts b/tests/cases/fourslash/renameDefaultImportDifferentName.ts new file mode 100644 index 00000000000..5965f1a63e9 --- /dev/null +++ b/tests/cases/fourslash/renameDefaultImportDifferentName.ts @@ -0,0 +1,23 @@ +/// + +// @Filename: B.ts +////export default class /*1*/C { +//// test() { +//// } +////} + +// @Filename: A.ts +////import [|B|] from "./B"; +////let b = new [|B|](); +////b.test(); + +goTo.file("B.ts"); +goTo.marker("1"); +verify.occurrencesAtPositionCount(1); + +goTo.file("A.ts"); +let ranges = test.ranges() +for (let range of ranges) { + goTo.position(range.start); + verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false); +}