fix no-unused-vars issue with spread
Use a private _spread property on Property node instead of SpreadProperty Fixes https://github.com/babel/babel-eslint/issues/142#issuecomment-118707124
This commit is contained in:
parent
8c4adbf98d
commit
d9bf8d252e
@ -172,7 +172,9 @@ var astTransformVisitor = {
|
|||||||
noScope: true,
|
noScope: true,
|
||||||
exit: function (node) { /* parent */
|
exit: function (node) { /* parent */
|
||||||
if (this.isSpreadProperty()) {
|
if (this.isSpreadProperty()) {
|
||||||
node.type = "SpreadProperty";
|
// private var to track if it's a spread property
|
||||||
|
node._spread = true;
|
||||||
|
node.type = "Property";
|
||||||
node.kind = "init";
|
node.kind = "init";
|
||||||
node.computed = true;
|
node.computed = true;
|
||||||
node.key = node.value = node.argument;
|
node.key = node.value = node.argument;
|
||||||
|
|||||||
@ -266,7 +266,7 @@ function monkeypatch() {
|
|||||||
if (id.type === "ObjectPattern") {
|
if (id.type === "ObjectPattern") {
|
||||||
// check if object destructuring has a spread
|
// check if object destructuring has a spread
|
||||||
var hasSpread = id.properties.filter(function(p) {
|
var hasSpread = id.properties.filter(function(p) {
|
||||||
return p.type === "SpreadProperty"
|
return p._spread === true;
|
||||||
});
|
});
|
||||||
// visit properties if so
|
// visit properties if so
|
||||||
if (hasSpread.length > 0) {
|
if (hasSpread.length > 0) {
|
||||||
|
|||||||
@ -1179,4 +1179,18 @@ describe("verify", function () {
|
|||||||
[ "1:7 Bacona is defined but never used no-unused-vars" ]
|
[ "1:7 Bacona is defined but never used no-unused-vars" ]
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("don't warn no-unused-vars with spread #142", function () {
|
||||||
|
verifyAndAssertMessages([
|
||||||
|
"export default function test(data) {",
|
||||||
|
"return {",
|
||||||
|
"foo: 'bar',",
|
||||||
|
"...data",
|
||||||
|
"};",
|
||||||
|
"}",
|
||||||
|
].join("\n"),
|
||||||
|
{ "no-undef": 1, "no-unused-vars": 1 },
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user