@putout/plugin-for-of 12.7.0 → 12.7.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.
@@ -5,7 +5,11 @@ const {
5
5
  isObjectProperty,
6
6
  } = types;
7
7
 
8
- const {remove} = operator;
8
+ const {
9
+ remove,
10
+ createTypeChecker,
11
+ } = operator;
12
+
9
13
  const getValue = ({value}) => value;
10
14
 
11
15
  export const report = (path) => {
@@ -29,9 +33,24 @@ function matchForOf(vars, path) {
29
33
  const idPath = path.get('left.declarations.0.id');
30
34
  const elements = getElements(idPath);
31
35
 
32
- return !isAllReferenced(idPath, elements);
36
+ if (isAllReferenced(idPath, elements))
37
+ return false;
38
+
39
+ return isSupportedForOf(idPath, {
40
+ variables: getVariables(path),
41
+ });
33
42
  }
34
43
 
44
+ const hasOneProperty = ({node}) => node.properties.length === 1;
45
+ const isFullyUnreferenced = ({node}, {variables}) => variables.length === node.properties.length;
46
+
47
+ const isSupportedForOf = createTypeChecker([
48
+ ['+: -> !ObjectPattern'],
49
+ ['+', hasOneProperty],
50
+ ['-', isFullyUnreferenced],
51
+ ['+: -> ObjectPattern'],
52
+ ]);
53
+
35
54
  function replaceForOf(vars, path) {
36
55
  const variables = getVariables(path);
37
56
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-for-of",
3
- "version": "12.7.0",
3
+ "version": "12.7.1",
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",