Skip to content

Commit 2d3a274

Browse files
fix: extra space between '#' and '{' (#13286)
* fix: extra space between '#' and '{' * Update src/language-css/printer-postcss.js Co-authored-by: fisker Cheung <lionkay@gmail.com> * adding changelog * Update 13286.md Co-authored-by: fisker Cheung <lionkay@gmail.com>
1 parent 5910eb9 commit 2d3a274

4 files changed

Lines changed: 24 additions & 0 deletions

File tree

changelog_unreleased/scss/13286.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#### fix: extra space between '#' and '{' (#13286 by @jspereiramoura)
2+
3+
<!-- prettier-ignore -->
4+
```scss
5+
// Input
6+
padding: var(--spacer#{(1) + 2});
7+
8+
// Prettier stable
9+
padding: var(--spacer# {(1) + 2});
10+
11+
// Prettier main
12+
padding: var(--spacer#{(1) + 2});
13+
```

src/language-css/printer-postcss.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,14 @@ function genericPrint(path, options, print) {
825825
continue;
826826
}
827827

828+
if (
829+
iNode.value?.endsWith("#") &&
830+
iNextNode.value === "{" &&
831+
isParenGroupNode(iNextNode.group)
832+
) {
833+
continue;
834+
}
835+
828836
// Be default all values go through `line`
829837
parts.push(line);
830838
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ printWidth: 80
1212
prop1: var(--#{$var});
1313
prop2: var(#{$var}, --my-#{$var}, pink);
1414
prop3: calc(var(--#{$var}) * 1px);
15+
prop4: var(--spacer#{(1) + 2});
1516
}
1617
1718
@supports (--#{$prop}: green) {
@@ -27,6 +28,7 @@ printWidth: 80
2728
prop1: var(--#{$var});
2829
prop2: var(#{$var}, --my-#{$var}, pink);
2930
prop3: calc(var(--#{$var}) * 1px);
31+
prop4: var(--spacer#{(1) + 2});
3032
}
3133
3234
@supports (--#{$prop}: green) {

tests/format/scss/variables/variables.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
prop1: var(--#{$var});
55
prop2: var(#{$var}, --my-#{$var}, pink);
66
prop3: calc(var(--#{$var}) * 1px);
7+
prop4: var(--spacer#{(1) + 2});
78
}
89

910
@supports (--#{$prop}: green) {

0 commit comments

Comments
 (0)