1
1
/*global Tokens, TokenStreamBase*/
2
2
3
3
var h = / ^ [ 0 - 9 a - f A - F ] $ / ,
4
- nonascii = / ^ [ \u0080 - \uFFFF ] $ / ,
4
+ nonascii = / ^ [ \u00A0 - \uFFFF ] $ / ,
5
5
nl = / \n | \r \n | \r | \f / ,
6
6
whitespace = / \u0009 | \u000a | \u000c | \u000d | \u0020 / ;
7
7
@@ -27,7 +27,7 @@ function isNewLine(c){
27
27
}
28
28
29
29
function isNameStart ( c ) {
30
- return c !== null && ( / [ a - z _ \u0080 - \uFFFF \\ ] / i. test ( c ) ) ;
30
+ return c !== null && ( / [ a - z _ \u00A0 - \uFFFF \\ ] / i. test ( c ) ) ;
31
31
}
32
32
33
33
function isNameChar ( c ) {
@@ -214,6 +214,19 @@ TokenStream.prototype = mix(new TokenStreamBase(), {
214
214
token = this . htmlCommentStartToken ( c , startLine , startCol ) ;
215
215
break ;
216
216
217
+ /*
218
+ * Potential tokens:
219
+ * - IDENT
220
+ * - CHAR
221
+ */
222
+ case "\\" :
223
+ if ( / [ ^ \r \n \f ] / . test ( reader . peek ( ) ) ) {
224
+ token = this . identOrFunctionToken ( c , startLine , startCol ) ;
225
+ } else {
226
+ token = this . charToken ( c , startLine , startCol ) ;
227
+ }
228
+ break ;
229
+
217
230
/*
218
231
* Potential tokens:
219
232
* - UNICODE_RANGE
@@ -942,8 +955,13 @@ TokenStream.prototype = mix(new TokenStreamBase(), {
942
955
943
956
while ( true ) {
944
957
if ( c == "\\" ) {
945
- ident += this . readEscape ( reader . read ( ) ) ;
946
- c = reader . peek ( ) ;
958
+ if ( / ^ [ ^ \r \n \f ] $ / . test ( reader . peek ( 2 ) ) ) {
959
+ ident += this . readEscape ( reader . read ( ) , true ) ;
960
+ c = reader . peek ( ) ;
961
+ } else {
962
+ // Bad escape sequence.
963
+ break ;
964
+ }
947
965
} else if ( c && isNameChar ( c ) ) {
948
966
ident += reader . read ( ) ;
949
967
c = reader . peek ( ) ;
@@ -955,7 +973,7 @@ TokenStream.prototype = mix(new TokenStreamBase(), {
955
973
return ident ;
956
974
} ,
957
975
958
- readEscape : function ( first ) {
976
+ readEscape : function ( first , unescape ) {
959
977
var reader = this . _reader ,
960
978
cssEscape = first || "" ,
961
979
i = 0 ,
@@ -968,13 +986,31 @@ TokenStream.prototype = mix(new TokenStreamBase(), {
968
986
} while ( c && isHexDigit ( c ) && ++ i < 6 ) ;
969
987
}
970
988
971
- if ( cssEscape . length == 3 && / \s / . test ( c ) ||
972
- cssEscape . length == 7 || cssEscape . length == 1 ) {
989
+ if ( cssEscape . length === 1 ) {
990
+ if ( / ^ [ ^ \r \n \f 0 - 9 a - f ] $ / . test ( c ) ) {
973
991
reader . read ( ) ;
992
+ if ( unescape ) { return c ; }
993
+ } else {
994
+ // We should never get here (readName won't call readEscape
995
+ // if the escape sequence is bad).
996
+ throw new Error ( "Bad escape sequence." ) ;
997
+ }
998
+ } else if ( c === '\r' ) {
999
+ reader . read ( ) ;
1000
+ if ( reader . peek ( ) === '\n' ) {
1001
+ c += reader . read ( ) ;
1002
+ }
1003
+ } else if ( / ^ [ \t \n \f ] $ / . test ( c ) ) {
1004
+ reader . read ( ) ;
974
1005
} else {
975
1006
c = "" ;
976
1007
}
977
1008
1009
+ if ( unescape ) {
1010
+ var cp = parseInt ( cssEscape . slice ( first . length ) , 16 ) ;
1011
+ return String . fromCodePoint ? String . fromCodePoint ( cp ) :
1012
+ String . fromCharCode ( cp ) ;
1013
+ }
978
1014
return cssEscape + c ;
979
1015
} ,
980
1016
0 commit comments