Skip to content

Commit

Permalink
fix: preserve empty lines between scss nested maps
Browse files Browse the repository at this point in the history
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 prettier#12536, which mentioned the issue via code comment and in the pull
request.
  • Loading branch information
Jeremy Neander committed Dec 1, 2022
1 parent 655a161 commit e72503c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/language-css/printer-postcss.js
Expand Up @@ -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 (
Expand All @@ -931,17 +932,22 @@ 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 (
!isLast &&
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)
) {
Expand Down
1 change: 1 addition & 0 deletions tests/format/scss/parens/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -28,6 +28,7 @@ $icons: (
left: 253,
top: 73,
),
/* Should preserve empty lines */ cal-week-group:
(
left: 1,
Expand Down

0 comments on commit e72503c

Please sign in to comment.