@putout/plugin-for-of 7.1.0 → 7.2.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.
@@ -3,8 +3,11 @@
3
3
  const {types, operator} = require('putout');
4
4
 
5
5
  const {replaceWith, remove} = operator;
6
+ const {
7
+ isAssignmentPattern,
8
+ isObjectPattern,
9
+ } = types;
6
10
 
7
- const {isAssignmentPattern} = types;
8
11
  const isToManyProperties = (a, {maxProperties}) => a.isObjectPattern() && a.node.properties.length > maxProperties;
9
12
  const isAssignment = (a) => isAssignmentPattern(a.value);
10
13
 
@@ -24,9 +27,7 @@ module.exports.traverse = ({push, options}) => ({
24
27
  return;
25
28
 
26
29
  const {scope, node} = varPath;
27
-
28
30
  const {name} = node;
29
-
30
31
  const {references, referencePaths} = scope.bindings[name];
31
32
 
32
33
  if (references !== 1)
@@ -35,11 +36,9 @@ module.exports.traverse = ({push, options}) => ({
35
36
  const [referencePath] = referencePaths;
36
37
  const {parentPath} = referencePath;
37
38
 
38
- const isSameName = parentPath
39
- .get('init')
40
- .isIdentifier({
41
- name,
42
- });
39
+ const isSameName = parentPath.get('init').isIdentifier({
40
+ name,
41
+ });
43
42
 
44
43
  if (!isSameName)
45
44
  return;
@@ -50,6 +49,9 @@ module.exports.traverse = ({push, options}) => ({
50
49
  if (isToManyProperties(idPath, {maxProperties}))
51
50
  return;
52
51
 
52
+ if (isNested(idPath))
53
+ return;
54
+
53
55
  const {properties} = idPath.node;
54
56
 
55
57
  if (idPath.isObjectPattern() && properties.find(isAssignment))
@@ -61,3 +63,15 @@ module.exports.traverse = ({push, options}) => ({
61
63
  });
62
64
  },
63
65
  });
66
+
67
+ function isNested(path) {
68
+ if (!path.isObjectPattern())
69
+ return false;
70
+
71
+ for (const {value} of path.node.properties) {
72
+ if (isObjectPattern(value))
73
+ return true;
74
+ }
75
+
76
+ return false;
77
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-for-of",
3
- "version": "7.1.0",
3
+ "version": "7.2.0",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout plugin adds ability to apply for...of",