@putout/plugin-putout 20.9.0 → 20.10.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
|
@@ -89,7 +89,9 @@ npm i @putout/plugin-putout -D
|
|
|
89
89
|
"putout/add-await-to-progress": "on",
|
|
90
90
|
"putout/add-index-to-import": "on",
|
|
91
91
|
"putout/check-match": "on",
|
|
92
|
-
"putout/check-replace-code": "on",
|
|
92
|
+
"putout/check-replace-code": ["on", {
|
|
93
|
+
"once": true
|
|
94
|
+
}],
|
|
93
95
|
"putout/convert-putout-test-to-create-test": "on",
|
|
94
96
|
"putout/convert-to-no-transform-code": "on",
|
|
95
97
|
"putout/convert-number-to-numeric": "on",
|
|
@@ -743,6 +745,7 @@ module.exports.match = () => ({
|
|
|
743
745
|
## check-replace-code
|
|
744
746
|
|
|
745
747
|
Checks that [Replacer](https://github.com/coderaiser/putout/tree/master/packages/engine-runner#replacer) transform is possible.
|
|
748
|
+
Pass `once=false` to always fail no matter how many `fixCounts` passed.
|
|
746
749
|
|
|
747
750
|
### ❌ Example of incorrect code
|
|
748
751
|
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const {
|
|
4
|
+
parse,
|
|
5
|
+
print,
|
|
6
|
+
transform,
|
|
7
|
+
} = require('putout');
|
|
8
|
+
|
|
4
9
|
const tryCatch = require('try-catch');
|
|
5
10
|
const pluginGenerate = require('./plugin-generate');
|
|
6
11
|
|
|
@@ -11,21 +16,20 @@ module.exports = (rootPath, source) => {
|
|
|
11
16
|
|
|
12
17
|
if (parseError)
|
|
13
18
|
return [parseError];
|
|
14
|
-
|
|
19
|
+
|
|
15
20
|
const getVar = createVarStore(rootPath);
|
|
16
21
|
|
|
17
|
-
|
|
22
|
+
transform(ast, source, {
|
|
18
23
|
rules: {
|
|
19
|
-
|
|
24
|
+
generate: ['on', {
|
|
20
25
|
getVar,
|
|
21
26
|
}],
|
|
22
27
|
},
|
|
23
28
|
plugins: [
|
|
24
29
|
['generate', pluginGenerate],
|
|
25
|
-
]
|
|
30
|
+
],
|
|
26
31
|
});
|
|
27
32
|
|
|
28
|
-
|
|
29
33
|
const code = print(ast);
|
|
30
34
|
|
|
31
35
|
return [null, code];
|
|
@@ -33,13 +37,13 @@ module.exports = (rootPath, source) => {
|
|
|
33
37
|
|
|
34
38
|
function createVarStore(path) {
|
|
35
39
|
const store = {};
|
|
36
|
-
|
|
40
|
+
|
|
37
41
|
return (name) => {
|
|
38
42
|
if (store[name])
|
|
39
43
|
return store[name];
|
|
40
|
-
|
|
44
|
+
|
|
41
45
|
store[name] = path.scope.generateUid();
|
|
42
|
-
|
|
46
|
+
|
|
43
47
|
return store[name];
|
|
44
48
|
};
|
|
45
49
|
}
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const {
|
|
4
|
+
operator,
|
|
5
|
+
parse,
|
|
6
|
+
print,
|
|
7
|
+
transform,
|
|
8
|
+
} = require('putout');
|
|
9
|
+
|
|
4
10
|
const tryCatch = require('try-catch');
|
|
5
11
|
const generateCode = require('./generate-code');
|
|
6
12
|
const noop = () => {};
|
|
7
|
-
|
|
13
|
+
|
|
8
14
|
const {
|
|
9
15
|
compare,
|
|
10
16
|
extract,
|
|
@@ -37,10 +43,20 @@ module.exports.fix = ({mainPath}) => {
|
|
|
37
43
|
set(mainPath);
|
|
38
44
|
};
|
|
39
45
|
|
|
40
|
-
module.exports.traverse = ({push}) =>
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
46
|
+
module.exports.traverse = ({push, options}) => {
|
|
47
|
+
const {once = true} = options;
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
'module.exports.replace = () => __a': createTraverseReplacer({
|
|
51
|
+
once,
|
|
52
|
+
push,
|
|
53
|
+
}),
|
|
54
|
+
'export const replace = () => __a': createTraverseReplacer({
|
|
55
|
+
once,
|
|
56
|
+
push,
|
|
57
|
+
}),
|
|
58
|
+
};
|
|
59
|
+
};
|
|
44
60
|
|
|
45
61
|
function getProperties(path) {
|
|
46
62
|
const props = `body.properties`;
|
|
@@ -51,8 +67,8 @@ function getProperties(path) {
|
|
|
51
67
|
return path.get(`right.${props}`);
|
|
52
68
|
}
|
|
53
69
|
|
|
54
|
-
const createTraverseReplacer = (push) => (path) => {
|
|
55
|
-
if (get(path))
|
|
70
|
+
const createTraverseReplacer = ({once, push}) => (path) => {
|
|
71
|
+
if (once && get(path))
|
|
56
72
|
return;
|
|
57
73
|
|
|
58
74
|
if (hasMatch(path))
|
|
@@ -88,10 +104,11 @@ const createTraverseReplacer = (push) => (path) => {
|
|
|
88
104
|
return;
|
|
89
105
|
}
|
|
90
106
|
|
|
91
|
-
const
|
|
92
|
-
printer: 'putout',
|
|
93
|
-
fix: true,
|
|
107
|
+
const ast = parse(keyCode, {
|
|
94
108
|
isTS: true,
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
const [transformError] = tryCatch(transform, ast, keyCode, {
|
|
95
112
|
plugins: [
|
|
96
113
|
['evaluate', {
|
|
97
114
|
report: noop,
|
|
@@ -112,7 +129,7 @@ const createTraverseReplacer = (push) => (path) => {
|
|
|
112
129
|
return;
|
|
113
130
|
}
|
|
114
131
|
|
|
115
|
-
const code =
|
|
132
|
+
const code = print(ast).slice(0, -1);
|
|
116
133
|
const [error, is] = tryCatch(compare, rmSemi(code), template);
|
|
117
134
|
|
|
118
135
|
if (error || !is)
|
package/package.json
CHANGED