Skip to content

Commit

Permalink
organizeImports: Fix bug in reference-testing for renamed import (#22797
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Andy committed Mar 22, 2018
1 parent a807336 commit a9fccb2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/harness/unittests/organizeImports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,16 @@ export const Other = 1;
assert.isEmpty(changes);
});

testOrganizeImports("Renamed_used",
{
path: "/test.ts",
content: `
import { F1 as EffOne, F2 as EffTwo } from "lib";
EffOne();
`,
},
libFile);

testOrganizeImports("Simple",
{
path: "/test.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/services/organizeImports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ namespace ts.OrganizeImports {
}
else {
// List of named imports
const newElements = namedBindings.elements.filter(e => isDeclarationUsed(e.propertyName || e.name));
const newElements = namedBindings.elements.filter(e => isDeclarationUsed(e.name));
if (newElements.length < namedBindings.elements.length) {
namedBindings = newElements.length
? updateNamedImports(namedBindings, newElements)
Expand Down
9 changes: 9 additions & 0 deletions tests/baselines/reference/organizeImports/Renamed_used.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// ==ORIGINAL==

import { F1 as EffOne, F2 as EffTwo } from "lib";
EffOne();

// ==ORGANIZED==

import { F1 as EffOne } from "lib";
EffOne();

0 comments on commit a9fccb2

Please sign in to comment.