Merge pull request babel/babel-eslint#121 from hzoo/i-120

don't visit var decl - fixes babel/babel-eslint#120
This commit is contained in:
Henry Zhu 2015-06-05 05:24:20 -04:00
parent 8d3a7244c3
commit 84a8d342f2
2 changed files with 13 additions and 2 deletions

View File

@ -232,7 +232,10 @@ function monkeypatch() {
referencer.prototype.VariableDeclaration = function(node) { referencer.prototype.VariableDeclaration = function(node) {
if (node.declarations) { if (node.declarations) {
for (var i = 0; i < node.declarations.length; i++) { for (var i = 0; i < node.declarations.length; i++) {
checkIdentifierOrVisit.call(this, node.declarations[i].id); var type = node.declarations[i].id.typeAnnotation;
if (type) {
checkIdentifierOrVisit.call(this, type);
}
} }
} }
variableDeclaration.call(this, node); variableDeclaration.call(this, node);

View File

@ -950,7 +950,7 @@ describe("verify", function () {
it("array #9", function () { it("array #9", function () {
verifyAndAssertMessages([ verifyAndAssertMessages([
"let arr = [1, 2, 3];", "let arr = [1, 2, 3];",
"let b = [for (e of arr) String(e)];" "let b = [for (e of arr) String(e)]; b;"
].join("\n"), ].join("\n"),
{ "no-unused-vars": 1, "no-undef": 1 }, { "no-unused-vars": 1, "no-undef": 1 },
[] []
@ -1082,4 +1082,12 @@ describe("verify", function () {
); );
}); });
}); });
it("detects minimal no-unused-vars case #120", function () {
verifyAndAssertMessages(
"var unused;",
{ "no-unused-vars": 1 },
[ "1:4 unused is defined but never used no-unused-vars" ]
)
});
}); });