diff --git a/eslint/babel-eslint-parser/acorn-to-esprima.js b/eslint/babel-eslint-parser/acorn-to-esprima.js index 7809f04a1f..8681d04e5d 100644 --- a/eslint/babel-eslint-parser/acorn-to-esprima.js +++ b/eslint/babel-eslint-parser/acorn-to-esprima.js @@ -172,7 +172,7 @@ var astTransformVisitor = { noScope: true, exit: function (node) { /* parent */ if (this.isSpreadProperty()) { - node.type = "Property"; + node.type = "SpreadProperty"; node.kind = "init"; node.computed = true; node.key = node.value = node.argument; diff --git a/eslint/babel-eslint-parser/index.js b/eslint/babel-eslint-parser/index.js index 44893c80e4..e37e5417e3 100644 --- a/eslint/babel-eslint-parser/index.js +++ b/eslint/babel-eslint-parser/index.js @@ -264,8 +264,15 @@ function monkeypatch() { checkIdentifierOrVisit.call(this, typeAnnotation); } if (id.type === "ObjectPattern") { - for (var j = 0; j < id.properties.length; j++) { - this.visit(id.properties[j]); + // 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++) { + this.visit(id.properties[j]); + } } } } diff --git a/eslint/babel-eslint-parser/test/non-regression.js b/eslint/babel-eslint-parser/test/non-regression.js index 6be4343f42..553594df77 100644 --- a/eslint/babel-eslint-parser/test/non-regression.js +++ b/eslint/babel-eslint-parser/test/non-regression.js @@ -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" ] + ); + }); });