Fix whitespace-only custom property with !important (#20055)
Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: fisker <lionkay@gmail.com>
This commit is contained in:
5 files changed
+59
-3
No files matched your search
@@ -0,0 +1,19 @@
|
|||||||
|
#### Fix whitespace-only custom property with `!important` (#20055 by @scs0209)
|
||||||
|
|
||||||
|
<!-- prettier-ignore -->
|
||||||
|
```css
|
||||||
|
/* Input */
|
||||||
|
a {
|
||||||
|
--x: !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Prettier stable */
|
||||||
|
a {
|
||||||
|
--x: !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Prettier main */
|
||||||
|
a {
|
||||||
|
--x: !important;
|
||||||
|
}
|
||||||
|
```
|
||||||
@@ -82,7 +82,8 @@ function printCssDeclaration(path, options, print) {
|
|||||||
parts.push(value);
|
parts.push(value);
|
||||||
|
|
||||||
if (node.raws.important) {
|
if (node.raws.important) {
|
||||||
parts.push(node.raws.important.replace(/\s*!\s*important/i, " !important"));
|
const directive = `${isValueAllSpace ? "" : " "}!important`;
|
||||||
|
parts.push(node.raws.important.replace(/\s*!\s*important/i, directive));
|
||||||
} else if (node.important) {
|
} else if (node.important) {
|
||||||
parts.push(" !important");
|
parts.push(" !important");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,17 +2,41 @@
|
|||||||
|
|
||||||
exports[`important.css format 1`] = `
|
exports[`important.css format 1`] = `
|
||||||
====================================options=====================================
|
====================================options=====================================
|
||||||
parsers: ["css"]
|
parsers: ["css", "less", "scss"]
|
||||||
printWidth: 80 (default) |
|
printWidth: 80 (default) |
|
||||||
=====================================input======================================
|
=====================================input======================================
|
||||||
div {
|
div {
|
||||||
max-height: none !important;
|
max-height: none !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
--x11:!important;
|
||||||
|
--x12: !important;
|
||||||
|
--x13: !important;
|
||||||
|
--x21:;
|
||||||
|
--x22: ;
|
||||||
|
--x23: ;
|
||||||
|
--x31:x!important;
|
||||||
|
--x32:x !important;
|
||||||
|
--x33:x !important;
|
||||||
|
}
|
||||||
|
|
||||||
=====================================output=====================================
|
=====================================output=====================================
|
||||||
div {
|
div {
|
||||||
max-height: none !important;
|
max-height: none !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
--x11:!important;
|
||||||
|
--x12: !important;
|
||||||
|
--x13: !important;
|
||||||
|
--x21:;
|
||||||
|
--x22: ;
|
||||||
|
--x23: ;
|
||||||
|
--x31: x !important;
|
||||||
|
--x32: x !important;
|
||||||
|
--x33: x !important;
|
||||||
|
}
|
||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
`;
|
`;
|
||||||
@@ -1 +1 @@
|
|||||||
runFormatTest(import.meta, ["css"]);
|
runFormatTest(import.meta, ["css", "less", "scss"]);
|
||||||
@@ -1,3 +1,15 @@
|
|||||||
div {
|
div {
|
||||||
max-height: none !important;
|
max-height: none !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
--x11:!important;
|
||||||
|
--x12: !important;
|
||||||
|
--x13: !important;
|
||||||
|
--x21:;
|
||||||
|
--x22: ;
|
||||||
|
--x23: ;
|
||||||
|
--x31:x!important;
|
||||||
|
--x32:x !important;
|
||||||
|
--x33:x !important;
|
||||||
|
}
|
||||||
Reference in new issue
Block a user