Skip to content

Commit f2ce71a

Browse files
committed
feature: @putout/plugin-conditions: apply-consistent-blocks: exclude empty consequent body
1 parent 0825970 commit f2ce71a

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
if (isReturnStatement(last)) {} else {
2+
__body.body.push(expressionStatement(maybeRet(ret) || __b.typeName));
3+
}
4+

packages/plugin-conditions/lib/apply-consistent-blocks/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ export const filter = (path) => {
6060
if (!alternate && !consequent.body?.length)
6161
return false;
6262

63+
if (isBlockStatement(consequent) && !consequent.body.length)
64+
return false;
65+
6366
if (path === path.parentPath.get('alternate'))
6467
return false;
6568

packages/plugin-conditions/lib/apply-consistent-blocks/index.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ test('putout: apply-consistent-blocks: no report: else-statement', (t) => {
6262
t.end();
6363
});
6464

65+
test('putout: apply-consistent-blocks: no report: consequent', (t) => {
66+
t.noReport('consequent');
67+
t.end();
68+
});
69+
6570
test('putout: apply-consistent-blocks: no report after transform: nested', (t) => {
6671
t.noReportAfterTransform('nested');
6772
t.end();

0 commit comments

Comments
 (0)