Revert "Handle indexed access types in getSymbolAtLocation and findAllReferences (#17787)" (#18111)

This reverts commit 30b3cb0f68.
This commit is contained in:
Andy
2017-08-29 09:37:27 -07:00
committed by GitHub
parent 7306b13f74
commit 9daa70c47e
5 changed files with 30 additions and 60 deletions

View File

@@ -22931,7 +22931,7 @@ namespace ts {
return undefined;
}
function getSymbolAtLocation(node: Node): Symbol | undefined {
function getSymbolAtLocation(node: Node) {
if (node.kind === SyntaxKind.SourceFile) {
return isExternalModule(<SourceFile>node) ? getMergedSymbol(node.symbol) : undefined;
}
@@ -23009,21 +23009,9 @@ namespace ts {
case SyntaxKind.NumericLiteral:
// index access
switch (node.parent.kind) {
case SyntaxKind.ElementAccessExpression: {
if ((<ElementAccessExpression>node.parent).argumentExpression !== node) {
return undefined;
}
const objectType = getTypeOfExpression((<ElementAccessExpression>node.parent).expression);
return getPropertyOfType(objectType, (<NumericLiteral>node).text as __String);
}
case SyntaxKind.LiteralType: {
if (!isIndexedAccessTypeNode(node.parent.parent)) {
return undefined;
}
const objectType = getTypeFromTypeNode(node.parent.parent.objectType);
return getPropertyOfType(objectType, escapeLeadingUnderscores((node as StringLiteral | NumericLiteral).text));
}
if (node.parent.kind === SyntaxKind.ElementAccessExpression && (<ElementAccessExpression>node.parent).argumentExpression === node) {
const objectType = getTypeOfExpression((<ElementAccessExpression>node.parent).expression);
return getPropertyOfType(objectType, (<NumericLiteral>node).text as __String);
}
break;
}

View File

@@ -748,11 +748,11 @@ namespace ts.FindAllReferences.Core {
return (node as Identifier).text.length === searchSymbolName.length;
case SyntaxKind.StringLiteral:
return (isLiteralNameOfPropertyDeclarationOrIndexAccess(node as StringLiteral) || isNameOfExternalModuleImportOrDeclaration(node)) &&
return (isLiteralNameOfPropertyDeclarationOrIndexAccess(node) || isNameOfExternalModuleImportOrDeclaration(node)) &&
(node as StringLiteral).text.length === searchSymbolName.length;
case SyntaxKind.NumericLiteral:
return isLiteralNameOfPropertyDeclarationOrIndexAccess(node as NumericLiteral) && (node as NumericLiteral).text.length === searchSymbolName.length;
return isLiteralNameOfPropertyDeclarationOrIndexAccess(node) && (node as NumericLiteral).text.length === searchSymbolName.length;
default:
return false;

View File

@@ -89,15 +89,9 @@ namespace ts.Rename {
}
function nodeIsEligibleForRename(node: Node): boolean {
switch (node.kind) {
case SyntaxKind.Identifier:
case SyntaxKind.StringLiteral:
case SyntaxKind.ThisKeyword:
return true;
case SyntaxKind.NumericLiteral:
return isLiteralNameOfPropertyDeclarationOrIndexAccess(node as NumericLiteral);
default:
return false;
}
return node.kind === ts.SyntaxKind.Identifier ||
node.kind === SyntaxKind.StringLiteral ||
isLiteralNameOfPropertyDeclarationOrIndexAccess(node) ||
isThis(node);
}
}

View File

@@ -244,25 +244,27 @@ namespace ts {
isFunctionLike(node.parent) && (<FunctionLikeDeclaration>node.parent).name === node;
}
export function isLiteralNameOfPropertyDeclarationOrIndexAccess(node: StringLiteral | NumericLiteral): boolean {
switch (node.parent.kind) {
case SyntaxKind.PropertyDeclaration:
case SyntaxKind.PropertySignature:
case SyntaxKind.PropertyAssignment:
case SyntaxKind.EnumMember:
case SyntaxKind.MethodDeclaration:
case SyntaxKind.MethodSignature:
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
case SyntaxKind.ModuleDeclaration:
return getNameOfDeclaration(<Declaration>node.parent) === node;
case SyntaxKind.ElementAccessExpression:
return (<ElementAccessExpression>node.parent).argumentExpression === node;
case SyntaxKind.ComputedPropertyName:
return true;
case SyntaxKind.LiteralType:
return node.parent.parent.kind === SyntaxKind.IndexedAccessType;
export function isLiteralNameOfPropertyDeclarationOrIndexAccess(node: Node): boolean {
if (node.kind === SyntaxKind.StringLiteral || node.kind === SyntaxKind.NumericLiteral) {
switch (node.parent.kind) {
case SyntaxKind.PropertyDeclaration:
case SyntaxKind.PropertySignature:
case SyntaxKind.PropertyAssignment:
case SyntaxKind.EnumMember:
case SyntaxKind.MethodDeclaration:
case SyntaxKind.MethodSignature:
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
case SyntaxKind.ModuleDeclaration:
return getNameOfDeclaration(<Declaration>node.parent) === node;
case SyntaxKind.ElementAccessExpression:
return (<ElementAccessExpression>node.parent).argumentExpression === node;
case SyntaxKind.ComputedPropertyName:
return true;
}
}
return false;
}
export function isExpressionOfExternalModuleImportEqualsDeclaration(node: Node) {