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:
parent
d36f83a98d
commit
edcf087145
|
@ -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;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
// ==ORIGINAL==
|
||||
|
||||
import { x } from "a";
|
||||
export { x };
|
||||
|
||||
// ==ORGANIZED==
|
||||
|
||||
import { x } from "a";
|
||||
export { x };
|
|
@ -0,0 +1,9 @@
|
|||
// ==ORIGINAL==
|
||||
|
||||
import { x } from "a";
|
||||
const o = { x };
|
||||
|
||||
// ==ORGANIZED==
|
||||
|
||||
import { x } from "a";
|
||||
const o = { x };
|
Loading…
Reference in a new issue