Fix flow type spread handling (babel/babel-eslint#465)

This commit is contained in:
Andres Suarez 2017-04-21 11:48:52 -04:00
parent b5c058bf6e
commit 6feaee84e0
4 changed files with 21 additions and 6 deletions

View File

@ -107,7 +107,7 @@ function monkeypatch(modules) {
// loops
callProperties: { type: "loop", values: ["value"] },
indexers: { type: "loop", values: ["key", "value"] },
properties: { type: "loop", values: ["value"] },
properties: { type: "loop", values: ["argument", "value"] },
types: { type: "loop" },
params: { type: "loop" },
// single property
@ -142,7 +142,10 @@ function monkeypatch(modules) {
for (var j = 0; j < nodeProperty.length; j++) {
if (Array.isArray(propertyType.values)) {
for (var k = 0; k < propertyType.values.length; k++) {
checkIdentifierOrVisit.call(this, nodeProperty[j][propertyType.values[k]]);
var loopPropertyNode = nodeProperty[j][propertyType.values[k]];
if (loopPropertyNode) {
checkIdentifierOrVisit.call(this, loopPropertyNode);
}
}
} else {
checkIdentifierOrVisit.call(this, nodeProperty[j]);

View File

@ -15,7 +15,7 @@
"babel-code-frame": "^6.22.0",
"babel-traverse": "^6.23.1",
"babel-types": "^6.23.0",
"babylon": "^6.16.1"
"babylon": "^6.17.0"
},
"scripts": {
"test": "npm run lint && npm run test-only",

View File

@ -574,6 +574,18 @@ describe("verify", () => {
);
});
it("supports type spreading", () => {
verifyAndAssertMessages(
unpad(`
type U = {};
type T = {a: number, ...U, ...V};
`),
{ "no-undef": 1, "no-unused-vars": 1 },
[ "2:6 'T' is defined but never used. no-unused-vars",
"2:31 'V' is not defined. no-undef" ]
);
});
it("1", () => {
verifyAndAssertMessages(
unpad(`

View File

@ -113,9 +113,9 @@ babel-types@^6.15.0, babel-types@^6.23.0:
lodash "^4.2.0"
to-fast-properties "^1.0.1"
babylon@^6.13.0, babylon@^6.15.0, babylon@^6.16.1:
version "6.16.1"
resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.16.1.tgz#30c5a22f481978a9e7f8cdfdf496b11d94b404d3"
babylon@^6.13.0, babylon@^6.15.0, babylon@^6.17.0:
version "6.17.0"
resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.17.0.tgz#37da948878488b9c4e3c4038893fa3314b3fc932"
balanced-match@^0.4.1:
version "0.4.2"