@putout/plugin-variables 1.3.1 → 1.5.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.
|
@@ -23,12 +23,12 @@ const {
|
|
|
23
23
|
isFunctionDeclaration,
|
|
24
24
|
isArrayExpression,
|
|
25
25
|
isRestElement,
|
|
26
|
+
isArrayPattern,
|
|
26
27
|
} = types;
|
|
27
28
|
|
|
28
29
|
export default ({use, declare, addParams}) => {
|
|
29
30
|
const traverseObj = traverseObjectExpression(use);
|
|
30
|
-
|
|
31
|
-
const processObj = processObjectPattern({
|
|
31
|
+
const declareObject = processObjectPattern({
|
|
32
32
|
use,
|
|
33
33
|
declare,
|
|
34
34
|
});
|
|
@@ -40,6 +40,7 @@ export default ({use, declare, addParams}) => {
|
|
|
40
40
|
|
|
41
41
|
const traverseTmpl = traverseTemplateLiteral(use);
|
|
42
42
|
const traverseArray = traverseArrayExpression(use);
|
|
43
|
+
const declareArray = traverseArrayExpression(declare);
|
|
43
44
|
|
|
44
45
|
return {
|
|
45
46
|
'ObjectExpression'(path) {
|
|
@@ -63,7 +64,7 @@ export default ({use, declare, addParams}) => {
|
|
|
63
64
|
const param = path.get('param');
|
|
64
65
|
|
|
65
66
|
if (param.isObjectPattern())
|
|
66
|
-
return
|
|
67
|
+
return declareObject(param.get('properties'));
|
|
67
68
|
|
|
68
69
|
if (!param.isIdentifier())
|
|
69
70
|
return;
|
|
@@ -140,7 +141,12 @@ export default ({use, declare, addParams}) => {
|
|
|
140
141
|
|
|
141
142
|
for (const elPath of elements) {
|
|
142
143
|
if (elPath.isObjectPattern()) {
|
|
143
|
-
|
|
144
|
+
declareObject(elPath.get('properties'));
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (elPath.isArrayPattern()) {
|
|
149
|
+
declareArray(elPath.get('elements'));
|
|
144
150
|
continue;
|
|
145
151
|
}
|
|
146
152
|
|
|
@@ -207,7 +213,7 @@ export default ({use, declare, addParams}) => {
|
|
|
207
213
|
use(rightPath, rightPath.node.name);
|
|
208
214
|
},
|
|
209
215
|
|
|
210
|
-
|
|
216
|
+
ArrayExpression(path) {
|
|
211
217
|
const {elements} = path.node;
|
|
212
218
|
|
|
213
219
|
for (const el of elements) {
|
|
@@ -551,7 +557,12 @@ export default ({use, declare, addParams}) => {
|
|
|
551
557
|
|
|
552
558
|
/* istanbul ignore else */
|
|
553
559
|
if (isObjectPattern(node)) {
|
|
554
|
-
|
|
560
|
+
declareObject(paramPath.get('properties'));
|
|
561
|
+
continue;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
if (isArrayPattern(node)) {
|
|
565
|
+
declareArray(paramPath.get('elements'));
|
|
555
566
|
continue;
|
|
556
567
|
}
|
|
557
568
|
}
|
|
@@ -125,7 +125,10 @@ export const traverseArrayExpression = (use) => {
|
|
|
125
125
|
for (const elementPath of elementsPaths) {
|
|
126
126
|
const {node} = elementPath;
|
|
127
127
|
|
|
128
|
-
if (
|
|
128
|
+
if (isIdentifier(node))
|
|
129
|
+
use(elementPath, node.name);
|
|
130
|
+
|
|
131
|
+
if (node.properties)
|
|
129
132
|
traverseObjExpression(elementPath.get('properties'));
|
|
130
133
|
}
|
|
131
134
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-variables",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.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",
|
|
@@ -31,8 +31,7 @@
|
|
|
31
31
|
"plugin",
|
|
32
32
|
"remove",
|
|
33
33
|
"useless",
|
|
34
|
-
"variables"
|
|
35
|
-
"for-of"
|
|
34
|
+
"variables"
|
|
36
35
|
],
|
|
37
36
|
"devDependencies": {
|
|
38
37
|
"@putout/eslint-flat": "^3.0.0",
|
|
@@ -42,15 +41,15 @@
|
|
|
42
41
|
"@putout/plugin-minify": "*",
|
|
43
42
|
"@putout/plugin-nodejs": "*",
|
|
44
43
|
"@putout/plugin-putout": "*",
|
|
45
|
-
"@putout/plugin-remove-useless-array-from": "*",
|
|
46
44
|
"@putout/plugin-reuse-duplicate-init": "*",
|
|
47
45
|
"@putout/test": "^14.0.0",
|
|
48
46
|
"c8": "^10.0.0",
|
|
49
|
-
"eslint": "
|
|
47
|
+
"eslint": "^10.0.0-alpha.0",
|
|
50
48
|
"eslint-plugin-n": "^17.0.0",
|
|
51
49
|
"eslint-plugin-putout": "^29.0.0",
|
|
52
50
|
"just-camel-case": "^6.2.0",
|
|
53
51
|
"madrun": "^11.0.0",
|
|
52
|
+
"montag": "^1.2.1",
|
|
54
53
|
"nodemon": "^3.0.1",
|
|
55
54
|
"supertape": "^11.3.1",
|
|
56
55
|
"try-catch": "^3.0.1"
|