@putout/engine-runner 14.0.0 β 14.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 +20 -8
- package/lib/merge-visitors.js +1 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -65,6 +65,8 @@ module.exports.report = () => 'debugger should not be used';
|
|
|
65
65
|
module.exports.replace = () => ({
|
|
66
66
|
debugger: '',
|
|
67
67
|
});
|
|
68
|
+
|
|
69
|
+
// debugger; alert(); -> alert();
|
|
68
70
|
```
|
|
69
71
|
|
|
70
72
|
Templates:
|
|
@@ -75,6 +77,8 @@ module.exports.report = () => 'any message here';
|
|
|
75
77
|
module.exports.replace = () => ({
|
|
76
78
|
'var __a = 1': 'const __a = 1',
|
|
77
79
|
});
|
|
80
|
+
|
|
81
|
+
// var x = 1; -> const x = 1;
|
|
78
82
|
```
|
|
79
83
|
|
|
80
84
|
A couple variables example:
|
|
@@ -85,6 +89,8 @@ module.exports.report = () => 'any message here';
|
|
|
85
89
|
module.exports.replace = () => ({
|
|
86
90
|
'const __a = __b': 'const __b = __a',
|
|
87
91
|
});
|
|
92
|
+
|
|
93
|
+
// const hello = world; -> const world = hello;
|
|
88
94
|
```
|
|
89
95
|
|
|
90
96
|
#### Processing of node using functions
|
|
@@ -102,6 +108,8 @@ module.exports.replace = () => ({
|
|
|
102
108
|
return '';
|
|
103
109
|
},
|
|
104
110
|
});
|
|
111
|
+
|
|
112
|
+
// for (a of b) {}; alert(); -> alert();
|
|
105
113
|
```
|
|
106
114
|
|
|
107
115
|
Update node:
|
|
@@ -111,11 +119,13 @@ module.exports.report = () => 'any message here';
|
|
|
111
119
|
|
|
112
120
|
module.exports.replace = () => ({
|
|
113
121
|
'for (const __a of __array) __c': ({__a, __array, __c}, path) => {
|
|
114
|
-
// update __array elements
|
|
122
|
+
// update __array elements
|
|
115
123
|
path.node.right.elements = [];
|
|
116
124
|
return path;
|
|
117
125
|
},
|
|
118
126
|
});
|
|
127
|
+
|
|
128
|
+
// for (const a of [1, 2, 3]) {}; -> for (const a of []) {};
|
|
119
129
|
```
|
|
120
130
|
|
|
121
131
|
Update node using template variables:
|
|
@@ -129,6 +139,8 @@ module.exports.replace = () => ({
|
|
|
129
139
|
return 'for (const x of y) z';
|
|
130
140
|
},
|
|
131
141
|
});
|
|
142
|
+
|
|
143
|
+
// for (const item of array) {}; -> for (const x of y) z;
|
|
132
144
|
```
|
|
133
145
|
|
|
134
146
|
### Includer
|
|
@@ -224,8 +236,8 @@ const ast = parse('const m = "hi"; debugger');
|
|
|
224
236
|
const places = runPlugins({
|
|
225
237
|
ast,
|
|
226
238
|
shebang: false, // default
|
|
227
|
-
fix:
|
|
228
|
-
fixCount:
|
|
239
|
+
fix: false, // default
|
|
240
|
+
fixCount: 0, // default
|
|
229
241
|
plugins,
|
|
230
242
|
parser: 'babel', // default
|
|
231
243
|
});
|
|
@@ -234,7 +246,7 @@ const places = runPlugins({
|
|
|
234
246
|
## Stores
|
|
235
247
|
|
|
236
248
|
Stores is preferred way of keeping π**Putout** data, `traverse` init function called only once, and any other way
|
|
237
|
-
of handling variables will most likely will lead to bugs. There is
|
|
249
|
+
of handling variables will most likely will lead to bugs. There is a couple store types:
|
|
238
250
|
|
|
239
251
|
- β
`listStore`;
|
|
240
252
|
- β
`pathStore`;
|
|
@@ -296,7 +308,7 @@ module.exports.traverse = ({pathStore}) => ({
|
|
|
296
308
|
|
|
297
309
|
Program: {
|
|
298
310
|
exit() {
|
|
299
|
-
console.log(
|
|
311
|
+
console.log(pathStore());
|
|
300
312
|
// returns
|
|
301
313
|
[];
|
|
302
314
|
},
|
|
@@ -378,14 +390,14 @@ When you need to update named arrays:
|
|
|
378
390
|
module.exports.traverse = ({uplist, push}) => ({
|
|
379
391
|
'const __object = __a.__b': (fullPath) => {
|
|
380
392
|
const {__a, __b} = getTemplateValues(fullPath, 'const __object = __a.__b');
|
|
381
|
-
const
|
|
382
|
-
const {uid} =
|
|
393
|
+
const initPath = fullPath.get('declarations.0.init');
|
|
394
|
+
const {uid} = initPath.scope;
|
|
383
395
|
|
|
384
396
|
if (isIdentifier(__a) || isCallExpression(__a)) {
|
|
385
397
|
const {code} = generate(__a);
|
|
386
398
|
const id = `${uid}-${code}`;
|
|
387
399
|
|
|
388
|
-
return uplist(id,
|
|
400
|
+
return uplist(id, initPath);
|
|
389
401
|
}
|
|
390
402
|
},
|
|
391
403
|
'Program': {
|
package/lib/merge-visitors.js
CHANGED
|
@@ -65,7 +65,7 @@ module.exports = (pluginsToMerge, {fix, shebang, template}) => {
|
|
|
65
65
|
});
|
|
66
66
|
|
|
67
67
|
if (!visitor)
|
|
68
|
-
throw Error(
|
|
68
|
+
throw Error(`βοΈ Visitors cannot be empty in "${rule}"`);
|
|
69
69
|
|
|
70
70
|
assign(options, {
|
|
71
71
|
include: parse('include', plugin, options),
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/engine-runner",
|
|
3
|
-
"version": "14.0.
|
|
3
|
+
"version": "14.0.2",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
|
-
"description": "
|
|
6
|
+
"description": "Run πPutout plugins",
|
|
7
7
|
"homepage": "https://github.com/coderaiser/putout/tree/master/packages/engine-runner#readme",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
|
+
"commitType": "colon",
|
|
9
10
|
"release": false,
|
|
10
11
|
"tag": false,
|
|
11
12
|
"changelog": false,
|
|
@@ -53,7 +54,7 @@
|
|
|
53
54
|
"montag": "^1.0.0",
|
|
54
55
|
"nodemon": "^2.0.1",
|
|
55
56
|
"putout": "*",
|
|
56
|
-
"supertape": "^
|
|
57
|
+
"supertape": "^8.0.0"
|
|
57
58
|
},
|
|
58
59
|
"license": "MIT",
|
|
59
60
|
"engines": {
|