From 82d6e0b4ab5c96f8373c70d30aed9548a4a21405 Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Mon, 20 Mar 2017 09:33:42 -0700 Subject: [PATCH] Unrestrict flow union comments check (#1040) I was being very careful by checking all the surrounding types but it actually turns out we want this behavior all the time. Fixes #931 --- src/comments.js | 6 +-- .../comments/__snapshots__/jsfmt.spec.js.snap | 40 +++++++++++++++++++ tests/comments/flow_union.js | 10 +++++ 3 files changed, 51 insertions(+), 5 deletions(-) diff --git a/src/comments.js b/src/comments.js index 101044ea..efcb72d9 100644 --- a/src/comments.js +++ b/src/comments.js @@ -580,11 +580,7 @@ function handleUnionTypeComments( ) { if ( enclosingNode && - enclosingNode.type === "UnionTypeAnnotation" && - precedingNode && - precedingNode.type === "ObjectTypeAnnotation" && - followingNode && - followingNode.type === "ObjectTypeAnnotation" + enclosingNode.type === "UnionTypeAnnotation" ) { addTrailingComment(precedingNode, comment); return true; diff --git a/tests/comments/__snapshots__/jsfmt.spec.js.snap b/tests/comments/__snapshots__/jsfmt.spec.js.snap index 5f9b2f9e..6c09b620 100644 --- a/tests/comments/__snapshots__/jsfmt.spec.js.snap +++ b/tests/comments/__snapshots__/jsfmt.spec.js.snap @@ -352,6 +352,16 @@ exports[`flow_union.js 1`] = ` | {type: \\"Failed\\", error: E, errorMsg: EM} // Uploading to aws3 and CreatePostMutation succeeded | {type: \\"Success\\", data: D}; + +type UploadState + // The upload hasnt begun yet + = A + // The upload timed out + | B + // Failed somewhere on the line + | C + // Uploading to aws3 and CreatePostMutation succeeded + | D; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ type UploadState = // The upload hasnt begun yet @@ -362,6 +372,16 @@ type UploadState = | { type: \\"Failed\\", error: E, errorMsg: EM } // Uploading to aws3 and CreatePostMutation succeeded | { type: \\"Success\\", data: D }; + +type UploadState = + // The upload hasnt begun yet + | A + // The upload timed out + | B + // Failed somewhere on the line + | C + // Uploading to aws3 and CreatePostMutation succeeded + | D; " `; @@ -375,6 +395,16 @@ exports[`flow_union.js 2`] = ` | {type: \\"Failed\\", error: E, errorMsg: EM} // Uploading to aws3 and CreatePostMutation succeeded | {type: \\"Success\\", data: D}; + +type UploadState + // The upload hasnt begun yet + = A + // The upload timed out + | B + // Failed somewhere on the line + | C + // Uploading to aws3 and CreatePostMutation succeeded + | D; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ type UploadState = // The upload hasnt begun yet @@ -385,6 +415,16 @@ type UploadState = | { type: \\"Failed\\", error: E, errorMsg: EM } // Uploading to aws3 and CreatePostMutation succeeded | { type: \\"Success\\", data: D }; + +type UploadState = + // The upload hasnt begun yet + | A + // The upload timed out + | B + // Failed somewhere on the line + | C + // Uploading to aws3 and CreatePostMutation succeeded + | D; " `; diff --git a/tests/comments/flow_union.js b/tests/comments/flow_union.js index d76a0481..9d67d295 100644 --- a/tests/comments/flow_union.js +++ b/tests/comments/flow_union.js @@ -7,3 +7,13 @@ type UploadState | {type: "Failed", error: E, errorMsg: EM} // Uploading to aws3 and CreatePostMutation succeeded | {type: "Success", data: D}; + +type UploadState + // The upload hasnt begun yet + = A + // The upload timed out + | B + // Failed somewhere on the line + | C + // Uploading to aws3 and CreatePostMutation succeeded + | D;