@putout/plugin-remove-unused-variables
Advanced tools
Comparing version 1.3.1 to 1.4.0
@@ -15,2 +15,9 @@ 'use strict'; | ||
const { | ||
traverseObjectExpression, | ||
traverseArrayExpression, | ||
traverseAssignmentExpression, | ||
traverseTemplateLiteral | ||
} = require('./traverse'); | ||
const {assign} = Object; | ||
@@ -380,99 +387,2 @@ | ||
const traverseObjectPattern = (use) => (propertiesPaths) => { | ||
for (const path of propertiesPaths) { | ||
const { | ||
key, | ||
} = path.node; | ||
if (isIdentifier(key)) { | ||
use(path, key.name); | ||
continue; | ||
} | ||
} | ||
}; | ||
const traverseObjectExpression = (use) => { | ||
const traverseTmpl = traverseTemplateLiteral(use); | ||
return (propertiesPaths) => { | ||
for (const path of propertiesPaths) { | ||
const {node} = path; | ||
const { | ||
value | ||
} = path.node; | ||
if (isIdentifier(value)) { | ||
use(path, value.name); | ||
continue; | ||
} | ||
if (isTemplateLiteral(value)) { | ||
traverseTmpl(path, value.expressions); | ||
continue; | ||
} | ||
if (isSpreadElement(node)) { | ||
use(path, node.argument.name); | ||
continue; | ||
} | ||
if (isObjectExpression(value)) { | ||
const traverseObj = traverseObjectExpression(use); | ||
traverseObj(path.get('value.properties')); | ||
continue; | ||
} | ||
} | ||
}; | ||
}; | ||
const traverseArrayExpression = (use) => { | ||
const traverseObjExpression = traverseObjectExpression(use); | ||
return (elementsPaths) => { | ||
for (const elementPath of elementsPaths) { | ||
const {node} = elementPath; | ||
if (isObjectExpression(node)) | ||
traverseObjExpression(elementPath.get('properties')); | ||
} | ||
}; | ||
}; | ||
const traverseAssignmentExpression = (use) => { | ||
const traverseObjPattern = traverseObjectPattern(use); | ||
const traverseObjExpression = traverseObjectExpression(use); | ||
const traverseTmpl = traverseTemplateLiteral(use); | ||
const traverseArray = traverseArrayExpression(use); | ||
return (path) => { | ||
const {node} = path; | ||
const { | ||
left, | ||
right, | ||
} = node; | ||
if (isIdentifier(left)) | ||
use(path, left.name); | ||
else if (isObjectPattern(left)) | ||
traverseObjPattern(path.get('left.properties')); | ||
if (isIdentifier(right)) | ||
use(path, right.name); | ||
else if (isObjectExpression(right)) | ||
traverseObjExpression(path.get('right.properties')); | ||
else if (isTemplateLiteral(right)) | ||
traverseTmpl(path, right.expressions); | ||
else if (isArrayExpression(right)) | ||
traverseArray(path.get('right.elements')); | ||
}; | ||
}; | ||
const traverseTemplateLiteral = (use) => (path, expressions) => { | ||
for (const exp of expressions) { | ||
if (isIdentifier(exp)) | ||
use(path, exp.name); | ||
} | ||
}; | ||
const removeArrayPatternElement = (elPath) => { | ||
@@ -479,0 +389,0 @@ const {remove} = elPath; |
{ | ||
"name": "@putout/plugin-remove-unused-variables", | ||
"version": "1.3.1", | ||
"version": "1.4.0", | ||
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)", | ||
@@ -17,2 +17,3 @@ "description": "putout plugin adds ability to find and remove unused variables", | ||
"test": "tape 'test/*.js'", | ||
"watch:test": "nodemon -w lib -w test -x \"npm test\"", | ||
"lint": "eslint lib test --ignore-pattern test/fixture", | ||
@@ -37,2 +38,3 @@ "coverage": "nyc npm test" | ||
"just-camel-case": "^4.0.2", | ||
"nodemon": "^1.18.9", | ||
"nyc": "^13.0.1", | ||
@@ -39,0 +41,0 @@ "redrun": "^7.0.2" |
24007
9
604
9