@putout/engine-runner 23.4.1 → 23.6.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 +38 -27
- package/lib/replace/watermark.js +1 -1
- package/lib/run-fix.js +2 -1
- package/package.json +1 -1
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
|
@@ -39,27 +39,31 @@ const log = (from, path) => {
|
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
const {keys, entries} = Object;
|
|
42
|
-
|
|
43
42
|
const {stringify} = JSON;
|
|
44
43
|
|
|
45
44
|
const stub = () => [];
|
|
46
45
|
const stubMatch = () => ({});
|
|
47
46
|
const packKeys = (a) => () => keys(a);
|
|
48
|
-
const
|
|
47
|
+
const isObject = (a) => typeof a === 'object';
|
|
49
48
|
|
|
50
49
|
module.exports = ({rule, plugin, msg, options}) => {
|
|
50
|
+
const maybeMatch = plugin.match || stubMatch;
|
|
51
|
+
const match = maybeMatch({
|
|
52
|
+
options,
|
|
53
|
+
});
|
|
54
|
+
|
|
51
55
|
const {
|
|
52
56
|
report,
|
|
53
57
|
exclude = stub,
|
|
54
58
|
replace,
|
|
55
|
-
filter = getFilter(
|
|
59
|
+
filter = getFilter(match),
|
|
56
60
|
} = plugin;
|
|
57
61
|
|
|
58
62
|
const replaceItems = replace({
|
|
59
63
|
options,
|
|
60
64
|
});
|
|
61
65
|
|
|
62
|
-
const fix = getFix(replaceItems);
|
|
66
|
+
const fix = getFix(replaceItems, match);
|
|
63
67
|
const include = packKeys(replaceItems);
|
|
64
68
|
|
|
65
69
|
return {
|
|
@@ -96,9 +100,6 @@ const fix = (from, to, path) => {
|
|
|
96
100
|
if (mark.has())
|
|
97
101
|
return;
|
|
98
102
|
|
|
99
|
-
if (!compare(path, nodeFrom, {findUp: false}))
|
|
100
|
-
return;
|
|
101
|
-
|
|
102
103
|
const waysFrom = findVarsWays(nodeFrom);
|
|
103
104
|
const {node} = path;
|
|
104
105
|
|
|
@@ -138,45 +139,55 @@ const fix = (from, to, path) => {
|
|
|
138
139
|
log(from, newPath);
|
|
139
140
|
};
|
|
140
141
|
|
|
141
|
-
const getFix = (items) => (path) => {
|
|
142
|
-
for (const [from, to] of entries(items))
|
|
143
|
-
|
|
142
|
+
const getFix = (items, match) => (path) => {
|
|
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 = match[from];
|
|
148
|
+
|
|
149
|
+
if (!matchFn || runMatch(path, nodeFrom, matchFn))
|
|
150
|
+
fix(from, to, path);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
144
153
|
};
|
|
145
154
|
|
|
146
|
-
const getFilter = (match
|
|
147
|
-
const all = entries(match
|
|
148
|
-
options,
|
|
149
|
-
}));
|
|
155
|
+
const getFilter = (match) => (path) => {
|
|
156
|
+
const all = entries(match);
|
|
150
157
|
|
|
151
158
|
for (const [from, matchProperty] of all) {
|
|
152
159
|
const nodeFrom = template.ast(from);
|
|
153
160
|
|
|
154
|
-
if (!compare(path.node, nodeFrom))
|
|
161
|
+
if (!compare(path.node, nodeFrom, {findUp: false}))
|
|
155
162
|
continue;
|
|
156
163
|
|
|
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);
|
|
164
|
+
return runMatch(path, nodeFrom, matchProperty);
|
|
168
165
|
}
|
|
169
166
|
|
|
170
167
|
return true;
|
|
171
168
|
};
|
|
172
169
|
|
|
170
|
+
function runMatch(path, nodeFrom, matchProperty) {
|
|
171
|
+
const waysFrom = findVarsWays(nodeFrom);
|
|
172
|
+
const {node} = path;
|
|
173
|
+
|
|
174
|
+
const values = getValues({
|
|
175
|
+
waysFrom,
|
|
176
|
+
node,
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
validateMatchProperty(matchProperty);
|
|
180
|
+
|
|
181
|
+
return matchProperty(values, path);
|
|
182
|
+
}
|
|
183
|
+
|
|
173
184
|
function parseTo(to, values, path) {
|
|
174
185
|
const toStr = isFn(to) ? to(values, path) : to;
|
|
175
186
|
|
|
176
187
|
if (!toStr)
|
|
177
188
|
return null;
|
|
178
189
|
|
|
179
|
-
if (
|
|
190
|
+
if (isObject(toStr) && toStr.type) {
|
|
180
191
|
toStr.__putout_replace_cooked = true;
|
|
181
192
|
return toStr;
|
|
182
193
|
}
|
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