Skip to content

Commit b50dfd1

Browse files
jneanderJeremy Neanderfisker
authored
fix: preserve empty lines between nested SCSS maps (#13931)
Co-authored-by: Jeremy Neander <jeremy.neander@glassdoor.com> Co-authored-by: fisker Cheung <lionkay@gmail.com>
1 parent d24d749 commit b50dfd1

3 files changed

Lines changed: 47 additions & 4 deletions

File tree

changelog_unreleased/scss/13931.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#### Preserve empty lines between nested SCSS maps (#13931 by @jneander)
2+
3+
<!-- prettier-ignore -->
4+
```scss
5+
/* Input */
6+
$map: (
7+
'one': (
8+
'key': 'value',
9+
),
10+
11+
'two': (
12+
'key': 'value',
13+
),
14+
)
15+
16+
/* Prettier stable */
17+
$map: (
18+
'one': (
19+
'key': 'value',
20+
),
21+
'two': (
22+
'key': 'value',
23+
),
24+
)
25+
26+
/* Prettier main */
27+
$map: (
28+
'one': (
29+
'key': 'value',
30+
),
31+
32+
'two': (
33+
'key': 'value',
34+
),
35+
)
36+
```

src/language-css/printer-postcss.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,8 @@ function genericPrint(path, options, print) {
918918
path.map((childPath, index) => {
919919
const child = childPath.getValue();
920920
const isLast = index === node.groups.length - 1;
921-
const printed = [print(), isLast ? "" : ","];
921+
922+
let printed = [print(), isLast ? "" : ","];
922923

923924
// Key/Value pair in open paren already indented
924925
if (
@@ -931,17 +932,22 @@ function genericPrint(path, options, print) {
931932
) {
932933
const parts = getDocParts(printed[0].contents.contents);
933934
parts[1] = group(parts[1]);
934-
return group(dedent(printed));
935+
printed = [group(dedent(printed))];
935936
}
936937

937938
if (
938939
!isLast &&
939940
child.type === "value-comma_group" &&
940941
isNonEmptyArray(child.groups)
941942
) {
942-
const last = getLast(child.groups);
943+
let last = getLast(child.groups);
944+
945+
// `value-paren_group` does not have location info, but its closing parenthesis does.
946+
if (!last.source && last.close) {
947+
last = last.close;
948+
}
949+
943950
if (
944-
// `value-paren_group` missing location info
945951
last.source &&
946952
isNextLineEmpty(options.originalText, last, locEnd)
947953
) {

tests/format/scss/parens/__snapshots__/jsfmt.spec.js.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ $icons: (
2828
left: 253,
2929
top: 73,
3030
),
31+
3132
/* Should preserve empty lines */ cal-week-group:
3233
(
3334
left: 1,

0 commit comments

Comments
 (0)