Handles different references and renames involved with import export and import type node (#34813)

* Test

* Handle import type node when handling the namespace import and reexport
Fixes #33017

* Handle qualifier of the importTypeNode

* Handle export specifier

* Fix rename prefix when search for rename starts at qualifier in import type ndoe

* Fix rename of qualifier with importType node when invoked without provideSuffixAndPrefix option
This commit is contained in:
Sheetal Nandi
2019-12-11 15:11:27 -08:00
committed by GitHub
parent fc0f67dcfd
commit 1fd1b429f0
6 changed files with 70 additions and 9 deletions

View File

@@ -380,7 +380,10 @@ namespace ts.FindAllReferences {
return contains(originalSymbol!.declarations, entry.node.parent) ? { prefixText: name + " as " } : emptyOptions;
}
else if (isExportSpecifier(entry.node.parent) && !entry.node.parent.propertyName) {
return originalNode === entry.node ? { prefixText: name + " as " } : { suffixText: " as " + name };
// If the symbol for the node is same as declared node symbol use prefix text
return originalNode === entry.node || checker.getSymbolAtLocation(originalNode) === checker.getSymbolAtLocation(entry.node) ?
{ prefixText: name + " as " } :
{ suffixText: " as " + name };
}
}
@@ -758,7 +761,6 @@ namespace ts.FindAllReferences {
// Compute the meaning from the location and the symbol it references
const searchMeaning = node ? getIntersectingMeaningFromDeclarations(node, symbol) : SemanticMeaning.All;
const result: SymbolAndEntries[] = [];
const state = new State(sourceFiles, sourceFilesSet, node ? getSpecialSearchKind(node) : SpecialSearchKind.None, checker, cancellationToken, searchMeaning, options, result);
@@ -1894,6 +1896,13 @@ namespace ts.FindAllReferences {
return fromRoot(symbol.flags & SymbolFlags.FunctionScopedVariable ? paramProps[1] : paramProps[0]);
}
const exportSpecifier = getDeclarationOfKind<ExportSpecifier>(symbol, SyntaxKind.ExportSpecifier);
const localSymbol = exportSpecifier && checker.getExportSpecifierLocalTargetSymbol(exportSpecifier);
if (localSymbol) {
const res = cbSymbol(localSymbol, /*rootSymbol*/ undefined, /*baseSymbol*/ undefined, EntryKind.Node);
if (res) return res;
}
// symbolAtLocation for a binding element is the local symbol. See if the search symbol is the property.
// Don't do this when populating search set for a rename when prefix and suffix text will be provided -- just rename the local.
if (!isForRenamePopulateSearchSymbolSet) {

View File

@@ -176,7 +176,9 @@ namespace ts.FindAllReferences {
const directImports = getDirectImports(moduleSymbol);
if (directImports) {
for (const directImport of directImports) {
addIndirectUsers(getSourceFileLikeForImportDeclaration(directImport));
if (!isImportTypeNode(directImport)) {
addIndirectUsers(getSourceFileLikeForImportDeclaration(directImport));
}
}
}
}
@@ -221,8 +223,9 @@ namespace ts.FindAllReferences {
if (decl.kind === SyntaxKind.ImportType) {
if (decl.qualifier) {
if (isIdentifier(decl.qualifier) && decl.qualifier.escapedText === symbolName(exportSymbol)) {
singleReferences.push(decl.qualifier);
const firstIdentifier = getFirstIdentifier(decl.qualifier);
if (firstIdentifier.escapedText === symbolName(exportSymbol)) {
singleReferences.push(firstIdentifier);
}
}
else if (exportKind === ExportKind.ExportEquals) {