mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-08 12:55:49 -05:00
Fix bug: isSymbolReferencedInFile should return true for shorthand property assignment (#23314)
* Fix bug: isSymbolReferencedInFile should return true for shorthand property assignment * Also test for export specifier
This commit is contained in:
@@ -247,6 +247,24 @@ import D from "lib";
|
||||
},
|
||||
libFile);
|
||||
|
||||
testOrganizeImports("Unused_false_positive_shorthand_assignment",
|
||||
{
|
||||
path: "/test.ts",
|
||||
content: `
|
||||
import { x } from "a";
|
||||
const o = { x };
|
||||
`
|
||||
});
|
||||
|
||||
testOrganizeImports("Unused_false_positive_export_shorthand",
|
||||
{
|
||||
path: "/test.ts",
|
||||
content: `
|
||||
import { x } from "a";
|
||||
export { x };
|
||||
`
|
||||
});
|
||||
|
||||
testOrganizeImports("MoveToTop",
|
||||
{
|
||||
path: "/test.ts",
|
||||
|
||||
@@ -708,7 +708,11 @@ namespace ts.FindAllReferences.Core {
|
||||
if (!symbol) return true; // Be lenient with invalid code.
|
||||
return getPossibleSymbolReferencePositions(sourceFile, symbol.name).some(position => {
|
||||
const token = tryCast(getTouchingPropertyName(sourceFile, position, /*includeJsDocComment*/ true), isIdentifier);
|
||||
return token && token !== definition && token.escapedText === definition.escapedText && checker.getSymbolAtLocation(token) === symbol;
|
||||
if (!token || token === definition || token.escapedText !== definition.escapedText) return false;
|
||||
const referenceSymbol = checker.getSymbolAtLocation(token);
|
||||
return referenceSymbol === symbol
|
||||
|| checker.getShorthandAssignmentValueSymbol(token.parent) === symbol
|
||||
|| isExportSpecifier(token.parent) && getLocalSymbolForExportSpecifier(token, referenceSymbol, token.parent, checker) === symbol;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user