Merge pull request babel/babel-eslint#271 from danez/fix-use-before-define

Remove visiting of properties left of spread, fixes babel/babel-eslint#249.
This commit is contained in:
Henry Zhu 2016-03-07 23:09:46 -05:00
parent 6e3aa3357c
commit 217f83fd56
2 changed files with 31 additions and 16 deletions

View File

@ -298,18 +298,6 @@ function monkeypatch() {
if (typeAnnotation) { if (typeAnnotation) {
checkIdentifierOrVisit.call(this, typeAnnotation); checkIdentifierOrVisit.call(this, typeAnnotation);
} }
if (id.type === "ObjectPattern") {
// check if object destructuring has a spread
var hasSpread = id.properties.filter(function(p) {
return p._babelType === "SpreadProperty" || p._babelType === "RestProperty";
});
// visit properties if so
if (hasSpread.length > 0) {
for (var j = 0; j < id.properties.length; j++) {
this.visit(id.properties[j]);
}
}
}
} }
} }
variableDeclaration.call(this, node); variableDeclaration.call(this, node);

View File

@ -1137,18 +1137,45 @@ describe("verify", function () {
); );
}); });
it("visits excluded properties left of spread #95", function () { // This two tests are disabled, as the feature to visit properties when
// there is a spread/rest operator has been removed as it caused problems
// with other rules #249
it.skip("visits excluded properties left of spread #95", function () {
verifyAndAssertMessages( verifyAndAssertMessages(
"var originalObject = {}; var {field1, field2, ...clone} = originalObject;", "var originalObject = {}; var {field1, field2, ...clone} = originalObject;",
{ "no-undef": 1, "no-unused-vars": 1, "no-redeclare": 1 }, { "no-unused-vars": 1 },
[] []
); );
}); });
it("visits excluded properties left of spread #210", function () { it.skip("visits excluded properties left of spread #210", function () {
verifyAndAssertMessages( verifyAndAssertMessages(
"const props = { yo: 'yo' }; const { ...otherProps } = props;", "const props = { yo: 'yo' }; const { ...otherProps } = props;",
{ "no-undef": 1, "no-unused-vars": 1, "no-redeclare": 1 }, { "no-unused-vars": 1 },
[]
);
});
it("does not mark spread variables false-positive", function () {
verifyAndAssertMessages(
"var originalObject = {}; var {field1, field2, ...clone} = originalObject;",
{ "no-undef": 1, "no-redeclare": 1 },
[]
);
});
it("does not mark spread variables false-positive", function () {
verifyAndAssertMessages(
"const props = { yo: 'yo' }; const { ...otherProps } = props;",
{ "no-undef": 1, "no-redeclare": 1 },
[]
);
});
it("does not mark spread variables as use-before-define #249", function () {
verifyAndAssertMessages(
"var originalObject = {}; var {field1, field2, ...clone} = originalObject;",
{ "no-use-before-define": 1 },
[] []
); );
}); });