Skip to content

Commit 1dc70f8

Browse files
committed
Add CSS/SCSS spec references for non-ASCII identifier validity
1 parent 6a9bc23 commit 1dc70f8

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

src/core/sass/add-css-vars.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff 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).
2224
const decodeScssName = (name: string) =>
2325
name.replace(/_u([0-9a-f]+)_/g, (_, hex: string) =>
2426
String.fromCodePoint(parseInt(hex, 16))

src/core/sass/analyzer/parse.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff 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)}_`,

0 commit comments

Comments
 (0)