From f69c5496c60832615be413a775c22546fd244182 Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Tue, 23 May 2017 13:14:13 -0700 Subject: [PATCH] Break if the first group has an end of line comment (#1681) This was unstable --- src/printer.js | 1 + .../__snapshots__/jsfmt.spec.js.snap | 21 +++++++++++++++++++ tests/method-chain/comment.js | 11 ++++++++++ 3 files changed, 33 insertions(+) diff --git a/src/printer.js b/src/printer.js index 58bd2be6..6ba4e5d7 100644 --- a/src/printer.js +++ b/src/printer.js @@ -3347,6 +3347,7 @@ function printMemberChain(path, options, print) { const printedGroups = groups.map(printGroup); const oneLine = concat(printedGroups); const hasComment = + groups[0][groups[0].length - 1].node.comments || (groups.length >= 2 && groups[1][0].node.comments) || (groups.length >= 3 && groups[2][0].node.comments); diff --git a/tests/method-chain/__snapshots__/jsfmt.spec.js.snap b/tests/method-chain/__snapshots__/jsfmt.spec.js.snap index ab221072..0939ce35 100644 --- a/tests/method-chain/__snapshots__/jsfmt.spec.js.snap +++ b/tests/method-chain/__snapshots__/jsfmt.spec.js.snap @@ -230,6 +230,17 @@ Something // $FlowFixMe(>=0.41.0) .getInstance(this.props.dao) .getters() + +// Warm-up first +measure() + .then(() => { + SomethingLong(); + }); + +measure() // Warm-up first + .then(() => { + SomethingLong(); + }); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ function f() { return ( @@ -257,6 +268,16 @@ Something .getInstance(this.props.dao) .getters(); +// Warm-up first +measure().then(() => { + SomethingLong(); +}); + +measure() // Warm-up first + .then(() => { + SomethingLong(); + }); + `; exports[`first_long.js 1`] = ` diff --git a/tests/method-chain/comment.js b/tests/method-chain/comment.js index bb5c8a43..2c81c23c 100644 --- a/tests/method-chain/comment.js +++ b/tests/method-chain/comment.js @@ -22,3 +22,14 @@ Something // $FlowFixMe(>=0.41.0) .getInstance(this.props.dao) .getters() + +// Warm-up first +measure() + .then(() => { + SomethingLong(); + }); + +measure() // Warm-up first + .then(() => { + SomethingLong(); + });