Better reference usage detection
This commit is contained in:
parent
6bd298b884
commit
499bed540b
2 changed files with 6 additions and 4 deletions
|
@ -181,8 +181,8 @@ namespace ts.codefix {
|
||||||
|
|
||||||
function deleteAssignments(changes: textChanges.ChangeTracker, sourceFile: SourceFile, token: Identifier, checker: TypeChecker) {
|
function deleteAssignments(changes: textChanges.ChangeTracker, sourceFile: SourceFile, token: Identifier, checker: TypeChecker) {
|
||||||
FindAllReferences.Core.eachSymbolReferenceInFile(token, checker, sourceFile, (ref: Node) => {
|
FindAllReferences.Core.eachSymbolReferenceInFile(token, checker, sourceFile, (ref: Node) => {
|
||||||
if (ref.parent.kind === SyntaxKind.PropertyAccessExpression) ref = ref.parent;
|
if (isPropertyAccessExpression(ref.parent) && ref.parent.name === ref) ref = ref.parent;
|
||||||
if (ref.parent.kind === SyntaxKind.BinaryExpression && ref.parent.parent.kind === SyntaxKind.ExpressionStatement) {
|
if (isBinaryExpression(ref.parent) && isExpressionStatement(ref.parent.parent) && ref.parent.left === ref) {
|
||||||
changes.delete(sourceFile, ref.parent.parent);
|
changes.delete(sourceFile, ref.parent.parent);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -201,7 +201,7 @@ namespace ts.codefix {
|
||||||
function tryDeleteParameter(changes: textChanges.ChangeTracker, sourceFile: SourceFile, p: ParameterDeclaration, checker: TypeChecker, sourceFiles: ReadonlyArray<SourceFile>, isFixAll: boolean): void {
|
function tryDeleteParameter(changes: textChanges.ChangeTracker, sourceFile: SourceFile, p: ParameterDeclaration, checker: TypeChecker, sourceFiles: ReadonlyArray<SourceFile>, isFixAll: boolean): void {
|
||||||
if (mayDeleteParameter(p, checker, isFixAll)) {
|
if (mayDeleteParameter(p, checker, isFixAll)) {
|
||||||
if (p.modifiers && p.modifiers.length > 0
|
if (p.modifiers && p.modifiers.length > 0
|
||||||
&& (!isIdentifier(p.name) || FindAllReferences.Core.isSymbolReferencedInFile(p.name, checker, sourceFile))) {
|
&& (!isIdentifier(p.name) || FindAllReferences.Core.isSymbolReferencedInFile(p.name, checker, sourceFile))) {
|
||||||
p.modifiers.forEach(modifier => {
|
p.modifiers.forEach(modifier => {
|
||||||
changes.deleteModifier(sourceFile, modifier);
|
changes.deleteModifier(sourceFile, modifier);
|
||||||
});
|
});
|
||||||
|
|
|
@ -839,7 +839,9 @@ namespace ts.FindAllReferences.Core {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function eachSymbolReferenceInFile<T>(definition: Identifier, checker: TypeChecker, sourceFile: SourceFile, cb: (token: Identifier) => T): T | undefined {
|
export function eachSymbolReferenceInFile<T>(definition: Identifier, checker: TypeChecker, sourceFile: SourceFile, cb: (token: Identifier) => T): T | undefined {
|
||||||
const symbol = checker.getSymbolAtLocation(definition);
|
const symbol = isParameterPropertyDeclaration(definition.parent)
|
||||||
|
? first(checker.getSymbolsOfParameterPropertyDeclaration(definition.parent, definition.text))
|
||||||
|
: checker.getSymbolAtLocation(definition);
|
||||||
if (!symbol) return undefined;
|
if (!symbol) return undefined;
|
||||||
for (const token of getPossibleSymbolReferenceNodes(sourceFile, symbol.name)) {
|
for (const token of getPossibleSymbolReferenceNodes(sourceFile, symbol.name)) {
|
||||||
if (!isIdentifier(token) || token === definition || token.escapedText !== definition.escapedText) continue;
|
if (!isIdentifier(token) || token === definition || token.escapedText !== definition.escapedText) continue;
|
||||||
|
|
Loading…
Reference in a new issue