@putout/plugin-for-of 10.0.0 → 10.1.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/reduce/index.js +15 -3
- package/package.json +1 -1
package/lib/reduce/index.js
CHANGED
|
@@ -4,12 +4,16 @@ const {
|
|
|
4
4
|
isBlockStatement,
|
|
5
5
|
isArrayExpression,
|
|
6
6
|
isCallExpression,
|
|
7
|
+
isExportNamedDeclaration,
|
|
7
8
|
} = types;
|
|
8
9
|
|
|
9
10
|
export const report = () => `Use 'for...of' instead of '.reduce()'`;
|
|
10
11
|
|
|
11
12
|
export const match = () => ({
|
|
12
|
-
'const __a = __b.reduce((__c, __d) => __e)': ({__b, __e}) => {
|
|
13
|
+
'const __a = __b.reduce((__c, __d) => __e)': ({__b, __e}, path) => {
|
|
14
|
+
if (isExportNamedDeclaration(path.parentPath))
|
|
15
|
+
return false;
|
|
16
|
+
|
|
13
17
|
if (isArrayExpression(__b))
|
|
14
18
|
return false;
|
|
15
19
|
|
|
@@ -18,13 +22,21 @@ export const match = () => ({
|
|
|
18
22
|
|
|
19
23
|
return !isBlockStatement(__e);
|
|
20
24
|
},
|
|
21
|
-
'const __a = __b.reduceRight((__c, __d) => __e)': ({__b, __e}) => {
|
|
25
|
+
'const __a = __b.reduceRight((__c, __d) => __e)': ({__b, __e}, path) => {
|
|
26
|
+
if (isExportNamedDeclaration(path.parentPath))
|
|
27
|
+
return false;
|
|
28
|
+
|
|
22
29
|
if (isArrayExpression(__b))
|
|
23
30
|
return false;
|
|
24
31
|
|
|
25
32
|
return !isBlockStatement(__e);
|
|
26
33
|
},
|
|
27
|
-
'const __a = __b.reduce((__c, __d) => __e, __f)': ({__e}) =>
|
|
34
|
+
'const __a = __b.reduce((__c, __d) => __e, __f)': ({__e}, path) => {
|
|
35
|
+
if (isExportNamedDeclaration(path.parentPath))
|
|
36
|
+
return false;
|
|
37
|
+
|
|
38
|
+
return !isBlockStatement(__e);
|
|
39
|
+
},
|
|
28
40
|
});
|
|
29
41
|
|
|
30
42
|
export const replace = () => ({
|
package/package.json
CHANGED