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:
parent
78a2f603ce
commit
22fa8e6f20
@ -72,6 +72,15 @@ var astTransformVisitor = {
|
|||||||
delete node.bound;
|
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"
|
// flow: prevent "no-undef"
|
||||||
// for "Component" in: "let x: React.Component"
|
// for "Component" in: "let x: React.Component"
|
||||||
if (path.isQualifiedTypeIdentifier()) {
|
if (path.isQualifiedTypeIdentifier()) {
|
||||||
|
|||||||
@ -1091,6 +1091,18 @@ describe("verify", () => {
|
|||||||
{ "no-unused-vars": 1, "no-undef": 1 }
|
{ "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", () => {
|
it("class usage", () => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user