Skip to content

Commit e109fd2

Browse files
authored
feature: @putout/plugin-remove-nested-blocks: case when it is the only block (#225)
1 parent 8698589 commit e109fd2

File tree

5 files changed

+34
-1
lines changed

5 files changed

+34
-1
lines changed

packages/plugin-remove-nested-blocks/lib/remove-nested-blocks.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ module.exports.filter = (path) => {
4949

5050
const is = !isIntersect(bindings, path.parentPath);
5151

52-
return is && (parentPath.isBlockStatement() || parentPath.isProgram());
52+
if (!parentPath.isBlockStatement() && !parentPath.isProgram())
53+
return false;
54+
55+
return is || path.container.length === 1;
5356
};
5457

5558
function isReturnWithoutArg(path) {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function fun1(f) {
2+
let x1;
3+
{
4+
let x1 = f;
5+
return x1;
6+
}
7+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
let x1;
2+
3+
function fun1(f) {
4+
let x1 = f;
5+
return x1;
6+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
let x1;
2+
function fun1(f) {
3+
{
4+
let x1 = f;
5+
return x1;
6+
}
7+
}

packages/plugin-remove-nested-blocks/test/remove-nested-blocks.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,13 @@ test('plugin-remove-nested-blocks: no report: return', (t) => {
6161
t.noReport('return');
6262
t.end();
6363
});
64+
65+
test('plugin-remove-nested-blocks: transform: intersect-single', (t) => {
66+
t.transform('intersect-single');
67+
t.end();
68+
});
69+
70+
test('plugin-remove-nested-blocks: no report: intersect-multi', (t) => {
71+
t.noReport('intersect-multi');
72+
t.end();
73+
});

0 commit comments

Comments
 (0)