diff --git a/changelog_unreleased/scss/15129.md b/changelog_unreleased/scss/15129.md new file mode 100644 index 000000000..92fb53b49 --- /dev/null +++ b/changelog_unreleased/scss/15129.md @@ -0,0 +1,19 @@ +#### Add space before unary minus followed by a function call (#15129 by @pamelalozano) + + +```less +// Input +div { + margin: - func(); +} + +// Prettier stable +div { + margin: -func(); +} + +// Prettier main +div { + margin: - func(); +} +``` diff --git a/src/language-css/print/comma-separated-value-group.js b/src/language-css/print/comma-separated-value-group.js index 476876bb1..92908649f 100644 --- a/src/language-css/print/comma-separated-value-group.js +++ b/src/language-css/print/comma-separated-value-group.js @@ -264,6 +264,17 @@ function printCommaSeparatedValueGroup(path, options, print) { iPrevNode?.type === "value-func" || (iPrevNode && isWordNode(iPrevNode)); + // Space before unary minus followed by a function call. + if ( + options.parser === "scss" && + isMathOperator && + iNode.value === "-" && + iNextNode.type === "value-func" + ) { + parts.push(" "); + continue; + } + // Formatting `/`, `+`, `-` sign if ( !(isMultiplicationNode(iNextNode) || isMultiplicationNode(iNode)) && diff --git a/tests/format/scss/scss/__snapshots__/jsfmt.spec.js.snap b/tests/format/scss/scss/__snapshots__/jsfmt.spec.js.snap index 9c0ba3216..6acc8a81c 100644 --- a/tests/format/scss/scss/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/scss/scss/__snapshots__/jsfmt.spec.js.snap @@ -1554,6 +1554,10 @@ label { pow(2, pow(2, pow(2, pow(2, pow(2, pow(2, pow(2, pow(2, pow(2, 2)))))))))))) } +// #5636 +div { + margin: - pow(2, 2) * 100px; +} =====================================output===================================== @media #{$g-breakpoint-tiny} { } @@ -2622,6 +2626,11 @@ label { ); } +// #5636 +div { + margin: - pow(2, 2) * 100px; +} + ================================================================================ `; @@ -3719,6 +3728,10 @@ label { pow(2, pow(2, pow(2, pow(2, pow(2, pow(2, pow(2, pow(2, pow(2, 2)))))))))))) } +// #5636 +div { + margin: - pow(2, 2) * 100px; +} =====================================output===================================== @media #{$g-breakpoint-tiny} { } @@ -4787,6 +4800,11 @@ label { ); } +// #5636 +div { + margin: - pow(2, 2) * 100px; +} + ================================================================================ `; diff --git a/tests/format/scss/scss/scss.scss b/tests/format/scss/scss/scss.scss index b5b0bdae8..cfa4fcb4d 100644 --- a/tests/format/scss/scss/scss.scss +++ b/tests/format/scss/scss/scss.scss @@ -1084,3 +1084,8 @@ label { // This next pow is really powerful pow(2, pow(2, pow(2, pow(2, pow(2, pow(2, pow(2, pow(2, pow(2, 2)))))))))))) } + +// #5636 +div { + margin: - pow(2, 2) * 100px; +} \ No newline at end of file