@putout/plugin-for-of 7.2.0 → 8.1.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.
@@ -1,7 +1,12 @@
1
1
  'use strict';
2
2
 
3
3
  const {types} = require('putout');
4
- const {isVariableDeclaration} = types;
4
+ const {
5
+ isVariableDeclaration,
6
+ isIdentifier,
7
+ isArrayPattern,
8
+ isObjectPattern,
9
+ } = types;
5
10
 
6
11
  module.exports.report = () => `Add missing declaration`;
7
12
 
@@ -12,7 +17,28 @@ module.exports.match = () => ({
12
17
 
13
18
  const bindings = path.scope.getAllBindings();
14
19
 
15
- return !bindings[__a.name];
20
+ if (isIdentifier(__a))
21
+ return !bindings[__a.name];
22
+
23
+ if (isArrayPattern(__a)) {
24
+ for (const element of __a.elements) {
25
+ if (!isIdentifier(element) || bindings[element.name])
26
+ return false;
27
+ }
28
+
29
+ return true;
30
+ }
31
+
32
+ if (isObjectPattern(__a))
33
+ for (const property of __a.properties) {
34
+ if (property.computed)
35
+ return false;
36
+
37
+ if (!isIdentifier(property.key) || bindings[property.key.name])
38
+ return false;
39
+ }
40
+
41
+ return true;
16
42
  },
17
43
  });
18
44
 
@@ -7,8 +7,8 @@ const {
7
7
  } = require('putout');
8
8
 
9
9
  const {
10
- ContinueStatement,
11
10
  isIdentifier,
11
+ continueStatement,
12
12
  } = types;
13
13
 
14
14
  const {
@@ -138,9 +138,9 @@ function fixReturn(path) {
138
138
  const {argument} = path.node;
139
139
 
140
140
  if (!argument)
141
- return replaceWith(path, ContinueStatement());
141
+ return replaceWith(path, continueStatement());
142
142
 
143
- replaceWithMultiple(path, [argument, ContinueStatement()]);
143
+ replaceWithMultiple(path, [argument, continueStatement()]);
144
144
  },
145
145
  });
146
146
  }
@@ -36,11 +36,7 @@ module.exports.traverse = ({push, options}) => ({
36
36
  const [referencePath] = referencePaths;
37
37
  const {parentPath} = referencePath;
38
38
 
39
- const isSameName = parentPath.get('init').isIdentifier({
40
- name,
41
- });
42
-
43
- if (!isSameName)
39
+ if (!parentPath.isVariableDeclarator())
44
40
  return;
45
41
 
46
42
  const idPath = parentPath.get('id');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-for-of",
3
- "version": "7.2.0",
3
+ "version": "8.1.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",
@@ -28,30 +28,30 @@
28
28
  "putout",
29
29
  "putout-plugin",
30
30
  "plugin",
31
- "for-of",
32
- "try-to-catch"
31
+ "for-of"
33
32
  ],
34
33
  "devDependencies": {
34
+ "@putout/eslint-flat": "^2.0.0",
35
35
  "@putout/plugin-conditions": "*",
36
36
  "@putout/plugin-convert-const-to-let": "*",
37
+ "@putout/plugin-remove-console": "*",
37
38
  "@putout/plugin-remove-empty": "*",
38
39
  "@putout/plugin-remove-nested-blocks": "*",
39
40
  "@putout/plugin-remove-unreferenced-variables": "*",
40
41
  "@putout/plugin-remove-unused-variables": "*",
41
42
  "@putout/plugin-remove-useless-arguments": "*",
42
43
  "@putout/plugin-remove-useless-continue": "*",
43
- "@putout/test": "^11.0.0",
44
+ "@putout/test": "^12.0.0",
44
45
  "c8": "^10.0.0",
45
46
  "eslint": "^9.0.0",
46
47
  "eslint-plugin-n": "^17.0.0",
47
- "eslint-plugin-putout": "^23.0.0",
48
- "lerna": "^6.0.1",
48
+ "eslint-plugin-putout": "^25.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": ">=37"
54
+ "putout": ">=38"
55
55
  },
56
56
  "license": "MIT",
57
57
  "engines": {