Support flow function type annotation with no parent (#14014)
This commit is contained in:
parent
f4236f43a1
commit
4079ee519f
@ -290,7 +290,7 @@ export function ExistsTypeAnnotation(this: Printer) {
|
|||||||
export function FunctionTypeAnnotation(
|
export function FunctionTypeAnnotation(
|
||||||
this: Printer,
|
this: Printer,
|
||||||
node: t.FunctionTypeAnnotation,
|
node: t.FunctionTypeAnnotation,
|
||||||
parent: any,
|
parent: t.Node | void,
|
||||||
) {
|
) {
|
||||||
this.print(node.typeParameters, node);
|
this.print(node.typeParameters, node);
|
||||||
this.token("(");
|
this.token("(");
|
||||||
@ -321,9 +321,10 @@ export function FunctionTypeAnnotation(
|
|||||||
|
|
||||||
// this node type is overloaded, not sure why but it makes it EXTREMELY annoying
|
// this node type is overloaded, not sure why but it makes it EXTREMELY annoying
|
||||||
if (
|
if (
|
||||||
parent.type === "ObjectTypeCallProperty" ||
|
parent &&
|
||||||
parent.type === "DeclareFunction" ||
|
(parent.type === "ObjectTypeCallProperty" ||
|
||||||
(parent.type === "ObjectTypeProperty" && parent.method)
|
parent.type === "DeclareFunction" ||
|
||||||
|
(parent.type === "ObjectTypeProperty" && parent.method))
|
||||||
) {
|
) {
|
||||||
this.token(":");
|
this.token(":");
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -497,6 +497,17 @@ describe("programmatic generation", function () {
|
|||||||
expect(output).toBe("interface A {}");
|
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 () {
|
describe("directives", function () {
|
||||||
it("preserves escapes", function () {
|
it("preserves escapes", function () {
|
||||||
const directive = t.directive(
|
const directive = t.directive(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user