@ -6,7 +6,8 @@ const REGEX_ATTRIBUTE_FLAGS = /^[a-zA-Z]+/; // only `i` and `s` are valid today,
const REGEX _COMBINATOR _WHITESPACE = /^\s*(\+|~|>|\|\|)\s*/ ;
const REGEX _COMBINATOR = /^(\+|~|>|\|\|)/ ;
const REGEX _PERCENTAGE = /^\d+(\.\d+)?%/ ;
const REGEX _NTH _OF = /^\s*(even|odd|(-?[0-9]?n?(\s*\+\s*[0-9]+)?))(\s*(?=[,)])|\s+of\s+)/ ;
const REGEX _NTH _OF =
/^\s*(even|odd|\+?(\d+|\d*n(\s*[+-]\s*\d+)?)|-\d*n(\s*\+\s*\d+))(\s*(?=[,)])|\s+of\s+)/ ;
const REGEX _WHITESPACE _OR _COLON = /[\s:]/ ;
const REGEX _BRACE _OR _SEMICOLON = /[{;]/ ;
const REGEX _LEADING _HYPHEN _OR _DIGIT = /-?\d/ ;
@ -277,6 +278,14 @@ function read_selector(parser, inside_pseudo_class = false) {
value ,
flags
} ) ;
} else if ( inside _pseudo _class && parser . match _regex ( REGEX _NTH _OF ) ) {
// nth of matcher must come before combinator matcher to prevent collision else the '+' in '+2n-1' would be parsed as a combinator
children . push ( {
type : 'Nth' ,
value : /** @type {string} */ ( parser . read ( REGEX _NTH _OF ) ) ,
start ,
end : parser . index
} ) ;
} else if ( parser . match _regex ( REGEX _COMBINATOR _WHITESPACE ) ) {
parser . allow _whitespace ( ) ;
const start = parser . index ;
@ -294,13 +303,6 @@ function read_selector(parser, inside_pseudo_class = false) {
start ,
end : parser . index
} ) ;
} else if ( inside _pseudo _class && parser . match _regex ( REGEX _NTH _OF ) ) {
children . push ( {
type : 'Nth' ,
value : /** @type {string} */ ( parser . read ( REGEX _NTH _OF ) ) ,
start ,
end : parser . index
} ) ;
} else {
let name = read _identifier ( parser ) ;
if ( parser . match ( '|' ) ) {