@putout/engine-runner 16.0.1 → 17.0.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 +12 -11
- package/lib/declare.js +0 -1
- package/lib/get-position.js +1 -4
- package/lib/include.js +1 -0
- package/lib/index.js +12 -13
- package/lib/maybe-array.js +0 -1
- package/lib/merge-visitors.js +3 -1
- package/lib/replace/find-path.js +1 -1
- package/lib/replace/index.js +13 -8
- package/lib/replace/watermark.js +6 -10
- package/lib/run-fix.js +7 -3
- package/lib/store.js +4 -1
- package/lib/super-find.js +6 -1
- package/lib/template/index.js +1 -1
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -167,14 +167,9 @@ module.exports.fix = (path) => {
|
|
|
167
167
|
path.remove();
|
|
168
168
|
};
|
|
169
169
|
|
|
170
|
-
module.exports.include = () => [
|
|
171
|
-
'debugger',
|
|
172
|
-
];
|
|
173
|
-
|
|
170
|
+
module.exports.include = () => ['debugger'];
|
|
174
171
|
// optional
|
|
175
|
-
module.exports.exclude = () => {
|
|
176
|
-
};
|
|
177
|
-
|
|
172
|
+
module.exports.exclude = () => {};
|
|
178
173
|
// optional
|
|
179
174
|
module.exports.filter = (path) => {
|
|
180
175
|
return true;
|
|
@@ -246,6 +241,7 @@ const plugins = [{
|
|
|
246
241
|
}];
|
|
247
242
|
|
|
248
243
|
const ast = parse('const m = "hi"; debugger');
|
|
244
|
+
|
|
249
245
|
const places = runPlugins({
|
|
250
246
|
ast,
|
|
251
247
|
shebang: false, // default
|
|
@@ -293,7 +289,12 @@ module.exports.traverse = ({listStore}) => ({
|
|
|
293
289
|
exit() {
|
|
294
290
|
console.log(listStore());
|
|
295
291
|
// returns
|
|
296
|
-
[{
|
|
292
|
+
[{
|
|
293
|
+
type: 'DebuggerStatement',
|
|
294
|
+
}, {
|
|
295
|
+
type: 'DebuggerStatement',
|
|
296
|
+
}];
|
|
297
|
+
|
|
297
298
|
// for code
|
|
298
299
|
'debugger; debugger';
|
|
299
300
|
},
|
|
@@ -363,12 +364,12 @@ module.exports.traverse = ({push, store}) => ({
|
|
|
363
364
|
When you need to update already saved values, use `upstore`:
|
|
364
365
|
|
|
365
366
|
```js
|
|
366
|
-
module.exports.traverse = ({push,
|
|
367
|
+
module.exports.traverse = ({push, upstore}) => ({
|
|
367
368
|
TSTypeAliasDeclaration(path) {
|
|
368
369
|
if (path.parentPath.isExportNamedDeclaration())
|
|
369
370
|
return;
|
|
370
371
|
|
|
371
|
-
|
|
372
|
+
upstore(path.node.id.name, {
|
|
372
373
|
path,
|
|
373
374
|
});
|
|
374
375
|
},
|
|
@@ -384,7 +385,7 @@ module.exports.traverse = ({push, store}) => ({
|
|
|
384
385
|
|
|
385
386
|
Program: {
|
|
386
387
|
exit() {
|
|
387
|
-
for (const {path, used} of
|
|
388
|
+
for (const {path, used} of upstore()) {
|
|
388
389
|
if (used)
|
|
389
390
|
continue;
|
|
390
391
|
|
package/lib/declare.js
CHANGED
package/lib/get-position.js
CHANGED
package/lib/include.js
CHANGED
package/lib/index.js
CHANGED
|
@@ -11,10 +11,7 @@ const include = require('./include');
|
|
|
11
11
|
const replace = require('./replace');
|
|
12
12
|
const declare = require('./declare');
|
|
13
13
|
|
|
14
|
-
const {
|
|
15
|
-
getPath,
|
|
16
|
-
getPosition,
|
|
17
|
-
} = require('./get-position');
|
|
14
|
+
const {getPath, getPosition} = require('./get-position');
|
|
18
15
|
|
|
19
16
|
const isRemoved = (a) => a?.removed;
|
|
20
17
|
|
|
@@ -22,6 +19,7 @@ module.exports.runPlugins = ({ast, shebang, fix, fixCount, plugins, template = r
|
|
|
22
19
|
let places = [];
|
|
23
20
|
|
|
24
21
|
const merge = once(mergeVisitors);
|
|
22
|
+
|
|
25
23
|
const {
|
|
26
24
|
pluginsFind,
|
|
27
25
|
pluginsTraverse,
|
|
@@ -51,17 +49,21 @@ module.exports.getPosition = getPosition;
|
|
|
51
49
|
|
|
52
50
|
function run({ast, fix, shebang, pluginsFind, pluginsTraverse, template, merge}) {
|
|
53
51
|
return [
|
|
54
|
-
...runWithoutMerge({
|
|
52
|
+
...runWithoutMerge({
|
|
53
|
+
ast,
|
|
55
54
|
fix,
|
|
56
55
|
shebang,
|
|
57
56
|
template,
|
|
58
|
-
pluginsFind
|
|
59
|
-
|
|
57
|
+
pluginsFind,
|
|
58
|
+
}),
|
|
59
|
+
...runWithMerge({
|
|
60
|
+
ast,
|
|
60
61
|
fix,
|
|
61
62
|
shebang,
|
|
62
63
|
template,
|
|
63
64
|
pluginsTraverse,
|
|
64
|
-
merge
|
|
65
|
+
merge,
|
|
66
|
+
}),
|
|
65
67
|
];
|
|
66
68
|
}
|
|
67
69
|
|
|
@@ -96,10 +98,8 @@ function runWithoutMerge({ast, fix, shebang, template, pluginsFind}) {
|
|
|
96
98
|
|
|
97
99
|
for (const {rule, plugin, msg, options} of pluginsFind) {
|
|
98
100
|
debug(`find: ${rule}`);
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
find,
|
|
102
|
-
} = plugin;
|
|
101
|
+
|
|
102
|
+
const {report, find} = plugin;
|
|
103
103
|
|
|
104
104
|
const items = superFind({
|
|
105
105
|
rule,
|
|
@@ -178,4 +178,3 @@ function splitPlugins(plugins) {
|
|
|
178
178
|
pluginsTraverse,
|
|
179
179
|
};
|
|
180
180
|
}
|
|
181
|
-
|
package/lib/maybe-array.js
CHANGED
package/lib/merge-visitors.js
CHANGED
|
@@ -6,6 +6,7 @@ const {generate} = require('@putout/engine-parser');
|
|
|
6
6
|
const runFix = require('./run-fix');
|
|
7
7
|
const {getPosition} = require('./get-position');
|
|
8
8
|
const maybeArray = require('./maybe-array');
|
|
9
|
+
|
|
9
10
|
const {
|
|
10
11
|
listStore,
|
|
11
12
|
mapStore,
|
|
@@ -18,6 +19,7 @@ const shouldSkip = (a) => !a.parent;
|
|
|
18
19
|
const {merge} = traverse.visitors;
|
|
19
20
|
|
|
20
21
|
const {assign} = Object;
|
|
22
|
+
|
|
21
23
|
const parse = (name, plugin, options) => {
|
|
22
24
|
const list = [];
|
|
23
25
|
|
|
@@ -80,6 +82,7 @@ module.exports = (pluginsToMerge, {fix, shebang, template}) => {
|
|
|
80
82
|
}
|
|
81
83
|
|
|
82
84
|
const entries = Object.entries(pushed);
|
|
85
|
+
|
|
83
86
|
const visitor = {
|
|
84
87
|
shouldSkip,
|
|
85
88
|
...merge(mergeItems),
|
|
@@ -136,4 +139,3 @@ function getStore(plugin, {fix, rule, shebang, msg, options}) {
|
|
|
136
139
|
pathStore: paths,
|
|
137
140
|
};
|
|
138
141
|
}
|
|
139
|
-
|
package/lib/replace/find-path.js
CHANGED
package/lib/replace/index.js
CHANGED
|
@@ -8,10 +8,7 @@ const {
|
|
|
8
8
|
isExpressionStatement,
|
|
9
9
|
} = require('@babel/types');
|
|
10
10
|
|
|
11
|
-
const {
|
|
12
|
-
remove,
|
|
13
|
-
replaceWith,
|
|
14
|
-
} = require('@putout/operate');
|
|
11
|
+
const {remove, replaceWith} = require('@putout/operate');
|
|
15
12
|
|
|
16
13
|
const {
|
|
17
14
|
compare,
|
|
@@ -31,6 +28,7 @@ const log = (from, path) => {
|
|
|
31
28
|
};
|
|
32
29
|
|
|
33
30
|
const {keys, entries} = Object;
|
|
31
|
+
|
|
34
32
|
const {stringify} = JSON;
|
|
35
33
|
|
|
36
34
|
const stub = () => [];
|
|
@@ -46,7 +44,10 @@ module.exports = ({rule, plugin, msg, options}) => {
|
|
|
46
44
|
filter = getFilter(plugin.match, options),
|
|
47
45
|
} = plugin;
|
|
48
46
|
|
|
49
|
-
const replaceItems = replace({
|
|
47
|
+
const replaceItems = replace({
|
|
48
|
+
options,
|
|
49
|
+
});
|
|
50
|
+
|
|
50
51
|
const fix = getFix(replaceItems);
|
|
51
52
|
const include = packKeys(replaceItems);
|
|
52
53
|
|
|
@@ -116,7 +117,10 @@ const fix = (from, to, path) => {
|
|
|
116
117
|
});
|
|
117
118
|
|
|
118
119
|
mark.add();
|
|
119
|
-
path
|
|
120
|
+
path
|
|
121
|
+
.scope
|
|
122
|
+
.getBlockParent()
|
|
123
|
+
.crawl();
|
|
120
124
|
|
|
121
125
|
log(from, newPath);
|
|
122
126
|
};
|
|
@@ -127,7 +131,9 @@ const getFix = (items) => (path) => {
|
|
|
127
131
|
};
|
|
128
132
|
|
|
129
133
|
const getFilter = (match = stubMatch, options) => (path) => {
|
|
130
|
-
const all = entries(match({
|
|
134
|
+
const all = entries(match({
|
|
135
|
+
options,
|
|
136
|
+
}));
|
|
131
137
|
|
|
132
138
|
for (const [from, matchProperty] of all) {
|
|
133
139
|
const nodeFrom = template.ast(from);
|
|
@@ -193,4 +199,3 @@ function checkExpressionStatement(nodeFrom, nodeTo, path) {
|
|
|
193
199
|
|
|
194
200
|
throw Error(`☝️ Looks like try to put Statement in place of Expression, use 'match' to filter out such cases`);
|
|
195
201
|
}
|
|
196
|
-
|
package/lib/replace/watermark.js
CHANGED
|
@@ -9,10 +9,7 @@ const name = '__putout_runner_replace';
|
|
|
9
9
|
const hasWatermark = (watermark) => (path) => path.node?.[name]?.has(watermark);
|
|
10
10
|
|
|
11
11
|
module.exports = (from, to, path) => {
|
|
12
|
-
const {
|
|
13
|
-
watermark,
|
|
14
|
-
highWatermark,
|
|
15
|
-
} = create(from, to, path);
|
|
12
|
+
const {watermark, highWatermark} = create(from, to, path);
|
|
16
13
|
|
|
17
14
|
const program = path.findParent(isProgram) || path;
|
|
18
15
|
|
|
@@ -54,7 +51,10 @@ function init({path, program}) {
|
|
|
54
51
|
|
|
55
52
|
module.exports.add = add;
|
|
56
53
|
function add({path, program, watermark, highWatermark}) {
|
|
57
|
-
init({
|
|
54
|
+
init({
|
|
55
|
+
path,
|
|
56
|
+
program,
|
|
57
|
+
});
|
|
58
58
|
|
|
59
59
|
path?.node[name].add(watermark);
|
|
60
60
|
program.node[name].add(highWatermark);
|
|
@@ -65,9 +65,5 @@ function has({path, program, watermark, highWatermark}) {
|
|
|
65
65
|
if (path.node?.[name].has(watermark) || path.findParent(hasWatermark(watermark)))
|
|
66
66
|
return true;
|
|
67
67
|
|
|
68
|
-
|
|
69
|
-
return true;
|
|
70
|
-
|
|
71
|
-
return false;
|
|
68
|
+
return program.node[name].has(highWatermark);
|
|
72
69
|
}
|
|
73
|
-
|
package/lib/run-fix.js
CHANGED
|
@@ -9,11 +9,16 @@ const isFn = (a) => typeof a === 'function';
|
|
|
9
9
|
const getPath = (path) => path.path || path;
|
|
10
10
|
|
|
11
11
|
const tryToFix = (fix, {path, position, options}) => {
|
|
12
|
-
const [e] = tryCatch(fix, path, {
|
|
12
|
+
const [e] = tryCatch(fix, path, {
|
|
13
|
+
options,
|
|
14
|
+
});
|
|
15
|
+
|
|
13
16
|
const {scope} = path.path || path;
|
|
14
17
|
|
|
15
18
|
if (!e && scope)
|
|
16
|
-
scope
|
|
19
|
+
scope
|
|
20
|
+
.getProgramParent()
|
|
21
|
+
.crawl();
|
|
17
22
|
|
|
18
23
|
if (!e) {
|
|
19
24
|
return;
|
|
@@ -44,4 +49,3 @@ function validate(name, fn) {
|
|
|
44
49
|
if (!isFn(fn))
|
|
45
50
|
throw Error(`☝️ Looks like '${name}' is not a 'function' but '${typeof fn}' with value: '${stringify(fn)}'. More on writing 🐊Putout Plugins: https://git.io/JqcMn`);
|
|
46
51
|
}
|
|
47
|
-
|
package/lib/store.js
CHANGED
|
@@ -35,7 +35,9 @@ module.exports.upStore = createStore({
|
|
|
35
35
|
|
|
36
36
|
module.exports.upListStore = createStore({
|
|
37
37
|
get(map) {
|
|
38
|
-
|
|
38
|
+
const result = values(map).map(notRemoved);
|
|
39
|
+
|
|
40
|
+
return result;
|
|
39
41
|
},
|
|
40
42
|
set(map, name, data) {
|
|
41
43
|
map[name] = map[name] || new Set();
|
|
@@ -79,6 +81,7 @@ function createListStore(returns = id) {
|
|
|
79
81
|
|
|
80
82
|
fn.clear = () => {
|
|
81
83
|
const a = list;
|
|
84
|
+
|
|
82
85
|
list = new Set();
|
|
83
86
|
|
|
84
87
|
return returns(toArray(a));
|
package/lib/super-find.js
CHANGED
|
@@ -8,12 +8,17 @@ const {merge} = babelTraverse.visitors;
|
|
|
8
8
|
|
|
9
9
|
module.exports = function superFind({rule, find, ast, options, template}) {
|
|
10
10
|
const pushItems = [];
|
|
11
|
+
|
|
11
12
|
const push = (a) => {
|
|
12
13
|
pushItems.push(a);
|
|
13
14
|
};
|
|
14
15
|
|
|
15
16
|
const returnItems = find(ast, {
|
|
16
|
-
traverse: traverse({
|
|
17
|
+
traverse: traverse({
|
|
18
|
+
rule,
|
|
19
|
+
options,
|
|
20
|
+
template,
|
|
21
|
+
}),
|
|
17
22
|
generate,
|
|
18
23
|
types,
|
|
19
24
|
push,
|
package/lib/template/index.js
CHANGED
|
@@ -61,6 +61,7 @@ module.exports = ({rule, visitor, options}) => {
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
const [node, type] = parseTemplate(tmpl);
|
|
64
|
+
|
|
64
65
|
const visit = wrapWithCheck({
|
|
65
66
|
rule,
|
|
66
67
|
fn,
|
|
@@ -102,4 +103,3 @@ function wrapWithCheck({rule, nodesInclude, nodesExclude, fn}) {
|
|
|
102
103
|
}
|
|
103
104
|
};
|
|
104
105
|
}
|
|
105
|
-
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/engine-runner",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "17.0.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "Run 🐊Putout plugins",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@babel/traverse": "^7.12.7",
|
|
28
28
|
"@babel/types": "^7.12.7",
|
|
29
|
-
"@putout/compare": "^
|
|
30
|
-
"@putout/engine-parser": "^
|
|
29
|
+
"@putout/compare": "^11.0.0",
|
|
30
|
+
"@putout/engine-parser": "^7.0.0",
|
|
31
31
|
"@putout/operate": "^8.0.0",
|
|
32
32
|
"@putout/operator-declare": "^5.0.0",
|
|
33
33
|
"debug": "^4.1.1",
|
|
@@ -43,7 +43,8 @@
|
|
|
43
43
|
],
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@babel/plugin-codemod-optional-catch-binding": "^7.7.4",
|
|
46
|
-
"
|
|
46
|
+
"@putout/plugin-minify": "*",
|
|
47
|
+
"c8": "^8.0.0",
|
|
47
48
|
"eslint": "^8.0.1",
|
|
48
49
|
"eslint-plugin-n": "^16.0.0",
|
|
49
50
|
"eslint-plugin-putout": "^17.0.0",
|