@putout/plugin-for-of 9.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/README.md CHANGED
@@ -61,7 +61,7 @@ npm i @putout/plugin-for-of
61
61
  >
62
62
  > (c) MDN
63
63
 
64
- Chechout in 🐊[**Putout Editor**](https://putout.vercel.app/#/gist/68d114f01384084cc3bec0a5d75f2dfa/0bb5201d36ed27f74728921aca95a04efa35c82d).
64
+ Checkout in 🐊[**Putout Editor**](https://putout.vercel.app/#/gist/68d114f01384084cc3bec0a5d75f2dfa/0bb5201d36ed27f74728921aca95a04efa35c82d).
65
65
 
66
66
  ### ❌ Example of incorrect code
67
67
 
@@ -34,13 +34,16 @@ export const replace = () => ({
34
34
  '__.forEach.call(__a, (__b) => __body)': 'for (const __b of __a) __body',
35
35
  '__.forEach(__args)': (vars, path) => {
36
36
  const {params, body} = path.node.arguments[0];
37
-
38
37
  const item = getItem(params);
39
38
 
40
39
  delete item.typeAnnotation;
41
40
 
42
41
  const {length} = params;
43
42
 
43
+ for (const param of params) {
44
+ delete param.typeAnnotation;
45
+ }
46
+
44
47
  const thisPassed = isIdentifier(params[0], {
45
48
  name: 'this',
46
49
  });
@@ -104,8 +107,7 @@ export const match = () => ({
104
107
  if (path.node.arguments.length === 2 && !path.get('arguments.1').isThisExpression())
105
108
  return false;
106
109
 
107
- // this is the case when "i" declared and "this"
108
- if (params.length >= 3 && params[0].isIdentifier({name: 'this'}))
110
+ if (isIndexWithThis(params))
109
111
  return false;
110
112
 
111
113
  const [paramPath] = params;
@@ -198,3 +200,14 @@ function isForBeforeFnUp(path) {
198
200
 
199
201
  return true;
200
202
  }
203
+
204
+ function isIndexWithThis(params) {
205
+ if (params.length < 3)
206
+ return false;
207
+
208
+ const [first] = params;
209
+
210
+ return first.isIdentifier({
211
+ name: 'this',
212
+ });
213
+ }
@@ -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}) => !isBlockStatement(__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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-for-of",
3
- "version": "9.0.0",
3
+ "version": "10.1.0",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout plugin adds ability to apply for...of",
@@ -41,17 +41,17 @@
41
41
  "@putout/plugin-remove-unused-variables": "*",
42
42
  "@putout/plugin-remove-useless-arguments": "*",
43
43
  "@putout/plugin-remove-useless-continue": "*",
44
- "@putout/test": "^12.0.0",
44
+ "@putout/test": "^14.0.0",
45
45
  "c8": "^10.0.0",
46
46
  "eslint": "^9.0.0",
47
47
  "eslint-plugin-n": "^17.0.0",
48
- "eslint-plugin-putout": "^26.0.0",
48
+ "eslint-plugin-putout": "^28.0.0",
49
49
  "madrun": "^11.0.0",
50
50
  "montag": "^1.2.1",
51
51
  "nodemon": "^3.0.1"
52
52
  },
53
53
  "peerDependencies": {
54
- "putout": ">=39"
54
+ "putout": ">=40"
55
55
  },
56
56
  "license": "MIT",
57
57
  "engines": {