Skip to content

Commit

Permalink
handle object destructuring
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorHom committed Jul 29, 2017
1 parent 4251e2a commit f9f6582
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/rules/prefer-const.js
Expand Up @@ -204,11 +204,20 @@ function groupByDestructuring(variables, ignoreReadBeforeAssign, checkingMixedDe
for (const key of identifierMap.keys()) {
const destructureGroup = identifierMap.get(key);
const destructureElement = destructureGroup[0];
let elementsInHost;

if (destructureElement && destructureElement.parent && destructureElement.parent.elements) {
if (destructureElement.parent.elements.length !== destructureGroup.length) {
identifierMap.delete(key);
if (destructureElement && destructureElement.parent) {
if (destructureElement.parent.elements) {
elementsInHost = destructureElement.parent.elements;
}

if (destructureElement.parent.parent.type === "ObjectPattern") {
elementsInHost = destructureGroup[0].parent.parent.properties;
}
}

if (elementsInHost && elementsInHost.length && elementsInHost.length !== destructureGroup.length) {
identifierMap.delete(key);
}
}
}
Expand Down

0 comments on commit f9f6582

Please sign in to comment.