@putout/plugin-for-of 12.4.2 → 12.5.1
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 +1 -1
- package/lib/map/index.js +33 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,6 +25,7 @@ npm i @putout/plugin-for-of
|
|
|
25
25
|
- ✅ [for-in-positive](#for-in-positive);
|
|
26
26
|
- ✅ [for-length](#for-length);
|
|
27
27
|
- ✅ [for-n](#for-n);
|
|
28
|
+
- ✅ [from-while](#from-while);
|
|
28
29
|
- ✅ [map](#map);
|
|
29
30
|
- ✅ [reduce](#reduce);
|
|
30
31
|
- ✅ [remove-unused-variables](#remove-unused-variables);
|
|
@@ -32,7 +33,6 @@ npm i @putout/plugin-for-of
|
|
|
32
33
|
- ✅ [remove-useless-array-from](#remove-useless-array-from);
|
|
33
34
|
- ✅ [remove-useless-variables](#remove-useless-variables);
|
|
34
35
|
- ✅ [to-for-n](#to-for-n);
|
|
35
|
-
- ✅ [from-while](#from-while);
|
|
36
36
|
|
|
37
37
|
## Configuration
|
|
38
38
|
|
package/lib/map/index.js
CHANGED
|
@@ -44,7 +44,12 @@ export const match = () => ({
|
|
|
44
44
|
|
|
45
45
|
return !isArrayPattern(__a);
|
|
46
46
|
},
|
|
47
|
-
'__a = __b.map((__c) => __d)': ({__b}) =>
|
|
47
|
+
'__a = __b.map((__c) => __d)': ({__a, __b}) => {
|
|
48
|
+
if (compare(__a, __b))
|
|
49
|
+
return false;
|
|
50
|
+
|
|
51
|
+
return !isCallExpression(__b);
|
|
52
|
+
},
|
|
48
53
|
});
|
|
49
54
|
|
|
50
55
|
export const replace = () => ({
|
|
@@ -57,14 +62,7 @@ export const replace = () => ({
|
|
|
57
62
|
'const __a = __b.map((__c) => __d)': ({__a, __d}, path) => {
|
|
58
63
|
if (isBlockStatement(__d)) {
|
|
59
64
|
path.traverse({
|
|
60
|
-
ReturnStatement(
|
|
61
|
-
const {argument} = path.node;
|
|
62
|
-
|
|
63
|
-
replaceWith(path, createPush({
|
|
64
|
-
ARRAY: __a,
|
|
65
|
-
ARGUMENT: argument,
|
|
66
|
-
}));
|
|
67
|
-
},
|
|
65
|
+
ReturnStatement: createReplaceWithPush(__a),
|
|
68
66
|
});
|
|
69
67
|
return `{
|
|
70
68
|
const __a = [];
|
|
@@ -79,10 +77,31 @@ export const replace = () => ({
|
|
|
79
77
|
}
|
|
80
78
|
}`;
|
|
81
79
|
},
|
|
82
|
-
'__a = __b.map((__c) => __d)':
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
80
|
+
'__a = __b.map((__c) => __d)': ({__a, __d}, path) => {
|
|
81
|
+
if (isBlockStatement(__d)) {
|
|
82
|
+
path.traverse({
|
|
83
|
+
ReturnStatement: createReplaceWithPush(__a),
|
|
84
|
+
});
|
|
85
|
+
return `{
|
|
86
|
+
__a = [];
|
|
87
|
+
for (const __c of __b) __d;
|
|
88
|
+
}`;
|
|
86
89
|
}
|
|
87
|
-
|
|
90
|
+
|
|
91
|
+
return `{
|
|
92
|
+
__a = [];
|
|
93
|
+
for (const __c of __b) {
|
|
94
|
+
__a.push(__d);
|
|
95
|
+
}
|
|
96
|
+
}`;
|
|
97
|
+
},
|
|
88
98
|
});
|
|
99
|
+
|
|
100
|
+
const createReplaceWithPush = (__a) => (path) => {
|
|
101
|
+
const {argument} = path.node;
|
|
102
|
+
|
|
103
|
+
replaceWith(path, createPush({
|
|
104
|
+
ARRAY: __a,
|
|
105
|
+
ARGUMENT: argument,
|
|
106
|
+
}));
|
|
107
|
+
};
|
package/package.json
CHANGED