@putout/plugin-conditions 9.0.0 β 9.0.2
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.
- package/README.md +5 -2
- package/lib/apply-early-return/index.js +15 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -147,6 +147,8 @@ Linter | Rule | Fix
|
|
|
147
147
|
|
|
148
148
|
## apply-early-return
|
|
149
149
|
|
|
150
|
+
Checkout in π[**Putout Editor**](https://putout.cloudcmd.io/#/gist/dd2ba101a3039784bd83a12157fd7fc4/5cdf5340f761c6df3d82964b27aae7d7befcdc56).
|
|
151
|
+
|
|
150
152
|
### β Example of incorrect code
|
|
151
153
|
|
|
152
154
|
```js
|
|
@@ -165,8 +167,9 @@ function notBlockNoNext() {
|
|
|
165
167
|
if (a) {
|
|
166
168
|
x();
|
|
167
169
|
return;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
b();
|
|
170
173
|
}
|
|
171
174
|
```
|
|
172
175
|
|
|
@@ -17,6 +17,7 @@ export const replace = () => ({
|
|
|
17
17
|
'if (__a) __b; else __c': ({__b}, path) => {
|
|
18
18
|
if (isBlockStatement(__b)) {
|
|
19
19
|
__b.body.push(returnStatement());
|
|
20
|
+
|
|
20
21
|
return path;
|
|
21
22
|
}
|
|
22
23
|
|
|
@@ -46,5 +47,18 @@ function check(vars, path) {
|
|
|
46
47
|
return false;
|
|
47
48
|
}
|
|
48
49
|
|
|
49
|
-
return
|
|
50
|
+
return !hasReturn(path);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function hasReturn(path) {
|
|
54
|
+
let has = false;
|
|
55
|
+
|
|
56
|
+
path.traverse({
|
|
57
|
+
ReturnStatement(path) {
|
|
58
|
+
has = true;
|
|
59
|
+
path.stop();
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
return has;
|
|
50
64
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-conditions",
|
|
3
|
-
"version": "9.0.
|
|
3
|
+
"version": "9.0.2",
|
|
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",
|