From 3f8c4d6974e06235e66b91684e14d46b39465f02 Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Thu, 1 Jun 2017 19:02:15 -0700 Subject: [PATCH] Fix yet another form of class with the same ast (#1849) Fixes #1847 --- src/printer.js | 5 +++-- tests/flow_method/__snapshots__/jsfmt.spec.js.snap | 10 ++++++++++ tests/flow_method/method.js | 5 +++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/printer.js b/src/printer.js index a2cbbc223..e04ed7dd0 100644 --- a/src/printer.js +++ b/src/printer.js @@ -1868,9 +1868,10 @@ function genericPrintNoParens(path, options, print, args) { const parentParentParent = path.getParentNode(2); let isArrowFunctionTypeAnnotation = n.type === "TSFunctionType" || - !((!getFlowVariance(parent) && + !((parent.type === "ObjectTypeProperty" && + !getFlowVariance(parent) && !parent.optional && - parent.type === "ObjectTypeProperty") || + util.locStart(parent) === util.locStart(n)) || parent.type === "ObjectTypeCallProperty" || (parentParentParent && parentParentParent.type === "DeclareFunction")); diff --git a/tests/flow_method/__snapshots__/jsfmt.spec.js.snap b/tests/flow_method/__snapshots__/jsfmt.spec.js.snap index 3094aea8e..975277d58 100644 --- a/tests/flow_method/__snapshots__/jsfmt.spec.js.snap +++ b/tests/flow_method/__snapshots__/jsfmt.spec.js.snap @@ -23,6 +23,11 @@ type T = { method(): void }; declare class X { method(): void } declare function f(): void; var f: () => void; + +declare class X { + static deserialize(): mixed, + static deserialize: () => mixed, +} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ type T = { method: () => void }; type T = { method(): void }; @@ -30,4 +35,9 @@ declare class X { method(): void } declare function f(): void; var f: () => void; +declare class X { + static deserialize(): mixed, + static deserialize: () => mixed +} + `; diff --git a/tests/flow_method/method.js b/tests/flow_method/method.js index 405f3fe2b..18ffddfa6 100644 --- a/tests/flow_method/method.js +++ b/tests/flow_method/method.js @@ -3,3 +3,8 @@ type T = { method(): void }; declare class X { method(): void } declare function f(): void; var f: () => void; + +declare class X { + static deserialize(): mixed, + static deserialize: () => mixed, +}