11"use strict" ;
22
33var Parser = require ( "fastparse" ) ;
4+ var regexpu = require ( "regexpu-core" ) ;
45
56function unescape ( str ) {
67 return str . replace ( / \\ ( .) / g, "$1" ) ;
@@ -164,11 +165,19 @@ function bracketEnd(match) {
164165 this . token . content += match ;
165166}
166167
167- var parser = new Parser ( {
168- selector : {
169- "/\\*([\\s\\S]*?)\\*/" : commentMatch ,
170- "\\.((?:\\\\.|[A-Za-z_\\-])(?:\\\\.|[A-Za-z_\\-0-9])*)" : typeMatch ( "class" ) ,
171- "#((?:\\\\.|[A-Za-z_\\-])(?:\\\\.|[A-Za-z_\\-0-9])*)" : typeMatch ( "id" ) ,
168+ function getSelectors ( ) {
169+ // The assignment here is split to preserve the property enumeration order.
170+ var selectors = {
171+ "/\\*([\\s\\S]*?)\\*/" : commentMatch
172+ } ;
173+ // https://www.w3.org/TR/CSS21/syndata.html#characters
174+ // 4.1.3: identifiers (...) can contain only the characters [a-zA-Z0-9] and
175+ // ISO 10646 characters U+00A0 and higher, plus the hyphen (-) and the underscore (_)
176+ //
177+ // 10ffff is the maximum allowed in current Unicode
178+ selectors [ regexpu ( "\\.((?:\\\\.|[A-Za-z_\\-\\u{00a0}-\\u{10ffff}])(?:\\\\.|[A-Za-z_\\-0-9\\u{00a0}-\\u{10ffff}])*)" , "u" ) ] = typeMatch ( "class" ) ;
179+ selectors [ regexpu ( "#((?:\\\\.|[A-Za-z_\\-\\u{00a0}-\\u{10ffff}])(?:\\\\.|[A-Za-z_\\-0-9\\u{00a0}-\\u{10ffff}])*)" , "u" ) ] = typeMatch ( "id" ) ;
180+ var selectorsSecondHalf = {
172181 ":(not|matches|has|local|global)\\((\\s*)" : nestedPseudoClassStartMatch ,
173182 ":((?:\\\\.|[A-Za-z_\\-0-9])+)\\(" : pseudoClassStartMatch ,
174183 ":((?:\\\\.|[A-Za-z_\\-0-9])+)" : typeMatch ( "pseudo-class" ) ,
@@ -185,7 +194,18 @@ var parser = new Parser({
185194 "^\\s+" : irrelevantSpacingStartMatch ,
186195 "\\s+" : spacingMatch ,
187196 "." : invalidMatch
188- } ,
197+ } ;
198+ var selector ;
199+ for ( selector in selectorsSecondHalf ) {
200+ if ( Object . prototype . hasOwnProperty . call ( selectorsSecondHalf , selector ) ) {
201+ selectors [ selector ] = selectorsSecondHalf [ selector ] ;
202+ }
203+ }
204+ return selectors ;
205+ }
206+
207+ var parser = new Parser ( {
208+ selector : getSelectors ( ) ,
189209 inBrackets : {
190210 "/\\*[\\s\\S]*?\\*/" : addToCurrent ,
191211 "\"([^\\\\\"]|\\\\.)*\"" : addToCurrent ,
0 commit comments