@putout/plugin-putout 9.0.1 → 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 +39 -1
- package/lib/check-replace-code/generate-code.js +14 -4
- package/lib/check-replace-code/index.js +14 -0
- package/lib/convert-add-argument-to-add-args/index.js +0 -2
- package/lib/convert-match-to-function/index.js +8 -0
- package/lib/convert-replace-to-function/index.js +8 -0
- package/lib/convert-replace-with/index.js +0 -1
- package/lib/convert-replace-with-multiple/index.js +24 -36
- package/lib/index.js +3 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-putout.svg?style=flat&longCache=true
|
|
4
4
|
[NPMURL]: https://npmjs.org/package/@putout/plugin-putout"npm"
|
|
5
5
|
|
|
6
|
-
🐊[`Putout`](https://github.com/coderaiser/putout) plugin helps with
|
|
6
|
+
🐊[`Putout`](https://github.com/coderaiser/putout) plugin helps with plugins development.
|
|
7
7
|
|
|
8
8
|
## Install
|
|
9
9
|
|
|
@@ -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
|
+
|
|
@@ -44,6 +44,9 @@ module.exports.traverse = ({push}) => ({
|
|
|
44
44
|
if (get(path))
|
|
45
45
|
return;
|
|
46
46
|
|
|
47
|
+
if (hasMatch(path))
|
|
48
|
+
return;
|
|
49
|
+
|
|
47
50
|
for (const propertyPath of path.get('right.body.properties')) {
|
|
48
51
|
if (!propertyPath.get('value').isStringLiteral())
|
|
49
52
|
continue;
|
|
@@ -117,3 +120,14 @@ function parseKey(propertyPath) {
|
|
|
117
120
|
return [null, key];
|
|
118
121
|
}
|
|
119
122
|
|
|
123
|
+
function hasMatch(path) {
|
|
124
|
+
const {body} = path.scope.getProgramParent().path.node;
|
|
125
|
+
|
|
126
|
+
for (const current of body) {
|
|
127
|
+
if (compare(current, 'module.exports.match = __a'))
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const fullstore = require('fullstore');
|
|
4
|
-
|
|
5
3
|
const {
|
|
6
4
|
operator,
|
|
7
5
|
template,
|
|
@@ -26,7 +24,7 @@ const replaceWithAST = template.ast(`
|
|
|
26
24
|
const {replaceWithMultiple} = require('putout').operate;
|
|
27
25
|
`);
|
|
28
26
|
|
|
29
|
-
module.exports.fix = ({path, calleePath, property, object, program
|
|
27
|
+
module.exports.fix = ({path, calleePath, property, object, program}) => {
|
|
30
28
|
const strictModePath = program.get('body.0');
|
|
31
29
|
const {bindings} = strictModePath.scope;
|
|
32
30
|
|
|
@@ -36,11 +34,6 @@ module.exports.fix = ({path, calleePath, property, object, program, isInserted})
|
|
|
36
34
|
if (bindings.replaceWithMultiple)
|
|
37
35
|
return;
|
|
38
36
|
|
|
39
|
-
if (isInserted())
|
|
40
|
-
return;
|
|
41
|
-
|
|
42
|
-
isInserted(true);
|
|
43
|
-
|
|
44
37
|
if (!bindings.replaceWith && !bindings.insertAfter)
|
|
45
38
|
return insertAfter(strictModePath, replaceWithAST);
|
|
46
39
|
|
|
@@ -63,32 +56,27 @@ function getVarPath(bindings) {
|
|
|
63
56
|
return insertAfter.path;
|
|
64
57
|
}
|
|
65
58
|
|
|
66
|
-
module.exports.traverse = ({push}) => {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
property,
|
|
90
|
-
});
|
|
91
|
-
},
|
|
92
|
-
};
|
|
93
|
-
};
|
|
59
|
+
module.exports.traverse = ({push}) => ({
|
|
60
|
+
CallExpression(path) {
|
|
61
|
+
const calleePath = path.get('callee');
|
|
62
|
+
|
|
63
|
+
if (!calleePath.isMemberExpression())
|
|
64
|
+
return;
|
|
65
|
+
|
|
66
|
+
const {object, property} = calleePath.node;
|
|
67
|
+
|
|
68
|
+
if (property.name !== 'replaceWithMultiple')
|
|
69
|
+
return;
|
|
70
|
+
|
|
71
|
+
const program = path.findParent((path) => path.isProgram());
|
|
72
|
+
|
|
73
|
+
push({
|
|
74
|
+
path,
|
|
75
|
+
object,
|
|
76
|
+
program,
|
|
77
|
+
calleePath,
|
|
78
|
+
property,
|
|
79
|
+
});
|
|
80
|
+
},
|
|
81
|
+
});
|
|
94
82
|
|
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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-putout",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.2.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "putout plugin helps with plugins development",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"nodemon": "^2.0.1"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"putout": ">=24"
|
|
50
|
+
"putout": ">=24.2"
|
|
51
51
|
},
|
|
52
52
|
"license": "MIT",
|
|
53
53
|
"engines": {
|