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:
Henry Zhu 2015-07-06 09:36:34 -04:00
parent 8c4adbf98d
commit d9bf8d252e
3 changed files with 18 additions and 2 deletions

View File

@ -172,7 +172,9 @@ var astTransformVisitor = {
noScope: true,
exit: function (node) { /* parent */
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.computed = true;
node.key = node.value = node.argument;

View File

@ -266,7 +266,7 @@ function monkeypatch() {
if (id.type === "ObjectPattern") {
// check if object destructuring has a spread
var hasSpread = id.properties.filter(function(p) {
return p.type === "SpreadProperty"
return p._spread === true;
});
// visit properties if so
if (hasSpread.length > 0) {

View File

@ -1179,4 +1179,18 @@ describe("verify", function () {
[ "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 },
[]
);
});
});