Skip to content

Commit

Permalink
Fixed scss function arguments on different lines in maps #9128 (#9184)
Browse files Browse the repository at this point in the history
Co-authored-by: agamkrbit <agamkrbit123@gmail.com>
Co-authored-by: fisker Cheung <lionkay@gmail.com>
  • Loading branch information
3 people committed Nov 24, 2022
1 parent 38806fe commit 4a1e32a
Show file tree
Hide file tree
Showing 5 changed files with 284 additions and 0 deletions.
35 changes: 35 additions & 0 deletions changelog_unreleased/scss/9184.md
@@ -0,0 +1,35 @@
#### Fix SCSS map in arguments (#9184 by @agamkrbit)

<!-- prettier-ignore -->
```scss
// Input
$display-breakpoints: map-deep-merge(
(
"print-only": "only print",
"screen-only": "only screen",
"xs-only": "only screen and (max-width: #{map-get($grid-breakpoints, "sm")-1})",
),
$display-breakpoints
);

// Prettier stable
$display-breakpoints: map-deep-merge(
(
"print-only": "only print",
"screen-only": "only screen",
"xs-only": "only screen and (max-width: #{map-get($grid-breakpoints, " sm
")-1})",
),
$display-breakpoints
);

// Prettier main
$display-breakpoints: map-deep-merge(
(
"print-only": "only print",
"screen-only": "only screen",
"xs-only": "only screen and (max-width: #{map-get($grid-breakpoints, "sm")-1})",
),
$display-breakpoints
);
```
17 changes: 17 additions & 0 deletions src/language-css/parser-postcss.js
Expand Up @@ -122,6 +122,23 @@ function parseValueNode(valueNode, options) {
parenGroupStack.pop();
parenGroup = getLast(parenGroupStack);
} else if (node.type === "comma") {
if (commaGroup.groups.length > 1) {
for (const group of commaGroup.groups) {
// if css interpolation
if (
group.value &&
typeof group.value === "string" &&
group.value.includes("#{")
) {
commaGroup.groups = [
stringifyNode({
groups: commaGroup.groups,
}).trim(),
];
break;
}
}
}
parenGroup.groups.push(commaGroup);
commaGroup = {
groups: [],
Expand Down
@@ -0,0 +1,146 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`functional-argument.scss format 1`] = `
====================================options=====================================
parsers: ["scss"]
printWidth: 80
| printWidth
=====================================input======================================
//simple test
$display-breakpoints: map-deep-merge(
(
"print-only": "only print",
"screen-only": "only screen",
"xs-only": "only screen and (max-width: #{map-get($grid-breakpoints, "sm") - 1})",
"sm-only": "only screen and (min-width: #{map-get($grid-breakpoints, "sm")}) and (max-width: #{map-get($grid-breakpoints, "md") - 1})",
),
$display-breakpoints
);
//list test
@each
$size
in
$sizes {
.icon
#{$size}
{
border
:
"#{$size + "px"}"
solid
red;
}
}
@each
$size
in
$sizes {
.icon-#{$size}
{
border
:
"#{$size + "px"}"
solid
red;
}
}
//map test
$font-weights
:
("regular": 400
,
"medium": 500,
"bold":
700);
@each
$name,
$boldness
in
$icons {
.text
#{
$name
} {
color: red;
font-weight:
"#{$boldness}"
}
}
$font-weights
:
("regular": 400
,
"medium": 500,
"bold":
700);
@each
$name,
$boldness
in
$icons {
.text-#{
$name
} {
color: red;
font-weight:
"#{$boldness}"
}
}
=====================================output=====================================
//simple test
$display-breakpoints: map-deep-merge(
(
"print-only": "only print",
"screen-only": "only screen",
"xs-only": "only screen and (max-width: #{map-get($grid-breakpoints, "sm") - 1})",
"sm-only": "only screen and (min-width: #{map-get($grid-breakpoints, "sm")}) and (max-width: #{map-get($grid-breakpoints, "md") - 1})",
),
$display-breakpoints
);
//list test
@each $size in $sizes {
.icon #{$size} {
border: "#{$size + "px"}" solid red;
}
}
@each $size in $sizes {
.icon-#{$size} {
border: "#{$size + "px"}" solid red;
}
}
//map test
$font-weights: (
"regular": 400,
"medium": 500,
"bold": 700,
);
@each $name, $boldness in $icons {
.text #{ $name } {
color: red;
font-weight: "#{$boldness}";
}
}
$font-weights: (
"regular": 400,
"medium": 500,
"bold": 700,
);
@each $name, $boldness in $icons {
.text-#{ $name } {
color: red;
font-weight: "#{$boldness}";
}
}
================================================================================
`;
85 changes: 85 additions & 0 deletions tests/format/scss/map/function-argument/functional-argument.scss
@@ -0,0 +1,85 @@
//simple test
$display-breakpoints: map-deep-merge(
(
"print-only": "only print",
"screen-only": "only screen",
"xs-only": "only screen and (max-width: #{map-get($grid-breakpoints, "sm") - 1})",
"sm-only": "only screen and (min-width: #{map-get($grid-breakpoints, "sm")}) and (max-width: #{map-get($grid-breakpoints, "md") - 1})",
),
$display-breakpoints
);


//list test
@each
$size
in
$sizes {
.icon
#{$size}
{
border
:
"#{$size + "px"}"
solid
red;
}
}

@each
$size
in
$sizes {
.icon-#{$size}
{
border
:
"#{$size + "px"}"
solid
red;
}
}

//map test
$font-weights
:
("regular": 400
,
"medium": 500,
"bold":
700);
@each
$name,
$boldness
in
$icons {
.text
#{
$name
} {
color: red;
font-weight:
"#{$boldness}"
}
}

$font-weights
:
("regular": 400
,
"medium": 500,
"bold":
700);
@each
$name,
$boldness
in
$icons {
.text-#{
$name
} {
color: red;
font-weight:
"#{$boldness}"
}
}
1 change: 1 addition & 0 deletions tests/format/scss/map/function-argument/jsfmt.spec.js
@@ -0,0 +1 @@
run_spec(__dirname, ["scss"]);

0 comments on commit 4a1e32a

Please sign in to comment.