From e0ca8a5f39fef5c054c885adcff4ffefb3e1680d Mon Sep 17 00:00:00 2001 From: Andy Date: Thu, 22 Mar 2018 13:08:58 -0700 Subject: [PATCH] organizeImports: Fix bug in reference-testing for renamed import (#22797) --- src/harness/unittests/organizeImports.ts | 10 ++++++++++ src/services/organizeImports.ts | 2 +- .../reference/organizeImports/Renamed_used.ts | 9 +++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/organizeImports/Renamed_used.ts diff --git a/src/harness/unittests/organizeImports.ts b/src/harness/unittests/organizeImports.ts index de4a4722d67dc..044fee1367cfd 100644 --- a/src/harness/unittests/organizeImports.ts +++ b/src/harness/unittests/organizeImports.ts @@ -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", diff --git a/src/services/organizeImports.ts b/src/services/organizeImports.ts index f6489fce6d208..b4999e968fbda 100644 --- a/src/services/organizeImports.ts +++ b/src/services/organizeImports.ts @@ -98,7 +98,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) diff --git a/tests/baselines/reference/organizeImports/Renamed_used.ts b/tests/baselines/reference/organizeImports/Renamed_used.ts new file mode 100644 index 0000000000000..5e9395e9ef5fb --- /dev/null +++ b/tests/baselines/reference/organizeImports/Renamed_used.ts @@ -0,0 +1,9 @@ +// ==ORIGINAL== + +import { F1 as EffOne, F2 as EffTwo } from "lib"; +EffOne(); + +// ==ORGANIZED== + +import { F1 as EffOne } from "lib"; +EffOne();