@putout/plugin-putout 10.1.0 → 10.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.
package/README.md
CHANGED
|
@@ -24,6 +24,8 @@ npm i @putout/plugin-putout -D
|
|
|
24
24
|
"putout/convert-to-no-transform-code": "on",
|
|
25
25
|
"putout/convert-replace-with": "on",
|
|
26
26
|
"putout/convert-replace-with-multiple": "on",
|
|
27
|
+
"putout/convert-replace-to-function": "on",
|
|
28
|
+
"putout/convert-match-to-function": "on",
|
|
27
29
|
"putout/convert-babel-types": "on",
|
|
28
30
|
"putout/convert-destructuring-to-identifier": "on",
|
|
29
31
|
"putout/convert-node-to-path-in-get-template-values": "on",
|
|
@@ -188,6 +190,42 @@ module.exports.fix = (path) => {
|
|
|
188
190
|
};
|
|
189
191
|
```
|
|
190
192
|
|
|
193
|
+
## convert-replace-to-function
|
|
194
|
+
|
|
195
|
+
### ❌ Incorrect code example
|
|
196
|
+
|
|
197
|
+
```js
|
|
198
|
+
module.exports.replace = {
|
|
199
|
+
'let __a = __b': 'const __b = __a',
|
|
200
|
+
};
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### ✅ Correct code Example
|
|
204
|
+
|
|
205
|
+
```js
|
|
206
|
+
module.exports.replace = () => ({
|
|
207
|
+
'let __a = __b': 'const __b = __a',
|
|
208
|
+
});
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## convert-match-to-function
|
|
212
|
+
|
|
213
|
+
### ❌ Incorrect code example
|
|
214
|
+
|
|
215
|
+
```js
|
|
216
|
+
module.exports.match = {
|
|
217
|
+
'let __a = __b': () => false,
|
|
218
|
+
};
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### ✅ Correct code Example
|
|
222
|
+
|
|
223
|
+
```js
|
|
224
|
+
module.exports.match = () => ({
|
|
225
|
+
'let __a = __b': () => false,
|
|
226
|
+
});
|
|
227
|
+
```
|
|
228
|
+
|
|
191
229
|
## convert-babel-types
|
|
192
230
|
|
|
193
231
|
### ❌ Incorrect code example
|
|
@@ -9,6 +9,7 @@ const {
|
|
|
9
9
|
ArrayPattern,
|
|
10
10
|
ObjectPattern,
|
|
11
11
|
BlockStatement,
|
|
12
|
+
ObjectExpression,
|
|
12
13
|
} = types;
|
|
13
14
|
|
|
14
15
|
module.exports = (rootPath, key) => {
|
|
@@ -56,10 +57,7 @@ module.exports = (rootPath, key) => {
|
|
|
56
57
|
}
|
|
57
58
|
|
|
58
59
|
if (name === '__object') {
|
|
59
|
-
|
|
60
|
-
replaceWith(path, ObjectPattern([]));
|
|
61
|
-
|
|
62
|
-
return;
|
|
60
|
+
return objectify(path);
|
|
63
61
|
}
|
|
64
62
|
|
|
65
63
|
if (name === '__body') {
|
|
@@ -86,3 +84,15 @@ function createVarStore(path) {
|
|
|
86
84
|
};
|
|
87
85
|
}
|
|
88
86
|
|
|
87
|
+
function objectify(path) {
|
|
88
|
+
const {parentPath} = path;
|
|
89
|
+
const isVar = parentPath.isVariableDeclarator();
|
|
90
|
+
const isAssign = parentPath.isAssignmentExpression();
|
|
91
|
+
|
|
92
|
+
if (isVar && parentPath.get('id') === path)
|
|
93
|
+
return replaceWith(path, ObjectPattern([]));
|
|
94
|
+
|
|
95
|
+
if (isAssign && parentPath.get('right') === path)
|
|
96
|
+
return replaceWith(path, ObjectExpression([]));
|
|
97
|
+
}
|
|
98
|
+
|
package/lib/index.js
CHANGED
|
@@ -11,9 +11,11 @@ module.exports.rules = {
|
|
|
11
11
|
...getRule('convert-putout-test-to-create-test'),
|
|
12
12
|
...getRule('convert-to-no-transform-code'),
|
|
13
13
|
...getRule('convert-find-to-traverse'),
|
|
14
|
-
...getRule('convert-replace-with'),
|
|
15
14
|
...getRule('convert-destructuring-to-identifier'),
|
|
15
|
+
...getRule('convert-replace-with'),
|
|
16
16
|
...getRule('convert-replace-with-multiple'),
|
|
17
|
+
...getRule('convert-replace-to-function'),
|
|
18
|
+
...getRule('convert-match-to-function'),
|
|
17
19
|
...getRule('convert-babel-types'),
|
|
18
20
|
...getRule('convert-node-to-path-in-get-template-values'),
|
|
19
21
|
...getRule('convert-traverse-to-include'),
|
package/package.json
CHANGED