Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: preserve empty lines between nested SCSS maps #13931

Merged
merged 3 commits into from Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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