Skip to content
This repository has been archived by the owner on Aug 18, 2021. It is now read-only.

Support cyclic type declarations (#485) #584

Merged
merged 1 commit into from Sep 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/babylon-to-espree/toAST.js
Expand Up @@ -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;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have some tests for the babylon-to-espress transform? That is surprising to me that this don't have any side effect?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


// flow: prevent "no-undef"
// for "Component" in: "let x: React.Component"
if (path.isQualifiedTypeIdentifier()) {
Expand Down
12 changes: 12 additions & 0 deletions test/non-regression.js
Expand Up @@ -1157,6 +1157,18 @@ describe("verify", () => {
[]
);
});

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", () => {
Expand Down