Fix less/scss format error (#12536)

This commit is contained in:
fisker Cheung authored and GitHub committed 2022-03-29 20:44:28 +08:00
1 parent 529312e9ac
commit b429cee273
6 files changed
+137 -8

No files matched your search

+29
View File
@@ -0,0 +1,29 @@
#### Fix LESS/SCSS format error (#12536 by @fisker)
<!-- prettier-ignore -->
```less
// Input
.background-gradient(@cut) {
background: linear-gradient(
to right,
@white 0%,
@white (@cut - 0.01%),
@portal-background @cut,
@portal-background 100%
);
}
// Prettier stable
TypeError: Cannot read properties of undefined (reading 'endOffset')
// Prettier main
.background-gradient(@cut) {
background: linear-gradient(
to right,
@white 0%,
@white (@cut - 0.01%),
@portal-background @cut,
@portal-background 100%
);
}
```
+9 -8
View File
@@ -924,15 +924,16 @@ function genericPrint(path, options, print) {
if (
!isLast &&
child.type === "value-comma_group" &&
child.groups &&
child.groups[0].type !== "value-paren_group" &&
isNextLineEmpty(
options.originalText,
getLast(child.groups),
locEnd
)
isNonEmptyArray(child.groups)
) {
printed.push(hardline);
const last = getLast(child.groups);
if (
// `value-paren_group` missing location info
last.source &&
isNextLineEmpty(options.originalText, last, locEnd)
) {
printed.push(hardline);
}
}
return printed;
+12
View File
@@ -0,0 +1,12 @@
.background-gradient(@cut) {
background: linear-gradient(
to right,
/* Should preserve empty lines */
@white 0%,
@white (@cut - 0.01%),
@portal-background @cut,
@portal-background 100%
);
}
@@ -1,5 +1,39 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`2.less format 1`] = `
====================================options=====================================
parsers: ["less"]
printWidth: 80
| printWidth
=====================================input======================================
.background-gradient(@cut) {
background: linear-gradient(
to right,
/* Should preserve empty lines */
@white 0%,
@white (@cut - 0.01%),
@portal-background @cut,
@portal-background 100%
);
}
=====================================output=====================================
.background-gradient(@cut) {
background: linear-gradient(
to right,
/* Should preserve empty lines */ @white 0%,
@white (@cut - 0.01%),
@portal-background @cut,
@portal-background 100%
);
}
================================================================================
`;
exports[`parens.less format 1`] = `
====================================options=====================================
parsers: ["less"]
+15
View File
@@ -0,0 +1,15 @@
$icons: (
cal-day-group:
(
left: 253,
top: 73,
),
/* Should preserve empty lines */
cal-week-group:
(
left: 1,
top: 169,
)
);
@@ -1,5 +1,43 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`2.scss format 1`] = `
====================================options=====================================
parsers: ["scss"]
printWidth: 80
| printWidth
=====================================input======================================
$icons: (
cal-day-group:
(
left: 253,
top: 73,
),
/* Should preserve empty lines */
cal-week-group:
(
left: 1,
top: 169,
)
);
=====================================output=====================================
$icons: (
cal-day-group: (
left: 253,
top: 73,
),
/* Should preserve empty lines */ cal-week-group:
(
left: 1,
top: 169,
),
);
================================================================================
`;
exports[`parens.scss format 1`] = `
====================================options=====================================
parsers: ["scss"]