From 6f72e278e9b94507f3d92dafdca7744fc1350ab3 Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Sat, 27 May 2017 13:41:19 -0700 Subject: [PATCH] Do not break before `+` (#1777) We really want to parse those as binary expressions but it's not going to be trivial. A quick fix that should help is to not break before those. --- src/printer.js | 9 ++++++++- tests/css_indent/__snapshots__/jsfmt.spec.js.snap | 5 +++++ tests/css_indent/indent.css | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/printer.js b/src/printer.js index 7dd532fa..5bcb46d7 100644 --- a/src/printer.js +++ b/src/printer.js @@ -2648,7 +2648,14 @@ function genericPrintNoParens(path, options, print, args) { n.groups[i + 1].raws && n.groups[i + 1].raws.before !== "" ) { - parts.push(line); + if ( + n.groups[i + 1].type === "value-operator" && + ["+", "-", "/", "*", "%"].indexOf(n.groups[i + 1].value) !== -1 + ) { + parts.push(" "); + } else { + parts.push(line); + } } } diff --git a/tests/css_indent/__snapshots__/jsfmt.spec.js.snap b/tests/css_indent/__snapshots__/jsfmt.spec.js.snap index b0a2fc1f..b854b11f 100644 --- a/tests/css_indent/__snapshots__/jsfmt.spec.js.snap +++ b/tests/css_indent/__snapshots__/jsfmt.spec.js.snap @@ -4,6 +4,7 @@ exports[`indent.css 1`] = ` div { background: var(fig-light-02) url(/images/inset-shadow-east-ltr.png) 100% 0 repeat-y; box-shadow: 0 0 1px 2px rgba(88, 144, 255, 0.75), 0 1px 1px rgba(0, 0, 0, 0.15); + padding-bottom: calc(var(ads-help-tray-footer-with-support-link-height) + var(ads-help-tray-header-height-new)); } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ div { @@ -14,6 +15,10 @@ div { repeat-y; box-shadow: 0 0 1px 2px rgba(88, 144, 255, 0.75), 0 1px 1px rgba(0, 0, 0, 0.15); + padding-bottom: calc( + var(ads-help-tray-footer-with-support-link-height) + + var(ads-help-tray-header-height-new) + ); } `; diff --git a/tests/css_indent/indent.css b/tests/css_indent/indent.css index 075f78ad..28636d82 100644 --- a/tests/css_indent/indent.css +++ b/tests/css_indent/indent.css @@ -1,4 +1,5 @@ div { background: var(fig-light-02) url(/images/inset-shadow-east-ltr.png) 100% 0 repeat-y; box-shadow: 0 0 1px 2px rgba(88, 144, 255, 0.75), 0 1px 1px rgba(0, 0, 0, 0.15); + padding-bottom: calc(var(ads-help-tray-footer-with-support-link-height) + var(ads-help-tray-header-height-new)); }