Scss: fix scss variable string concatenation removing spaces (#7211)

This commit is contained in:
Daiki Ihara authored and Lipis committed 2020-01-09 23:38:16 +02:00
1 parent 5f2384e497
commit 209cee6cea
4 files changed
+87 -5

No files matched your search

+22
View File
@@ -0,0 +1,22 @@
#### Fix scss variable string concatenation removing spaces ([#7211](https://github.com/prettier/prettier/pull/7211) by [@sasurau4](https://github.com/sasurau4))
Previously, when Prettier format the scss variable string concatenation, it would remove spaces. Now, Prettier insert spaces around plus operator.
<!-- prettier-ignore -->
```scss
// Input
a {
background-image: url($test-path + 'static/test.jpg');
}
// Prettier stable
a {
background-image: url($test-path+"static/test.jpg");
}
// Prettier master
a {
background-image: url($test-path + "static/test.jpg");
}
```
+10 -5
View File
@@ -458,16 +458,21 @@ function genericPrint(path, options, print) {
for (let i = 0; i < node.groups.length; ++i) {
parts.push(printed[i]);
// Ignore value inside `url()`
if (insideURLFunction) {
continue;
}
const iPrevNode = node.groups[i - 1];
const iNode = node.groups[i];
const iNextNode = node.groups[i + 1];
const iNextNextNode = node.groups[i + 2];
if (insideURLFunction) {
if (
(iNextNode && isAdditionNode(iNextNode)) ||
isAdditionNode(iNode)
) {
parts.push(" ");
}
continue;
}
// Ignore after latest node (i.e. before semicolon)
if (!iNextNode) {
continue;
@@ -4073,3 +4073,52 @@ label {
================================================================================
`;
exports[`string-concatanation.scss 1`] = `
====================================options=====================================
parsers: ["scss"]
printWidth: 80
| printWidth
=====================================input======================================
a {
background-image: url($test-path + $test-path);
background-image: url($test-path + 'static/test.jpg');
background-image: url('../test/' + $test-path);
background-image: url('../test/' + 'static/test.jpg');
}
=====================================output=====================================
a {
background-image: url($test-path + $test-path);
background-image: url($test-path + "static/test.jpg");
background-image: url("../test/" + $test-path);
background-image: url("../test/" + "static/test.jpg");
}
================================================================================
`;
exports[`string-concatanation.scss 2`] = `
====================================options=====================================
parsers: ["scss"]
printWidth: 80
trailingComma: "es5"
| printWidth
=====================================input======================================
a {
background-image: url($test-path + $test-path);
background-image: url($test-path + 'static/test.jpg');
background-image: url('../test/' + $test-path);
background-image: url('../test/' + 'static/test.jpg');
}
=====================================output=====================================
a {
background-image: url($test-path + $test-path);
background-image: url($test-path + "static/test.jpg");
background-image: url("../test/" + $test-path);
background-image: url("../test/" + "static/test.jpg");
}
================================================================================
`;
+6
View File
@@ -0,0 +1,6 @@
a {
background-image: url($test-path + $test-path);
background-image: url($test-path + 'static/test.jpg');
background-image: url('../test/' + $test-path);
background-image: url('../test/' + 'static/test.jpg');
}