File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -19,6 +19,8 @@ const { getSassAst } = makeParserModule(parse);
1919// Reverse the _u<hex>_ encoding applied in parse.ts so that
2020// variable names emitted into the CSS vars block match the
2121// original SCSS source that Dart Sass compiles against.
22+ // Non-ASCII codepoints are valid in CSS custom property names since they
23+ // follow the <ident> production (see spec references in parse.ts).
2224const decodeScssName = ( name : string ) =>
2325 name . replace ( / _ u ( [ 0 - 9 a - f ] + ) _ / g, ( _ , hex : string ) =>
2426 String . fromCodePoint ( parseInt ( hex , 16 ) )
Original file line number Diff line number Diff line change @@ -42,8 +42,15 @@ export const makeParserModule = (
4242 ) ;
4343
4444 // scss-parser's tokenizer only handles ASCII identifier characters.
45- // Encode non-ASCII characters as ASCII codepoint placeholders since the
46- // parser is only used for variable analysis, not CSS generation.
45+ // Non-ASCII codepoints are valid in both CSS and SCSS identifiers:
46+ // - CSS Syntax L3 §4.2 defines "ident code point" as including any
47+ // codepoint >= U+0080 (https://www.w3.org/TR/css-syntax-3/#ident-code-point)
48+ // - CSS2 grammar includes `nonascii` in `nmstart`/`nmchar` productions
49+ // (https://www.w3.org/TR/CSS2/grammar.html#scanner)
50+ // - Sass inherits CSS's <ident-token> grammar for identifiers
51+ // (https://github.com/sass/sass/blob/main/spec/syntax.md)
52+ // Dart Sass handles them correctly, so we encode here as ASCII
53+ // placeholders for analysis only, then decode in add-css-vars.ts.
4754 contents = contents . replaceAll (
4855 / [ ^ \x00 - \x7F ] / g,
4956 ( ch ) => `_u${ ch . codePointAt ( 0 ) ! . toString ( 16 ) } _` ,
You can’t perform that action at this time.
0 commit comments