Skip to content

Commit 9efeb83

Browse files
authored
Update postcss-scss to v3 (#9210)
1 parent 50eeaad commit 9efeb83

10 files changed

Lines changed: 118 additions & 26 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"postcss": "8.0.9",
6868
"postcss-less": "3.1.4",
6969
"postcss-media-query-parser": "0.2.3",
70-
"postcss-scss": "2.1.1",
70+
"postcss-scss": "3.0.1",
7171
"postcss-selector-parser": "2.2.3",
7272
"postcss-values-parser": "2.0.1",
7373
"regexp-util": "1.2.2",

src/language-css/clean.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ function clean(ast, newObj, parent) {
9595
if (ast.type === "value-number") {
9696
newObj.unit = newObj.unit.toLowerCase();
9797
}
98+
if (ast.type === "value-unknown") {
99+
newObj.value = newObj.value.replace(/;$/g, "");
100+
}
98101

99102
if (
100103
(ast.type === "media-feature" ||

src/language-css/parser-postcss.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ function parseNestedCSS(node, options) {
302302

303303
// Custom properties looks like declarations
304304
if (
305-
options.parser === "css" &&
305+
(options.parser === "css" || options.parser === "scss") &&
306306
node.type === "css-decl" &&
307307
typeof node.prop === "string" &&
308308
node.prop.startsWith("--") &&
@@ -322,9 +322,15 @@ function parseNestedCSS(node, options) {
322322
node.source.end.offset + 1
323323
);
324324
const fakeContent = textBefore.replace(/[^\n]/g, " ") + nodeText;
325+
let parse;
326+
if (options.parser === "scss") {
327+
parse = parseScss;
328+
} else if (options.parser === "css") {
329+
parse = parseCss;
330+
}
325331
let ast;
326332
try {
327-
ast = parseCss(fakeContent, [], { ...options });
333+
ast = parse(fakeContent, [], { ...options });
328334
} catch (_) {
329335
// noop
330336
}

src/language-css/printer-postcss.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,11 @@ function genericPrint(path, options, print) {
245245
]);
246246
}
247247
}
248+
const isImportUnknownValueEndsWithSemiColon =
249+
node.name === "import" &&
250+
node.params &&
251+
node.params.type === "value-unknown" &&
252+
node.params.value.endsWith(";");
248253

249254
return concat([
250255
"@",
@@ -313,7 +318,8 @@ function genericPrint(path, options, print) {
313318
softline,
314319
"}",
315320
])
316-
: isTemplatePlaceholderNodeWithoutSemiColon
321+
: isTemplatePlaceholderNodeWithoutSemiColon ||
322+
isImportUnknownValueEndsWithSemiColon
317323
? ""
318324
: ";",
319325
]);

tests/misc/errors/scss/__snapshots__/jsfmt.spec.js.snap

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,3 @@ exports[`less-syntax.less error test 1`] = `
66
| ^
77
2 | "
88
`;
9-
10-
exports[`postcss-8-improment.scss error test 1`] = `
11-
"(postcss) CssSyntaxError Missed semicolon (9:20)
12-
7 | :root {
13-
8 | --empty: ;
14-
> 9 | --JSON: [1, \\"2\\", {\\"three\\": {\\"a\\":1}}, [4]];
15-
| ^
16-
10 | --javascript: function(rule) { console.log(rule) };
17-
11 | }
18-
12 | "
19-
`;

tests/scss/comments/__snapshots__/jsfmt.spec.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,11 @@ printWidth: 80
320320
/* custom properties set & @apply rule */
321321
:root {
322322
/* comments 192 */
323-
--centered /* comments 193 */ : /* comments 194 */ {
323+
--centered/* comments 193 */ : /* comments 194 */ {
324324
display: flex;
325325
align-items: center;
326326
justify-content: center;
327-
}
327+
};
328328
}
329329
330330
================================================================================

tests/scss/variables/__snapshots__/jsfmt.spec.js.snap

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,20 @@ printWidth: 80
2323
--without-semi: {color:red;}
2424
}
2525
26+
:root {
27+
--like-a-apply-rule: {
28+
color:red;} /* no semi here*/
29+
--another-prop: blue;
30+
}
31+
32+
:root {
33+
--like-a-apply-rule: {
34+
color:red;} /* no semi here*/
35+
--another-one-like-a-apply-rule: {
36+
color:red;
37+
};
38+
}
39+
2640
=====================================output=====================================
2741
/* http://tabatkins.github.io/specs/css-apply-rule/#defining */
2842
@@ -31,15 +45,75 @@ printWidth: 80
3145
background-color: hsl(120, 70%, 95%);
3246
border-radius: 4px;
3347
border: 1px solid var(--theme-color late);
34-
}
48+
};
3549
--toolbar-title-theme: {
3650
color: green;
37-
}
51+
};
3852
}
3953
4054
:root {
4155
--without-semi: {
4256
color: red;
57+
};
58+
}
59+
60+
:root {
61+
--like-a-apply-rule: {
62+
color:red;} /* no semi here*/
63+
--another-prop: blue;
64+
}
65+
66+
:root {
67+
--like-a-apply-rule: {
68+
color:red;} /* no semi here*/
69+
--another-one-like-a-apply-rule: {
70+
color:red;
71+
};
72+
}
73+
74+
================================================================================
75+
`;
76+
77+
exports[`postcss-8-improment.scss format 1`] = `
78+
====================================options=====================================
79+
parsers: ["scss"]
80+
printWidth: 80
81+
| printWidth
82+
=====================================input======================================
83+
/*
84+
This test is copied from \`postcss@8\` release note
85+
86+
https://github.com/postcss/postcss/releases/tag/8.0.0
87+
*/
88+
89+
:root {
90+
--empty: ;
91+
--JSON: [1, "2", {"three": {"a":1}}, [4]];
92+
--javascript: function(rule) { console.log(rule) };
93+
}
94+
95+
@supports (--element(".minwidth", { "minWidth": 300 })) {
96+
[--self] {
97+
background: greenyellow;
98+
}
99+
}
100+
101+
=====================================output=====================================
102+
/*
103+
This test is copied from \`postcss@8\` release note
104+
105+
https://github.com/postcss/postcss/releases/tag/8.0.0
106+
*/
107+
108+
:root {
109+
--empty: ;
110+
--JSON: [1, "2", {"three": {"a": 1}}, [4]];
111+
--javascript: function(rule) {console.log(rule)};
112+
}
113+
114+
@supports (--element(".minwidth", {"minWidth": 300})) {
115+
[--self] {
116+
background: greenyellow;
43117
}
44118
}
45119

tests/scss/variables/apply-rule.scss

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,17 @@
1414
:root {
1515
--without-semi: {color:red;}
1616
}
17+
18+
:root {
19+
--like-a-apply-rule: {
20+
color:red;} /* no semi here*/
21+
--another-prop: blue;
22+
}
23+
24+
:root {
25+
--like-a-apply-rule: {
26+
color:red;} /* no semi here*/
27+
--another-one-like-a-apply-rule: {
28+
color:red;
29+
};
30+
}
File renamed without changes.

yarn.lock

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6555,12 +6555,12 @@ [email protected]:
65556555
resolved "https://registry.yarnpkg.com/postcss-media-query-parser/-/postcss-media-query-parser-0.2.3.tgz#27b39c6f4d94f81b1a73b8f76351c609e5cef244"
65566556
integrity sha1-J7Ocb02U+Bsac7j3Y1HGCeXO8kQ=
65576557

6558-
postcss-scss@2.1.1:
6559-
version "2.1.1"
6560-
resolved "https://registry.yarnpkg.com/postcss-scss/-/postcss-scss-2.1.1.tgz#ec3a75fa29a55e016b90bf3269026c53c1d2b383"
6561-
integrity sha512-jQmGnj0hSGLd9RscFw9LyuSVAa5Bl1/KBPqG1NQw9w8ND55nY4ZEsdlVuYJvLPpV+y0nwTV5v/4rHPzZRihQbA==
6558+
postcss-scss@3.0.1:
6559+
version "3.0.1"
6560+
resolved "https://registry.yarnpkg.com/postcss-scss/-/postcss-scss-3.0.1.tgz#174745f0ca1fda2ddb7d2a5e5d60fa74db3cbd48"
6561+
integrity sha512-gEri2aZT2Nwjbbqn0x9SoNHPL3QmswiTPEYS8Cc+kLivP3edPmNJgnENHRhUup8fF9xTpbqHRItBybGGpskj8w==
65626562
dependencies:
6563-
postcss "^7.0.6"
6563+
postcss "^8.0.7"
65646564

65656565
65666566
version "2.2.3"
@@ -6580,7 +6580,7 @@ [email protected]:
65806580
indexes-of "^1.0.1"
65816581
uniq "^1.0.1"
65826582

6583-
6583+
[email protected], postcss@^8.0.7:
65846584
version "8.0.9"
65856585
resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.0.9.tgz#d112fc1e8bbed550657901550fa736ae3dd25ec5"
65866586
integrity sha512-9Ikq03Hvb/L6dgnOtNOUbcgg9Rsff5uKrI1TyNTQ2ALpa6psZk1Ar3/Hhxv2Q0rECRGDxtcMUTZIQglXozlrDQ==
@@ -6590,7 +6590,7 @@ [email protected]:
65906590
nanoid "^3.1.12"
65916591
source-map "^0.6.1"
65926592

6593-
postcss@^7.0.14, postcss@^7.0.6:
6593+
postcss@^7.0.14:
65946594
version "7.0.32"
65956595
resolved "https://registry.yarnpkg.com/postcss/-/postcss-7.0.32.tgz#4310d6ee347053da3433db2be492883d62cec59d"
65966596
integrity sha512-03eXong5NLnNCD05xscnGKGDZ98CyzoqPSMjOe6SuoQY7Z2hIj0Ld1g/O/UQRuOle2aRtiIRDg9tDcTGAkLfKw==

0 commit comments

Comments
 (0)