@putout/plugin-for-of 12.6.5 → 12.7.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.
@@ -5,13 +5,14 @@ import {
5
5
  } from 'putout';
6
6
 
7
7
  const {
8
+ isFunction,
8
9
  isIdentifier,
9
10
  continueStatement,
10
- isReturnStatement,
11
11
  } = types;
12
12
 
13
13
  const {
14
14
  compare,
15
+ createTypeChecker,
15
16
  getTemplateValues,
16
17
  replaceWith,
17
18
  replaceWithMultiple,
@@ -29,7 +30,19 @@ const forOfEntriesTemplate = template(`
29
30
  `);
30
31
 
31
32
  const {keys} = Object;
32
- const isRoot = (path) => path.isFunction() || path.isProgram();
33
+
34
+ const isRoot = createTypeChecker([
35
+ ['+', isFunction],
36
+ ['+: -> Program'],
37
+ ]);
38
+
39
+ const isSupportedParent = createTypeChecker([
40
+ '-: parentPath -> ReturnStatement',
41
+ '-: parentPath -> SequenceExpression',
42
+ '-: parentPath -> ConditionalExpression',
43
+ '-: parentPath -> VariableDeclarator',
44
+ '+: -> +',
45
+ ]);
33
46
 
34
47
  export const report = () => `Use 'for-of' instead of 'forEach()'`;
35
48
 
@@ -93,18 +106,7 @@ export const fix = (path) => {
93
106
  export const traverse = ({push}) => ({
94
107
  '__.forEach.call(__a, (__b) => __body)': push,
95
108
  '__.forEach(__args)': (path) => {
96
- const {parentPath} = path;
97
-
98
- if (isReturnStatement(parentPath))
99
- return;
100
-
101
- if (parentPath.isSequenceExpression())
102
- return;
103
-
104
- if (parentPath.isConditionalExpression())
105
- return;
106
-
107
- if (parentPath.isVariableDeclarator())
109
+ if (!isSupportedParent(path))
108
110
  return;
109
111
 
110
112
  const objectPath = path.get('callee.object');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-for-of",
3
- "version": "12.6.5",
3
+ "version": "12.7.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",