@putout/plugin-for-of 1.2.0 → 1.2.2

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.
@@ -1,11 +1,16 @@
1
1
  'use strict';
2
2
 
3
- const {types} = require('putout');
3
+ const {
4
+ types,
5
+ operator,
6
+ } = require('putout');
7
+
4
8
  const {
5
9
  isIdentifier,
6
10
  isObjectProperty,
7
11
  } = types;
8
12
 
13
+ const {remove} = operator;
9
14
  const getValue = ({value}) => value;
10
15
 
11
16
  module.exports.report = (path) => {
@@ -29,9 +34,6 @@ function match(path) {
29
34
  const idPath = path.get('left.declarations.0.id');
30
35
  const elements = getElements(idPath);
31
36
 
32
- if (!isAllIdentifiers(elements))
33
- return false;
34
-
35
37
  if (isAllReferenced(idPath, elements))
36
38
  return false;
37
39
 
@@ -42,7 +44,7 @@ function replace(path) {
42
44
  const variables = getVariables(path);
43
45
 
44
46
  for (const currentPath of variables) {
45
- currentPath.remove();
47
+ remove(currentPath);
46
48
  }
47
49
 
48
50
  return path;
@@ -61,15 +63,6 @@ function getVariables(path) {
61
63
  return result;
62
64
  }
63
65
 
64
- function isAllIdentifiers(array) {
65
- const realArray = array.filter(Boolean);
66
-
67
- const {length} = realArray;
68
- const {length: realLength} = realArray.filter(isIdentifier);
69
-
70
- return length === realLength;
71
- }
72
-
73
66
  function isReferenced({scope}, path) {
74
67
  const {bindings} = scope;
75
68
 
@@ -80,6 +73,10 @@ function isReferenced({scope}, path) {
80
73
  return !current || current.referenced;
81
74
  }
82
75
 
76
+ if (path.isObjectPattern()) {
77
+ return true;
78
+ }
79
+
83
80
  const {node} = path;
84
81
 
85
82
  if (!node)
@@ -90,14 +87,19 @@ function isReferenced({scope}, path) {
90
87
  return bindings[name].referenced;
91
88
  }
92
89
 
93
- function isAllReferenced(path, array) {
90
+ function isAllReferenced(path, nodes) {
94
91
  const {bindings} = path.scope;
95
92
 
96
- for (const {name} of array) {
97
- const current = bindings[name];
98
-
99
- if (!current.referenced)
100
- return false;
93
+ for (const node of nodes) {
94
+ if (isIdentifier(node)) {
95
+ const {name} = node;
96
+ const current = bindings[name];
97
+
98
+ if (!current.referenced)
99
+ return false;
100
+
101
+ continue;
102
+ }
101
103
  }
102
104
 
103
105
  return true;
@@ -136,4 +138,3 @@ function getNames(paths) {
136
138
 
137
139
  return result;
138
140
  }
139
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-for-of",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
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",