@putout/plugin-conditions 8.0.0 → 8.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -60,6 +60,9 @@ export const filter = (path) => {
|
|
|
60
60
|
if (!alternate && !consequent.body?.length)
|
|
61
61
|
return false;
|
|
62
62
|
|
|
63
|
+
if (isBlockStatement(consequent) && !consequent.body.length)
|
|
64
|
+
return false;
|
|
65
|
+
|
|
63
66
|
if (path === path.parentPath.get('alternate'))
|
|
64
67
|
return false;
|
|
65
68
|
|
|
@@ -75,6 +78,9 @@ export const filter = (path) => {
|
|
|
75
78
|
|
|
76
79
|
if (isVariableDeclaration(first))
|
|
77
80
|
continue;
|
|
81
|
+
|
|
82
|
+
if (first.leadingComments?.length)
|
|
83
|
+
continue;
|
|
78
84
|
}
|
|
79
85
|
|
|
80
86
|
blocks.push(is);
|
|
@@ -14,6 +14,9 @@ export const match = () => ({
|
|
|
14
14
|
if (!isBlockStatement(__b))
|
|
15
15
|
return isReturnLike(__b);
|
|
16
16
|
|
|
17
|
+
if (!__b.body.length)
|
|
18
|
+
return true;
|
|
19
|
+
|
|
17
20
|
const latest = __b.body.at(-1);
|
|
18
21
|
|
|
19
22
|
return isReturnLike(latest);
|
|
@@ -21,10 +24,15 @@ export const match = () => ({
|
|
|
21
24
|
});
|
|
22
25
|
|
|
23
26
|
export const replace = () => ({
|
|
24
|
-
'if (__a) __b; else __c':
|
|
25
|
-
if (
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
'if (__a) __b; else __c': ({__b}) => {
|
|
28
|
+
if (isBlockStatement(__b) && !__b.body.length)
|
|
29
|
+
return 'if (!__a) __c';
|
|
30
|
+
|
|
31
|
+
return `{
|
|
32
|
+
if (__a) __b;
|
|
33
|
+
__c;
|
|
34
|
+
}`;
|
|
35
|
+
},
|
|
28
36
|
});
|
|
29
37
|
|
|
30
38
|
function isReturnLike(node) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-conditions",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "🐊Putout plugin adds support of conditions transformations",
|
|
@@ -34,11 +34,11 @@
|
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@putout/eslint-flat": "^3.0.0",
|
|
36
36
|
"@putout/plugin-for-of": "*",
|
|
37
|
-
"@putout/test": "^
|
|
37
|
+
"@putout/test": "^14.0.0",
|
|
38
38
|
"c8": "^10.0.0",
|
|
39
39
|
"eslint": "^9.0.0",
|
|
40
40
|
"eslint-plugin-n": "^17.0.0",
|
|
41
|
-
"eslint-plugin-putout": "^
|
|
41
|
+
"eslint-plugin-putout": "^28.0.0",
|
|
42
42
|
"madrun": "^11.0.0",
|
|
43
43
|
"montag": "^1.2.1",
|
|
44
44
|
"nodemon": "^3.0.1"
|