Skip to content

Commit f7d9ab6

Browse files
committed
feature: @putout/plugin-promise: remove-useless-async: await using couple
1 parent 0ca521a commit f7d9ab6

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
async (name, data) => {
22
await using disk = createDisk(data);
33
}
4+
5+
const x = async (name, data) => {
6+
await using baz = 3, qux = 4;
7+
}

packages/plugin-promises/lib/remove-useless-async/index.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,25 @@ export const include = () => [
1515
'async (__args) => __body',
1616
];
1717

18-
export const filter = (path) => !contains(path, [
19-
'throw __',
20-
'await __',
21-
'for await (__ of __) __',
22-
'await using __ = __',
23-
]);
18+
export const filter = (path) => {
19+
if (hasAwaitUsing(path))
20+
return false;
21+
22+
return !contains(path, ['throw __', 'await __', 'for await (__ of __) __']);
23+
};
24+
25+
function hasAwaitUsing(path) {
26+
let is = false;
27+
28+
path.traverse({
29+
VariableDeclaration(path) {
30+
if (path.node.kind !== 'await using')
31+
return;
32+
33+
is = true;
34+
path.stop();
35+
},
36+
});
37+
38+
return is;
39+
}

0 commit comments

Comments
 (0)