@putout/engine-runner 23.4.0 → 23.5.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/lib/merge-visitors.js +1 -4
- package/lib/replace/find-path.js +7 -2
- package/lib/replace/index.js +32 -19
- package/lib/replace/watermark.js +1 -1
- package/lib/run-fix.js +2 -1
- package/package.json +2 -2
package/lib/merge-visitors.js
CHANGED
package/lib/replace/find-path.js
CHANGED
|
@@ -16,10 +16,13 @@ module.exports = (parentPath) => {
|
|
|
16
16
|
|
|
17
17
|
return path.join('.');
|
|
18
18
|
};
|
|
19
|
+
|
|
19
20
|
function findKey(path, parent) {
|
|
20
21
|
const {node} = path;
|
|
22
|
+
let key;
|
|
23
|
+
let value;
|
|
21
24
|
|
|
22
|
-
for (
|
|
25
|
+
for ([key, value] of entries(parent)) {
|
|
23
26
|
if (isArray(value)) {
|
|
24
27
|
const index = value.indexOf(node);
|
|
25
28
|
|
|
@@ -30,6 +33,8 @@ function findKey(path, parent) {
|
|
|
30
33
|
}
|
|
31
34
|
|
|
32
35
|
if (value === node)
|
|
33
|
-
|
|
36
|
+
break;
|
|
34
37
|
}
|
|
38
|
+
|
|
39
|
+
return key;
|
|
35
40
|
}
|
package/lib/replace/index.js
CHANGED
|
@@ -59,7 +59,7 @@ module.exports = ({rule, plugin, msg, options}) => {
|
|
|
59
59
|
options,
|
|
60
60
|
});
|
|
61
61
|
|
|
62
|
-
const fix = getFix(replaceItems);
|
|
62
|
+
const fix = getFix(replaceItems, plugin.match, options);
|
|
63
63
|
const include = packKeys(replaceItems);
|
|
64
64
|
|
|
65
65
|
return {
|
|
@@ -96,9 +96,6 @@ const fix = (from, to, path) => {
|
|
|
96
96
|
if (mark.has())
|
|
97
97
|
return;
|
|
98
98
|
|
|
99
|
-
if (!compare(path, nodeFrom, {findUp: false}))
|
|
100
|
-
return;
|
|
101
|
-
|
|
102
99
|
const waysFrom = findVarsWays(nodeFrom);
|
|
103
100
|
const {node} = path;
|
|
104
101
|
|
|
@@ -138,9 +135,21 @@ const fix = (from, to, path) => {
|
|
|
138
135
|
log(from, newPath);
|
|
139
136
|
};
|
|
140
137
|
|
|
141
|
-
const getFix = (items) => (path) => {
|
|
142
|
-
|
|
143
|
-
|
|
138
|
+
const getFix = (items, match = stubMatch, options) => (path) => {
|
|
139
|
+
const initedMatch = match({
|
|
140
|
+
options,
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
for (const [from, to] of entries(items)) {
|
|
144
|
+
const nodeFrom = template.ast(from);
|
|
145
|
+
|
|
146
|
+
if (compare(path, nodeFrom, {findUp: false})) {
|
|
147
|
+
const matchFn = initedMatch[from];
|
|
148
|
+
|
|
149
|
+
if (!matchFn || runMatch(path, nodeFrom, matchFn))
|
|
150
|
+
fix(from, to, path);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
144
153
|
};
|
|
145
154
|
|
|
146
155
|
const getFilter = (match = stubMatch, options) => (path) => {
|
|
@@ -151,25 +160,29 @@ const getFilter = (match = stubMatch, options) => (path) => {
|
|
|
151
160
|
for (const [from, matchProperty] of all) {
|
|
152
161
|
const nodeFrom = template.ast(from);
|
|
153
162
|
|
|
154
|
-
if (!compare(path.node, nodeFrom))
|
|
163
|
+
if (!compare(path.node, nodeFrom, {findUp: false}))
|
|
155
164
|
continue;
|
|
156
165
|
|
|
157
|
-
|
|
158
|
-
const {node} = path;
|
|
159
|
-
|
|
160
|
-
const values = getValues({
|
|
161
|
-
waysFrom,
|
|
162
|
-
node,
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
validateMatchProperty(matchProperty);
|
|
166
|
-
|
|
167
|
-
return matchProperty(values, path);
|
|
166
|
+
return runMatch(path, nodeFrom, matchProperty);
|
|
168
167
|
}
|
|
169
168
|
|
|
170
169
|
return true;
|
|
171
170
|
};
|
|
172
171
|
|
|
172
|
+
function runMatch(path, nodeFrom, matchProperty) {
|
|
173
|
+
const waysFrom = findVarsWays(nodeFrom);
|
|
174
|
+
const {node} = path;
|
|
175
|
+
|
|
176
|
+
const values = getValues({
|
|
177
|
+
waysFrom,
|
|
178
|
+
node,
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
validateMatchProperty(matchProperty);
|
|
182
|
+
|
|
183
|
+
return matchProperty(values, path);
|
|
184
|
+
}
|
|
185
|
+
|
|
173
186
|
function parseTo(to, values, path) {
|
|
174
187
|
const toStr = isFn(to) ? to(values, path) : to;
|
|
175
188
|
|
package/lib/replace/watermark.js
CHANGED
|
@@ -11,7 +11,7 @@ const hasWatermark = (watermark) => (path) => path.node?.[name]?.has(watermark);
|
|
|
11
11
|
|
|
12
12
|
module.exports = (from, to, path) => {
|
|
13
13
|
const {watermark, highWatermark} = create(from, to, path);
|
|
14
|
-
const program = path.findParent(isProgram)
|
|
14
|
+
const program = path.findParent(isProgram);
|
|
15
15
|
const options = {
|
|
16
16
|
watermark,
|
|
17
17
|
highWatermark,
|
package/lib/run-fix.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/engine-runner",
|
|
3
|
-
"version": "23.
|
|
3
|
+
"version": "23.5.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "Run 🐊Putout plugins",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"@putout/plugin-filesystem": "^8.0.1",
|
|
39
39
|
"debug": "^4.1.1",
|
|
40
40
|
"fullstore": "^3.0.0",
|
|
41
|
-
"jessy": "^
|
|
41
|
+
"jessy": "^4.0.0",
|
|
42
42
|
"nessy": "^5.2.0",
|
|
43
43
|
"once": "^1.4.0",
|
|
44
44
|
"try-catch": "^3.0.0",
|