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

Fixed scss function arguments on different lines in maps #9128 #9184

17 changes: 17 additions & 0 deletions src/language-css/parser-postcss.js
Expand Up @@ -120,6 +120,23 @@ function parseValueNode(valueNode, options) {
parenGroupStack.pop();
parenGroup = parenGroupStack[parenGroupStack.length - 1];
} 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(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure it is safe to trim here, why we do it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stringify was adding extra '\n', so I am using trim

];
break;
}
}
}
parenGroup.groups.push(commaGroup);
commaGroup = {
groups: [],
Expand Down
30 changes: 30 additions & 0 deletions tests/scss/others/__snapshots__/jsfmt.spec.js.snap
@@ -0,0 +1,30 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`functional_argument_on_same_lines_in_maps.scss format 1`] = `
====================================options=====================================
parsers: ["scss"]
printWidth: 80
| printWidth
=====================================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})",
"sm-only": "only screen and (min-width: #{map-get($grid-breakpoints, "sm")}) and (max-width: #{map-get($grid-breakpoints, "md")-1})",
),
$display-breakpoints
);
=====================================output=====================================
$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
);

================================================================================
`;
@@ -0,0 +1,9 @@
$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})",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is some ugly, more readable (with spaces):

#{map-get($grid-breakpoints, "sm") - 1}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure will make the changes

"sm-only": "only screen and (min-width: #{map-get($grid-breakpoints, "sm")}) and (max-width: #{map-get($grid-breakpoints, "md")-1})",
),
$display-breakpoints
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add couple test more? the harder is the better

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, I will try to add. Do you have anything in mind?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something difficult with sass maps/list with interpolation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added new testcases

1 change: 1 addition & 0 deletions tests/scss/others/jsfmt.spec.js
@@ -0,0 +1 @@
run_spec(__dirname, ["scss"]);