From 32eecabc6d3ab05a288f68fca8791a5e7fb94070 Mon Sep 17 00:00:00 2001 From: Brian Ng Date: Wed, 12 Apr 2017 16:13:34 -0500 Subject: [PATCH] Stabilize comments on ObjectTypeAnnotation (#1214) --- src/comments.js | 9 +++ .../__snapshots__/jsfmt.spec.js.snap | 64 +++++++++++++++++++ tests/flow_comments/object_type_annotation.js | 13 ++++ 3 files changed, 86 insertions(+) create mode 100644 tests/flow_comments/object_type_annotation.js diff --git a/src/comments.js b/src/comments.js index 314b3d3e4..29e272fbf 100644 --- a/src/comments.js +++ b/src/comments.js @@ -219,6 +219,7 @@ function attach(comments, ast, text, options) { handleExportNamedDeclarationComments(enclosingNode, comment) || handleOnlyComments(enclosingNode, ast, comment, isLastComment) || handleClassMethodComments(enclosingNode, comment) || + handleTypeAliasComments(enclosingNode, followingNode, comment) || handleVariableDeclaratorComments(enclosingNode, followingNode, comment) ) { // We're good @@ -734,6 +735,14 @@ function handleClassMethodComments(enclosingNode, comment) { return false; } +function handleTypeAliasComments(enclosingNode, followingNode, comment) { + if (enclosingNode && enclosingNode.type === "TypeAlias") { + addLeadingComment(enclosingNode, comment); + return true; + } + return false; +} + function handleVariableDeclaratorComments( enclosingNode, followingNode, diff --git a/tests/flow_comments/__snapshots__/jsfmt.spec.js.snap b/tests/flow_comments/__snapshots__/jsfmt.spec.js.snap index 345d7e3be..5bd91afe5 100644 --- a/tests/flow_comments/__snapshots__/jsfmt.spec.js.snap +++ b/tests/flow_comments/__snapshots__/jsfmt.spec.js.snap @@ -29,3 +29,67 @@ const beep = (data /*: Object*/) => {}; const beep = (data /*: Object*/, secondData /*: Object*/) => {}; `; + +exports[`object_type_annotation.js 1`] = ` +type Props = // (DispatchProps & StateProps); WHY DON'T YOU WORK FLOW!!!!!!!!! +{ + isPlaying: boolean, +}; + +type Props = { // (DispatchProps & StateProps); WHY DON'T YOU WORK FLOW!!!!!!!!! + isPlaying: boolean +}; + +type Props = { + // (DispatchProps & StateProps); WHY DON'T YOU WORK FLOW!!!!!!!!! + isPlaying: boolean +}; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// (DispatchProps & StateProps); WHY DON'T YOU WORK FLOW!!!!!!!!! +type Props = { + isPlaying: boolean +}; + +type Props = { + // (DispatchProps & StateProps); WHY DON'T YOU WORK FLOW!!!!!!!!! + isPlaying: boolean +}; + +type Props = { + // (DispatchProps & StateProps); WHY DON'T YOU WORK FLOW!!!!!!!!! + isPlaying: boolean +}; + +`; + +exports[`object_type_annotation.js 2`] = ` +type Props = // (DispatchProps & StateProps); WHY DON'T YOU WORK FLOW!!!!!!!!! +{ + isPlaying: boolean, +}; + +type Props = { // (DispatchProps & StateProps); WHY DON'T YOU WORK FLOW!!!!!!!!! + isPlaying: boolean +}; + +type Props = { + // (DispatchProps & StateProps); WHY DON'T YOU WORK FLOW!!!!!!!!! + isPlaying: boolean +}; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// (DispatchProps & StateProps); WHY DON'T YOU WORK FLOW!!!!!!!!! +type Props = { + isPlaying: boolean +}; + +type Props = { + // (DispatchProps & StateProps); WHY DON'T YOU WORK FLOW!!!!!!!!! + isPlaying: boolean +}; + +type Props = { + // (DispatchProps & StateProps); WHY DON'T YOU WORK FLOW!!!!!!!!! + isPlaying: boolean +}; + +`; diff --git a/tests/flow_comments/object_type_annotation.js b/tests/flow_comments/object_type_annotation.js new file mode 100644 index 000000000..248d40570 --- /dev/null +++ b/tests/flow_comments/object_type_annotation.js @@ -0,0 +1,13 @@ +type Props = // (DispatchProps & StateProps); WHY DON'T YOU WORK FLOW!!!!!!!!! +{ + isPlaying: boolean, +}; + +type Props = { // (DispatchProps & StateProps); WHY DON'T YOU WORK FLOW!!!!!!!!! + isPlaying: boolean +}; + +type Props = { + // (DispatchProps & StateProps); WHY DON'T YOU WORK FLOW!!!!!!!!! + isPlaying: boolean +};