From 53dfaf93aae9b5b78d9733a24a9a609a54c1436f Mon Sep 17 00:00:00 2001 From: Jeremy Neander Date: Thu, 1 Dec 2022 11:30:30 -0600 Subject: [PATCH] fix: preserve empty lines between scss nested maps Empty lines between SCSS maps nested within other maps are not being preserved by prettier. This resolves that. No issue was found for this particular bug. As a reference, it relates to #12536, which mentioned the issue via code comment and in the pull request. --- src/language-css/printer-postcss.js | 14 ++++++++++---- .../scss/parens/__snapshots__/jsfmt.spec.js.snap | 1 + 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/language-css/printer-postcss.js b/src/language-css/printer-postcss.js index f8bbd02966e2..4ba444c8d77d 100644 --- a/src/language-css/printer-postcss.js +++ b/src/language-css/printer-postcss.js @@ -918,7 +918,8 @@ function genericPrint(path, options, print) { path.map((childPath, index) => { const child = childPath.getValue(); const isLast = index === node.groups.length - 1; - const printed = [print(), isLast ? "" : ","]; + + let printed = [print(), isLast ? "" : ","]; // Key/Value pair in open paren already indented if ( @@ -931,7 +932,7 @@ function genericPrint(path, options, print) { ) { const parts = getDocParts(printed[0].contents.contents); parts[1] = group(parts[1]); - return group(dedent(printed)); + printed = [group(dedent(printed))]; } if ( @@ -939,9 +940,14 @@ function genericPrint(path, options, print) { child.type === "value-comma_group" && isNonEmptyArray(child.groups) ) { - const last = getLast(child.groups); + let last = getLast(child.groups); + + // `value-paren_group` does not have location info, but its closing parenthesis does. + if (!last.source && last.close) { + last = last.close; + } + if ( - // `value-paren_group` missing location info last.source && isNextLineEmpty(options.originalText, last, locEnd) ) { diff --git a/tests/format/scss/parens/__snapshots__/jsfmt.spec.js.snap b/tests/format/scss/parens/__snapshots__/jsfmt.spec.js.snap index 5a8c9e105192..d817793377d2 100644 --- a/tests/format/scss/parens/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/scss/parens/__snapshots__/jsfmt.spec.js.snap @@ -28,6 +28,7 @@ $icons: ( left: 253, top: 73, ), + /* Should preserve empty lines */ cal-week-group: ( left: 1,