Skip to content

Commit

Permalink
Only break for conditionals (#1350)
Browse files Browse the repository at this point in the history
We only want to break for && and ||, not for ===
  • Loading branch information
vjeux committed Apr 19, 2017
1 parent 076804c commit bae08d4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/printer.js
Expand Up @@ -3205,7 +3205,7 @@ function printBinaryishExpressions(path, print, options, isNested, isInsideParen
// in order to avoid having a small right part like -1 be on its own line.
const parent = path.getParentNode();
const shouldGroup =
!isInsideParenthesis &&
!(isInsideParenthesis && node.type === "LogicalExpression") &&
parent.type !== node.type &&
node.left.type !== node.type &&
node.right.type !== node.type;
Expand Down
8 changes: 8 additions & 0 deletions tests/binary-expressions/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -61,6 +61,9 @@ if (this.hasPlugin("dynamicImports") && this.lookahead().type) {}
if (this.hasPlugin("dynamicImports") && this.lookahead().type === tt.parenLeft) {}
if (this.hasPlugin("dynamicImports") && this.lookahead().type === tt.parenLeft.right) {}
if (VeryVeryVeryVeryVeryVeryVeryVeryLong === VeryVeryVeryVeryVeryVeryVeryVeryLong) {
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if (this.hasPlugin("dynamicImports") && this.lookahead().type) {
}
Expand All @@ -77,6 +80,11 @@ if (
) {
}
if (
VeryVeryVeryVeryVeryVeryVeryVeryLong === VeryVeryVeryVeryVeryVeryVeryVeryLong
) {
}
`;

exports[`inline-object-array.js 1`] = `
Expand Down
3 changes: 3 additions & 0 deletions tests/binary-expressions/if.js
Expand Up @@ -3,3 +3,6 @@ if (this.hasPlugin("dynamicImports") && this.lookahead().type) {}
if (this.hasPlugin("dynamicImports") && this.lookahead().type === tt.parenLeft) {}

if (this.hasPlugin("dynamicImports") && this.lookahead().type === tt.parenLeft.right) {}

if (VeryVeryVeryVeryVeryVeryVeryVeryLong === VeryVeryVeryVeryVeryVeryVeryVeryLong) {
}

0 comments on commit bae08d4

Please sign in to comment.