Merge pull request babel/babel-eslint#143 from hzoo/i-142
only visit properties in object destructuring when there is a SpreadP…
This commit is contained in:
parent
78a7af3c0a
commit
4e884f439e
@ -172,7 +172,7 @@ var astTransformVisitor = {
|
|||||||
noScope: true,
|
noScope: true,
|
||||||
exit: function (node) { /* parent */
|
exit: function (node) { /* parent */
|
||||||
if (this.isSpreadProperty()) {
|
if (this.isSpreadProperty()) {
|
||||||
node.type = "Property";
|
node.type = "SpreadProperty";
|
||||||
node.kind = "init";
|
node.kind = "init";
|
||||||
node.computed = true;
|
node.computed = true;
|
||||||
node.key = node.value = node.argument;
|
node.key = node.value = node.argument;
|
||||||
|
|||||||
@ -264,12 +264,19 @@ function monkeypatch() {
|
|||||||
checkIdentifierOrVisit.call(this, typeAnnotation);
|
checkIdentifierOrVisit.call(this, typeAnnotation);
|
||||||
}
|
}
|
||||||
if (id.type === "ObjectPattern") {
|
if (id.type === "ObjectPattern") {
|
||||||
|
// check if object destructuring has a spread
|
||||||
|
var hasSpread = id.properties.filter(function(p) {
|
||||||
|
return p.type === "SpreadProperty"
|
||||||
|
});
|
||||||
|
// visit properties if so
|
||||||
|
if (hasSpread.length > 0) {
|
||||||
for (var j = 0; j < id.properties.length; j++) {
|
for (var j = 0; j < id.properties.length; j++) {
|
||||||
this.visit(id.properties[j]);
|
this.visit(id.properties[j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
variableDeclaration.call(this, node);
|
variableDeclaration.call(this, node);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1171,4 +1171,12 @@ describe("verify", function () {
|
|||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("detects no-unused-vars with object destructuring #142", function () {
|
||||||
|
verifyAndAssertMessages(
|
||||||
|
"const {Bacona} = require('baconjs')",
|
||||||
|
{ "no-undef": 1, "no-unused-vars": 1 },
|
||||||
|
[ "1:7 Bacona is defined but never used no-unused-vars" ]
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user