Allow to break after = for strings (#1142)

This is not a general fix but it solves some issues that people are seeing where prettier goes > 80 columns.

Fixes #1141
Also fixes part of #1110
master
Christopher Chedeau 2017-04-07 10:51:02 -07:00 committed by GitHub
parent 6b806d4411
commit 41dee70795
5 changed files with 19 additions and 2 deletions

View File

@ -3070,7 +3070,12 @@ function printAssignment(printedLeft, operator, rightNode, printedRight, options
printed = indent(
concat([hardline, printedRight])
);
} else if (isBinaryish(rightNode) && !shouldInlineLogicalExpression(rightNode)) {
} else if (
(isBinaryish(rightNode) && !shouldInlineLogicalExpression(rightNode)) ||
rightNode.type === "StringLiteral" ||
(rightNode.type === "Literal" &&
typeof rightNode.value === "string")
) {
printed = indent(
concat([line, printedRight])
);

View File

@ -7,6 +7,7 @@ export var name: \\"subdir/custom_resolve_dir/testproj2\\" = \\"subdir/custom_re
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
export var name: \\"subdir/custom_resolve_dir/testproj2\\" = \\"subdir/custom_resolve_dir/testproj2\\";
export var name: \\"subdir/custom_resolve_dir/testproj2\\" =
\\"subdir/custom_resolve_dir/testproj2\\";
"
`;

View File

@ -0,0 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`string.js 1`] = `
"elements[0].innerHTML = '<div></div><div></div><div></div><div></div><div></div><div></div>';
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
elements[0].innerHTML =
\\"<div></div><div></div><div></div><div></div><div></div><div></div>\\";
"
`;

View File

@ -0,0 +1 @@
run_spec(__dirname, null, ["babylon", "typescript"]);

View File

@ -0,0 +1 @@
elements[0].innerHTML = '<div></div><div></div><div></div><div></div><div></div><div></div>';