@putout/plugin-variables 2.0.0 → 2.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.
@@ -22,7 +22,7 @@ export const fix = (path) => {
22
22
  path.node.kind = 'let';
23
23
  };
24
24
 
25
- export const traverse = ({push}) => ({
25
+ export const traverse = ({push, pathStore}) => ({
26
26
  VariableDeclaration: (path) => {
27
27
  if (path.parentPath.isTSModuleBlock())
28
28
  return;
@@ -53,9 +53,16 @@ export const traverse = ({push}) => ({
53
53
  continue;
54
54
 
55
55
  if (parentPath.node.kind === 'const')
56
- push(binding.path.parentPath);
56
+ pathStore(binding.path.parentPath);
57
57
  }
58
58
  },
59
+ Program: {
60
+ exit() {
61
+ for (const path of pathStore()) {
62
+ push(path);
63
+ }
64
+ },
65
+ },
59
66
  });
60
67
 
61
68
  const isLoop = ({parentPath}) => {
@@ -174,9 +174,12 @@ export default ({use, declare, addParams}) => {
174
174
 
175
175
  const initPath = path.get('init');
176
176
 
177
- if (isIdentifier(init))
177
+ if (isIdentifier(init)) {
178
178
  use(path, init.name);
179
- else if (isArrayExpression(init))
179
+ return;
180
+ }
181
+
182
+ if (isArrayExpression(init))
180
183
  traverseArray(initPath.get('elements'));
181
184
  },
182
185
 
@@ -138,11 +138,13 @@ const useVariable = ({vars}) => (path, name) => {
138
138
 
139
139
  const current = vars[uid];
140
140
 
141
- if (current[name])
141
+ if (current[name]) {
142
142
  current[name].used = true;
143
- else
144
- current[name] = {
145
- declared: false,
146
- used: true,
147
- };
143
+ return;
144
+ }
145
+
146
+ current[name] = {
147
+ declared: false,
148
+ used: true,
149
+ };
148
150
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-variables",
3
- "version": "2.0.0",
3
+ "version": "2.2.0",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout plugin adds ability to find and remove useless",
@@ -44,7 +44,6 @@
44
44
  "@putout/plugin-reuse-duplicate-init": "*",
45
45
  "@putout/plugin-tape": "*",
46
46
  "@putout/test": "^15.0.0",
47
- "c8": "^10.0.0",
48
47
  "eslint": "^10.0.0",
49
48
  "eslint-plugin-n": "^17.0.0",
50
49
  "eslint-plugin-putout": "^31.0.0",
@@ -52,6 +51,7 @@
52
51
  "madrun": "^13.0.0",
53
52
  "montag": "^1.2.1",
54
53
  "nodemon": "^3.0.1",
54
+ "superc8": "^12.0.0",
55
55
  "supertape": "^12.0.0",
56
56
  "try-catch": "^4.0.0"
57
57
  },