Skip to content

Commit a1ed406

Browse files
committed
feature: @putout/plugin-remove-useless-variables: destruct: typeAnnotation: exclude
1 parent 8612c1e commit a1ed406

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function x(user: User) {
2+
const {a, b} = user;
3+
}

packages/plugin-remove-useless-variables/lib/destruct/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ export const match = () => ({
5757
if (__a.name !== first.name)
5858
return false;
5959

60-
if (path.scope.bindings[first.name].references > 1)
60+
const binding = path.scope.bindings[first.name];
61+
62+
if (binding.path.node.typeAnnotation)
63+
return false;
64+
65+
if (binding.references > 1)
6166
return false;
6267

6368
const namesLength = __object.properties.reduce(sum, 0);

packages/plugin-remove-useless-variables/lib/destruct/index.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,8 @@ test('remove-useless-variables: destruct: no transform: assign', (t) => {
4141
t.noTransform('assign');
4242
t.end();
4343
});
44+
45+
test('remove-useless-variables: destruct: no report: types', (t) => {
46+
t.noReport('types');
47+
t.end();
48+
});

0 commit comments

Comments
 (0)