Treat type alias declarationlike function declaration (babel/babel-eslint#584)

A type alias shouldn't trigger a no-use-before-define warning just
like a function declaration.

Cyclic type dependencies are common when using flow.
For instance: type Node<T> = { head: T; tail: Node<T> }

Fixes babel/babel-eslint#485
This commit is contained in:
Joa Ebert 2018-09-25 20:39:43 +02:00
parent 78a2f603ce
commit 22fa8e6f20
2 changed files with 21 additions and 0 deletions

View File

@ -72,6 +72,15 @@ var astTransformVisitor = {
delete node.bound;
}
if (path.isTypeAlias()) {
node.type = "FunctionDeclaration";
node.generator = false;
node.async = false;
node.expression = false;
node.params = [];
node.body = node.right;
}
// flow: prevent "no-undef"
// for "Component" in: "let x: React.Component"
if (path.isQualifiedTypeIdentifier()) {

View File

@ -1091,6 +1091,18 @@ describe("verify", () => {
{ "no-unused-vars": 1, "no-undef": 1 }
);
});
it("cyclic type dependencies #485", () => {
verifyAndAssertMessages(
unpad(`
type Node<T> = { head: T, tail: Node<T> };
type A = B[];
type B = number;
`),
{ "no-use-before-define": 1 },
[]
);
});
});
it("class usage", () => {