Skip to content

Commit e0ca8a5

Browse files
author
Andy
authored
organizeImports: Fix bug in reference-testing for renamed import (#22797)
1 parent 54274a8 commit e0ca8a5

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

src/harness/unittests/organizeImports.ts

+10
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,16 @@ export const Other = 1;
197197
assert.isEmpty(changes);
198198
});
199199

200+
testOrganizeImports("Renamed_used",
201+
{
202+
path: "/test.ts",
203+
content: `
204+
import { F1 as EffOne, F2 as EffTwo } from "lib";
205+
EffOne();
206+
`,
207+
},
208+
libFile);
209+
200210
testOrganizeImports("Simple",
201211
{
202212
path: "/test.ts",

src/services/organizeImports.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ namespace ts.OrganizeImports {
9898
}
9999
else {
100100
// List of named imports
101-
const newElements = namedBindings.elements.filter(e => isDeclarationUsed(e.propertyName || e.name));
101+
const newElements = namedBindings.elements.filter(e => isDeclarationUsed(e.name));
102102
if (newElements.length < namedBindings.elements.length) {
103103
namedBindings = newElements.length
104104
? updateNamedImports(namedBindings, newElements)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// ==ORIGINAL==
2+
3+
import { F1 as EffOne, F2 as EffTwo } from "lib";
4+
EffOne();
5+
6+
// ==ORGANIZED==
7+
8+
import { F1 as EffOne } from "lib";
9+
EffOne();

0 commit comments

Comments
 (0)