Skip to content

Commit

Permalink
fix: preserve empty lines between nested SCSS maps (#13931)
Browse files Browse the repository at this point in the history
Co-authored-by: Jeremy Neander <jeremy.neander@glassdoor.com>
Co-authored-by: fisker Cheung <lionkay@gmail.com>
  • Loading branch information
3 people committed Dec 15, 2022
1 parent d24d749 commit b50dfd1
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
36 changes: 36 additions & 0 deletions changelog_unreleased/scss/13931.md
@@ -0,0 +1,36 @@
#### Preserve empty lines between nested SCSS maps (#13931 by @jneander)

<!-- prettier-ignore -->
```scss
/* Input */
$map: (
'one': (
'key': 'value',
),

'two': (
'key': 'value',
),
)

/* Prettier stable */
$map: (
'one': (
'key': 'value',
),
'two': (
'key': 'value',
),
)

/* Prettier main */
$map: (
'one': (
'key': 'value',
),

'two': (
'key': 'value',
),
)
```
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 b50dfd1

Please sign in to comment.