@putout/plugin-for-of 6.1.0 → 7.0.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.
@@ -35,6 +35,14 @@ module.exports.filter = (path) => {
35
35
  const [first] = body.body;
36
36
  const {__i, __n} = getTemplateValues(path, forLoopToN);
37
37
 
38
+ const {
39
+ constantViolations,
40
+ references,
41
+ } = path.scope.bindings[__i.name];
42
+
43
+ if (constantViolations.length > 1)
44
+ return false;
45
+
38
46
  if (!compare(first, assignIterable(__i)))
39
47
  return false;
40
48
 
@@ -46,8 +54,6 @@ module.exports.filter = (path) => {
46
54
  if (nBinding.references > 1)
47
55
  return false;
48
56
 
49
- const {references} = path.scope.bindings[__i.name];
50
-
51
57
  return references > 3;
52
58
  };
53
59
 
@@ -43,7 +43,7 @@ module.exports.filter = (path) => {
43
43
 
44
44
  const {references} = path.scope.bindings[__i.name];
45
45
 
46
- return !(references > 3);
46
+ return references <= 3;
47
47
  };
48
48
 
49
49
  module.exports.replace = () => ({
@@ -18,23 +18,23 @@ module.exports.report = (path) => {
18
18
  };
19
19
 
20
20
  module.exports.match = () => ({
21
- 'for (const __array of __b) __c': (vars, path) => match(path),
22
- 'for (const __object of __b) __c': (vars, path) => match(path),
21
+ 'for (const __array of __b) __c': matchForOf,
22
+ 'for (const __object of __b) __c': matchForOf,
23
23
  });
24
24
 
25
25
  module.exports.replace = () => ({
26
- 'for (const __array of __b) __c': (vars, path) => replace(path),
27
- 'for (const __object of __b) __c': (vars, path) => replace(path),
26
+ 'for (const __array of __b) __c': replaceForOf,
27
+ 'for (const __object of __b) __c': replaceForOf,
28
28
  });
29
29
 
30
- function match(path) {
30
+ function matchForOf(vars, path) {
31
31
  const idPath = path.get('left.declarations.0.id');
32
32
  const elements = getElements(idPath);
33
33
 
34
34
  return !isAllReferenced(idPath, elements);
35
35
  }
36
36
 
37
- function replace(path) {
37
+ function replaceForOf(vars, path) {
38
38
  const variables = getVariables(path);
39
39
 
40
40
  for (const currentPath of variables) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-for-of",
3
- "version": "6.1.0",
3
+ "version": "7.0.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",
@@ -11,7 +11,7 @@
11
11
  "changelog": false,
12
12
  "repository": {
13
13
  "type": "git",
14
- "url": "git://github.com/coderaiser/putout.git"
14
+ "url": "git+https://github.com/coderaiser/putout.git"
15
15
  },
16
16
  "scripts": {
17
17
  "test": "madrun test",
@@ -40,18 +40,18 @@
40
40
  "@putout/plugin-remove-unused-variables": "*",
41
41
  "@putout/plugin-remove-useless-arguments": "*",
42
42
  "@putout/plugin-remove-useless-continue": "*",
43
- "@putout/test": "^9.0.0",
44
- "c8": "^9.0.0",
43
+ "@putout/test": "^11.0.0",
44
+ "c8": "^10.0.0",
45
45
  "eslint": "^9.0.0",
46
46
  "eslint-plugin-n": "^17.0.0",
47
- "eslint-plugin-putout": "^22.0.0",
47
+ "eslint-plugin-putout": "^23.0.0",
48
48
  "lerna": "^6.0.1",
49
49
  "madrun": "^10.0.0",
50
50
  "montag": "^1.2.1",
51
51
  "nodemon": "^3.0.1"
52
52
  },
53
53
  "peerDependencies": {
54
- "putout": ">=35"
54
+ "putout": ">=37"
55
55
  },
56
56
  "license": "MIT",
57
57
  "engines": {