diff --git a/src/printer.js b/src/printer.js index 6a88f722b..93a307730 100644 --- a/src/printer.js +++ b/src/printer.js @@ -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]) ); diff --git a/tests/flow/config_module_system_node_resolve_dirname/subdir/custom_resolve_dir/testproj2/__snapshots__/jsfmt.spec.js.snap b/tests/flow/config_module_system_node_resolve_dirname/subdir/custom_resolve_dir/testproj2/__snapshots__/jsfmt.spec.js.snap index c63d663fd..839f1fcf1 100644 --- a/tests/flow/config_module_system_node_resolve_dirname/subdir/custom_resolve_dir/testproj2/__snapshots__/jsfmt.spec.js.snap +++ b/tests/flow/config_module_system_node_resolve_dirname/subdir/custom_resolve_dir/testproj2/__snapshots__/jsfmt.spec.js.snap @@ -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\\"; " `; diff --git a/tests/variable_declarator/__snapshots__/jsfmt.spec.js.snap b/tests/variable_declarator/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000..9d35090a9 --- /dev/null +++ b/tests/variable_declarator/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,9 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`string.js 1`] = ` +"elements[0].innerHTML = '
'; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +elements[0].innerHTML = + \\"
\\"; +" +`; diff --git a/tests/variable_declarator/jsfmt.spec.js b/tests/variable_declarator/jsfmt.spec.js new file mode 100644 index 000000000..c426c19cc --- /dev/null +++ b/tests/variable_declarator/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname, null, ["babylon", "typescript"]); diff --git a/tests/variable_declarator/string.js b/tests/variable_declarator/string.js new file mode 100644 index 000000000..3c53a75cf --- /dev/null +++ b/tests/variable_declarator/string.js @@ -0,0 +1 @@ +elements[0].innerHTML = '
';