Merge pull request babel/babel-eslint#118 from hzoo/poly-types

add flow exceptions for polymorphic types (<A>) - Ref babel/babel-eslint#109
This commit is contained in:
Henry Zhu 2015-06-03 17:11:28 -04:00
parent ade0b3b21b
commit 6a2938deaa
2 changed files with 24 additions and 0 deletions

View File

@ -163,6 +163,10 @@ function monkeypatch() {
if (node.typeAnnotation) {
visitTypeAnnotation.call(this, node.typeAnnotation);
} else if (node.type === "Identifier") {
// exception for polymorphic types: <T>, <A>, etc
if (node.name.length === 1 && node.name === node.name.toUpperCase()) {
return;
}
this.visit(node);
} else {
visitTypeAnnotation.call(this, node);

View File

@ -296,6 +296,26 @@ describe("verify", function () {
);
});
it("polymorphpic types #109", function () {
verifyAndAssertMessages([
"export default function groupByEveryN<T>(array: Array<T>, n: number): Array<Array<?T>> {}"
].join("\n"),
{ "no-unused-vars": 1, "no-undef": 1 },
[]
);
});
it("types definition from import", function () {
verifyAndAssertMessages([
"import type Promise from 'bluebird';",
"type Operation = () => Promise;",
"x: Operation;"
].join("\n"),
{ "no-unused-vars": 1, "no-undef": 1 },
[]
);
});
it("1", function () {
verifyAndAssertMessages(
[