@@ -380,7 +380,8 @@ abstract class StylesheetParser extends Parser {
380
380
// Parse custom properties as declarations no matter what.
381
381
var name = nameBuffer.interpolation (scanner.spanFrom (start, beforeColon));
382
382
if (name.initialPlain.startsWith ('--' )) {
383
- var value = StringExpression (_interpolatedDeclarationValue ());
383
+ var value = StringExpression (
384
+ _interpolatedDeclarationValue (silentComments: false ));
384
385
expectStatementSeparator ("custom property" );
385
386
return Declaration (name, value, scanner.spanFrom (start));
386
387
}
@@ -532,7 +533,8 @@ abstract class StylesheetParser extends Parser {
532
533
scanner.expectChar ($colon);
533
534
534
535
if (parseCustomProperties && name.initialPlain.startsWith ('--' )) {
535
- var value = StringExpression (_interpolatedDeclarationValue ());
536
+ var value = StringExpression (
537
+ _interpolatedDeclarationValue (silentComments: false ));
536
538
expectStatementSeparator ("custom property" );
537
539
return Declaration (name, value, scanner.spanFrom (start));
538
540
}
@@ -1550,7 +1552,7 @@ abstract class StylesheetParser extends Parser {
1550
1552
1551
1553
Interpolation ? value;
1552
1554
if (scanner.peekChar () != $exclamation && ! atEndOfStatement ()) {
1553
- value = almostAnyValue ( );
1555
+ value = _interpolatedDeclarationValue (allowOpenBrace : false );
1554
1556
}
1555
1557
1556
1558
AtRule rule;
@@ -1575,7 +1577,7 @@ abstract class StylesheetParser extends Parser {
1575
1577
/// This declares a return type of [Statement] so that it can be returned
1576
1578
/// within case statements.
1577
1579
Statement _disallowedAtRule (LineScannerState start) {
1578
- almostAnyValue ( );
1580
+ _interpolatedDeclarationValue (allowEmpty : true , allowOpenBrace : false );
1579
1581
error ("This at-rule is not allowed here." , scanner.spanFrom (start));
1580
1582
}
1581
1583
@@ -2748,13 +2750,11 @@ abstract class StylesheetParser extends Parser {
2748
2750
///
2749
2751
/// Differences from [_interpolatedDeclarationValue] include:
2750
2752
///
2751
- /// * This does not balance brackets .
2753
+ /// * This always stops at curly braces .
2752
2754
///
2753
2755
/// * This does not interpret backslashes, since the text is expected to be
2754
2756
/// re-parsed.
2755
2757
///
2756
- /// * This supports Sass-style single-line comments.
2757
- ///
2758
2758
/// * This does not compress adjacent whitespace characters.
2759
2759
@protected
2760
2760
Interpolation almostAnyValue ({bool omitComments = false }) {
@@ -2773,11 +2773,21 @@ abstract class StylesheetParser extends Parser {
2773
2773
buffer.addInterpolation (interpolatedString ().asInterpolation ());
2774
2774
2775
2775
case $slash:
2776
- var commentStart = scanner.position;
2777
- if (scanComment ()) {
2778
- if (! omitComments) buffer.write (scanner.substring (commentStart));
2779
- } else {
2780
- buffer.writeCharCode (scanner.readChar ());
2776
+ switch (scanner.peekChar (1 )) {
2777
+ case $asterisk when ! omitComments:
2778
+ buffer.write (rawText (loudComment));
2779
+
2780
+ case $asterisk:
2781
+ loudComment ();
2782
+
2783
+ case $slash when ! omitComments:
2784
+ buffer.write (rawText (silentComment));
2785
+
2786
+ case $slash:
2787
+ silentComment ();
2788
+
2789
+ case _:
2790
+ buffer.writeCharCode (scanner.readChar ());
2781
2791
}
2782
2792
2783
2793
case $hash when scanner.peekChar (1 ) == $lbrace:
@@ -2794,12 +2804,17 @@ abstract class StylesheetParser extends Parser {
2794
2804
2795
2805
case $u || $U :
2796
2806
var beforeUrl = scanner.state;
2797
- if (! scanIdentifier ("url" )) {
2798
- buffer.writeCharCode (scanner.readChar ());
2807
+ var identifier = this .identifier ();
2808
+ if (identifier != "url" &&
2809
+ // This isn't actually a standard CSS feature, but it was
2810
+ // supported by the old `@document` rule so we continue to support
2811
+ // it for backwards-compatibility.
2812
+ identifier != "url-prefix" ) {
2813
+ buffer.write (identifier);
2799
2814
continue loop;
2800
2815
}
2801
2816
2802
- if (_tryUrlContents (beforeUrl) case var contents? ) {
2817
+ if (_tryUrlContents (beforeUrl, name : identifier ) case var contents? ) {
2803
2818
buffer.addInterpolation (contents);
2804
2819
} else {
2805
2820
scanner.state = beforeUrl;
@@ -2830,11 +2845,19 @@ abstract class StylesheetParser extends Parser {
2830
2845
///
2831
2846
/// If [allowColon] is `false` , this stops at top-level colons.
2832
2847
///
2848
+ /// If [allowOpenBrace] is `false` , this stops at top-level colons.
2849
+ ///
2850
+ /// If [silentComments] is `true` , this will parse silent comments as
2851
+ /// comments. Otherwise, it will preserve two adjacent slashes and emit them
2852
+ /// to CSS.
2853
+ ///
2833
2854
/// Unlike [declarationValue] , this allows interpolation.
2834
2855
Interpolation _interpolatedDeclarationValue (
2835
2856
{bool allowEmpty = false ,
2836
2857
bool allowSemicolon = false ,
2837
- bool allowColon = true }) {
2858
+ bool allowColon = true ,
2859
+ bool allowOpenBrace = true ,
2860
+ bool silentComments = true }) {
2838
2861
// NOTE: this logic is largely duplicated in Parser.declarationValue. Most
2839
2862
// changes here should be mirrored there.
2840
2863
@@ -2854,7 +2877,22 @@ abstract class StylesheetParser extends Parser {
2854
2877
buffer.addInterpolation (interpolatedString ().asInterpolation ());
2855
2878
wroteNewline = false ;
2856
2879
2857
- case $slash when scanner.peekChar (1 ) == $asterisk:
2880
+ case $slash:
2881
+ switch (scanner.peekChar (1 )) {
2882
+ case $asterisk:
2883
+ buffer.write (rawText (loudComment));
2884
+ wroteNewline = false ;
2885
+
2886
+ case $slash when silentComments:
2887
+ silentComment ();
2888
+ wroteNewline = false ;
2889
+
2890
+ case _:
2891
+ buffer.writeCharCode (scanner.readChar ());
2892
+ wroteNewline = false ;
2893
+ }
2894
+
2895
+ case $slash when silentComments && scanner.peekChar (1 ) == $slash:
2858
2896
buffer.write (rawText (loudComment));
2859
2897
wroteNewline = false ;
2860
2898
@@ -2882,6 +2920,9 @@ abstract class StylesheetParser extends Parser {
2882
2920
scanner.readChar ();
2883
2921
wroteNewline = true ;
2884
2922
2923
+ case $lbrace when ! allowOpenBrace:
2924
+ break loop;
2925
+
2885
2926
case $lparen || $lbrace || $lbracket:
2886
2927
var bracket = scanner.readChar ();
2887
2928
buffer.writeCharCode (bracket);
@@ -2907,13 +2948,18 @@ abstract class StylesheetParser extends Parser {
2907
2948
2908
2949
case $u || $U :
2909
2950
var beforeUrl = scanner.state;
2910
- if (! scanIdentifier ("url" )) {
2911
- buffer.writeCharCode (scanner.readChar ());
2951
+ var identifier = this .identifier ();
2952
+ if (identifier != "url" &&
2953
+ // This isn't actually a standard CSS feature, but it was
2954
+ // supported by the old `@document` rule so we continue to support
2955
+ // it for backwards-compatibility.
2956
+ identifier != "url-prefix" ) {
2957
+ buffer.write (identifier);
2912
2958
wroteNewline = false ;
2913
2959
continue loop;
2914
2960
}
2915
2961
2916
- if (_tryUrlContents (beforeUrl) case var contents? ) {
2962
+ if (_tryUrlContents (beforeUrl, name : identifier ) case var contents? ) {
2917
2963
buffer.addInterpolation (contents);
2918
2964
} else {
2919
2965
scanner.state = beforeUrl;
0 commit comments