Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support flow function type annotation with no parent #14014

Merged
merged 2 commits into from Dec 3, 2021
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: 5 additions & 4 deletions packages/babel-generator/src/generators/flow.ts
Expand Up @@ -290,7 +290,7 @@ export function ExistsTypeAnnotation(this: Printer) {
export function FunctionTypeAnnotation(
this: Printer,
node: t.FunctionTypeAnnotation,
parent: any,
parent: t.Node | void,
) {
this.print(node.typeParameters, node);
this.token("(");
Expand Down Expand Up @@ -321,9 +321,10 @@ export function FunctionTypeAnnotation(

// this node type is overloaded, not sure why but it makes it EXTREMELY annoying
if (
parent.type === "ObjectTypeCallProperty" ||
parent.type === "DeclareFunction" ||
(parent.type === "ObjectTypeProperty" && parent.method)
parent &&
(parent.type === "ObjectTypeCallProperty" ||
parent.type === "DeclareFunction" ||
(parent.type === "ObjectTypeProperty" && parent.method))
) {
this.token(":");
} else {
Expand Down
11 changes: 11 additions & 0 deletions packages/babel-generator/test/index.js
Expand Up @@ -497,6 +497,17 @@ describe("programmatic generation", function () {
expect(output).toBe("interface A {}");
});

it("flow function type annotation with no parent", () => {
const functionTypeAnnotation = t.functionTypeAnnotation(
null,
[],
null,
t.voidTypeAnnotation(),
);
const output = generate(functionTypeAnnotation).code;
expect(output).toBe("() => void");
});

describe("directives", function () {
it("preserves escapes", function () {
const directive = t.directive(
Expand Down