@@ -15,6 +15,7 @@ import '../ast/node.dart';
1515import '../ast/selector.dart' ;
1616import '../color_names.dart' ;
1717import '../exception.dart' ;
18+ import '../parse/parser.dart' ;
1819import '../utils.dart' ;
1920import '../util/character.dart' ;
2021import '../util/no_source_map_buffer.dart' ;
@@ -903,7 +904,10 @@ class _SerializeVisitor implements CssVisitor, ValueVisitor, SelectorVisitor {
903904 _buffer.write (attribute.name);
904905 if (attribute.op != null ) {
905906 _buffer.write (attribute.op);
906- if (_isIdentifier (attribute.value)) {
907+ if (Parser .isIdentifier (attribute.value) &&
908+ // Emit identifiers that start with `--` with quotes, because IE11
909+ // doesn't consider them to be valid identifiers.
910+ ! attribute.value.startsWith ('--' )) {
907911 _buffer.write (attribute.value);
908912 } else {
909913 _visitQuotedString (attribute.value);
@@ -1133,64 +1137,6 @@ class _SerializeVisitor implements CssVisitor, ValueVisitor, SelectorVisitor {
11331137 return false ;
11341138 }
11351139 }
1136-
1137- /// Returns whether [text] is a valid identifier.
1138- ///
1139- /// This *doesn't* consider identifiers beginning with `--` to be valid,
1140- /// because IE 11 doesn't.
1141- bool _isIdentifier (String text) {
1142- var scanner = StringScanner (text);
1143- scanner.scanChar ($dash);
1144-
1145- if (scanner.isDone) return false ;
1146- var first = scanner.readChar ();
1147-
1148- if (isNameStart (first)) {
1149- if (scanner.isDone) return true ;
1150- scanner.readChar ();
1151- } else if (first == $backslash) {
1152- if (! _consumeEscape (scanner)) return false ;
1153- } else {
1154- return false ;
1155- }
1156-
1157- while (true ) {
1158- var next = scanner.peekChar ();
1159- if (next == null ) return true ;
1160-
1161- if (isName (next)) {
1162- scanner.readChar ();
1163- } else if (next == $backslash) {
1164- if (! _consumeEscape (scanner)) return false ;
1165- } else {
1166- return false ;
1167- }
1168- }
1169- }
1170-
1171- /// Consumes an escape sequence in [scanner] .
1172- ///
1173- /// Returns whether a valid escape was consumed.
1174- bool _consumeEscape (StringScanner scanner) {
1175- scanner.expectChar ($backslash);
1176-
1177- var first = scanner.peekChar ();
1178- if (first == null || isNewline (first)) return false ;
1179-
1180- if (isHex (first)) {
1181- for (var i = 0 ; i < 6 ; i++ ) {
1182- var next = scanner.peekChar ();
1183- if (next == null || ! isHex (next)) break ;
1184- scanner.readChar ();
1185- }
1186- if (isWhitespace (scanner.peekChar ())) scanner.readChar ();
1187- } else {
1188- if (scanner.isDone) return false ;
1189- scanner.readChar ();
1190- }
1191-
1192- return true ;
1193- }
11941140}
11951141
11961142/// An enum of generated CSS styles.
0 commit comments