Skip to content

Commit

Permalink
Do not merge member chain if there's a comment in-between (#1218)
Browse files Browse the repository at this point in the history
Fixes #1198
  • Loading branch information
vjeux committed Apr 13, 2017
1 parent 5d8ffd0 commit 4a4e181
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/printer.js
Expand Up @@ -2731,11 +2731,12 @@ function printMemberChain(path, options, print) {
// letter, just a sequence of _$ or this. The rationale is that they are
// likely to be factories.
const shouldMerge =
groups.length >= 2 &&
!groups[1][0].node.comments &&
groups[0].length === 1 &&
(groups[0][0].node.type === "ThisExpression" ||
(groups[0][0].node.type === "Identifier" &&
groups[0][0].node.name.match(/(^[A-Z])|^[_$]+$/))) &&
groups.length >= 2;
groups[0][0].node.name.match(/(^[A-Z])|^[_$]+$/)));

function printGroup(printedGroup) {
return concat(printedGroup.map(tuple => tuple.printed));
Expand Down
10 changes: 10 additions & 0 deletions tests/method-chain/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -165,6 +165,11 @@ _.a(
_.a(
a
) /* very very very very very very very long such that it is longer than 80 columns */.a();
Something
// $FlowFixMe(>=0.41.0)
.getInstance(this.props.dao)
.getters()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function f() {
return (
Expand All @@ -187,6 +192,11 @@ _.a(
a
) /* very very very very very very very long such that it is longer than 80 columns */.a();
Something
// $FlowFixMe(>=0.41.0)
.getInstance(this.props.dao)
.getters();
`;

exports[`first_long.js 1`] = `
Expand Down
5 changes: 5 additions & 0 deletions tests/method-chain/comment.js
Expand Up @@ -17,3 +17,8 @@ _.a(
_.a(
a
) /* very very very very very very very long such that it is longer than 80 columns */.a();

Something
// $FlowFixMe(>=0.41.0)
.getInstance(this.props.dao)
.getters()

0 comments on commit 4a4e181

Please sign in to comment.