@putout/plugin-putout 20.6.0 → 20.8.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 +22 -0
- package/lib/add-traverse-args/index.js +1 -0
- package/lib/check-replace-code/index.js +78 -66
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -890,6 +890,28 @@ module.exports.traverse = ({store}) => ({
|
|
|
890
890
|
});
|
|
891
891
|
```
|
|
892
892
|
|
|
893
|
+
- [`listStore``](https://github.com/coderaiser/putout/blob/master/packages/engine-runner/README.md#liststore)
|
|
894
|
+
|
|
895
|
+
### ❌ Example of incorrect code
|
|
896
|
+
|
|
897
|
+
```js
|
|
898
|
+
export const traverse = () => ({
|
|
899
|
+
ImportDeclaration(path) {
|
|
900
|
+
listStore(path);
|
|
901
|
+
},
|
|
902
|
+
});
|
|
903
|
+
```
|
|
904
|
+
|
|
905
|
+
### ✅ Example of correct code
|
|
906
|
+
|
|
907
|
+
```js
|
|
908
|
+
module.exports.traverse = ({listStore}) => ({
|
|
909
|
+
ImportDeclaration(path) {
|
|
910
|
+
listStore(path);
|
|
911
|
+
},
|
|
912
|
+
});
|
|
913
|
+
```
|
|
914
|
+
|
|
893
915
|
- [`pathStore`](https://github.com/coderaiser/putout/blob/master/packages/engine-runner/README.md#pathstore)
|
|
894
916
|
|
|
895
917
|
### ❌ Example of incorrect code
|
|
@@ -38,79 +38,91 @@ module.exports.fix = ({mainPath}) => {
|
|
|
38
38
|
};
|
|
39
39
|
|
|
40
40
|
module.exports.traverse = ({push}) => ({
|
|
41
|
-
'module.exports.replace = () => __a': (
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
'module.exports.replace = () => __a': createTraverseReplacer(push),
|
|
42
|
+
'export const replace = () => __a': createTraverseReplacer(push),
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
function getProperties(path) {
|
|
46
|
+
const props = `body.properties`;
|
|
47
|
+
|
|
48
|
+
if (path.isExportNamedDeclaration())
|
|
49
|
+
return path.get(`declaration.declarations.0.init.${props}`);
|
|
50
|
+
|
|
51
|
+
return path.get(`right.${props}`);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const createTraverseReplacer = (push) => (path) => {
|
|
55
|
+
if (get(path))
|
|
56
|
+
return;
|
|
57
|
+
|
|
58
|
+
if (hasMatch(path))
|
|
59
|
+
return;
|
|
60
|
+
|
|
61
|
+
for (const propertyPath of getProperties(path)) {
|
|
62
|
+
const template = extractValue(propertyPath);
|
|
44
63
|
|
|
45
|
-
if (
|
|
46
|
-
|
|
64
|
+
if (!template)
|
|
65
|
+
continue;
|
|
47
66
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (parseError) {
|
|
57
|
-
push({
|
|
58
|
-
error: parseError,
|
|
59
|
-
mainPath: path,
|
|
60
|
-
path: propertyPath,
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const [generateError, keyCode] = generateCode(path, key);
|
|
67
|
-
|
|
68
|
-
if (generateError) {
|
|
69
|
-
push({
|
|
70
|
-
error: generateError,
|
|
71
|
-
mainPath: path,
|
|
72
|
-
path: propertyPath,
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const [transformError, result] = tryCatch(putout, keyCode, {
|
|
79
|
-
printer: 'putout',
|
|
80
|
-
fix: true,
|
|
81
|
-
isTS: true,
|
|
82
|
-
plugins: [
|
|
83
|
-
['evaluate', {
|
|
84
|
-
report: noop,
|
|
85
|
-
replace: () => ({
|
|
86
|
-
[key]: template,
|
|
87
|
-
}),
|
|
88
|
-
}],
|
|
89
|
-
],
|
|
67
|
+
const [parseError, key] = parseKey(propertyPath);
|
|
68
|
+
|
|
69
|
+
if (parseError) {
|
|
70
|
+
push({
|
|
71
|
+
error: parseError,
|
|
72
|
+
mainPath: path,
|
|
73
|
+
path: propertyPath,
|
|
90
74
|
});
|
|
91
75
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const [generateError, keyCode] = generateCode(path, key);
|
|
80
|
+
|
|
81
|
+
if (generateError) {
|
|
82
|
+
push({
|
|
83
|
+
error: generateError,
|
|
84
|
+
mainPath: path,
|
|
85
|
+
path: propertyPath,
|
|
86
|
+
});
|
|
101
87
|
|
|
102
|
-
|
|
103
|
-
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const [transformError, result] = tryCatch(putout, keyCode, {
|
|
92
|
+
printer: 'putout',
|
|
93
|
+
fix: true,
|
|
94
|
+
isTS: true,
|
|
95
|
+
plugins: [
|
|
96
|
+
['evaluate', {
|
|
97
|
+
report: noop,
|
|
98
|
+
replace: () => ({
|
|
99
|
+
[key]: template,
|
|
100
|
+
}),
|
|
101
|
+
}],
|
|
102
|
+
],
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
if (transformError) {
|
|
106
|
+
push({
|
|
107
|
+
error: transformError,
|
|
108
|
+
mainPath: path,
|
|
109
|
+
path: propertyPath,
|
|
110
|
+
});
|
|
104
111
|
|
|
105
|
-
|
|
106
|
-
push({
|
|
107
|
-
code,
|
|
108
|
-
mainPath: path,
|
|
109
|
-
path: propertyPath,
|
|
110
|
-
});
|
|
112
|
+
return;
|
|
111
113
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
+
|
|
115
|
+
const code = result.code.slice(0, -1);
|
|
116
|
+
const [error, is] = tryCatch(compare, rmSemi(code), template);
|
|
117
|
+
|
|
118
|
+
if (error || !is)
|
|
119
|
+
push({
|
|
120
|
+
code,
|
|
121
|
+
mainPath: path,
|
|
122
|
+
path: propertyPath,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
};
|
|
114
126
|
|
|
115
127
|
function parseKey(propertyPath) {
|
|
116
128
|
const keyPath = propertyPath.get('key');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-putout",
|
|
3
|
-
"version": "20.
|
|
3
|
+
"version": "20.8.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",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@putout/plugin-tape": "*",
|
|
41
41
|
"@putout/test": "^10.0.0",
|
|
42
|
-
"c8": "^
|
|
42
|
+
"c8": "^10.0.0",
|
|
43
43
|
"eslint": "^9.0.0",
|
|
44
44
|
"eslint-plugin-n": "^17.0.0",
|
|
45
45
|
"eslint-plugin-putout": "^22.0.0",
|