1 import { rpseudo } from "./var/rpseudo.js";
2 import { filterMatchExpr } from "./filterMatchExpr.js";
3 import { unescapeSelector } from "./unescapeSelector.js";
4 import { selectorError } from "./selectorError.js";
5 import { tokenize } from "./tokenize.js";
7 export var preFilter = {
8 ATTR: function( match ) {
9 match[ 1 ] = unescapeSelector( match[ 1 ] );
11 // Move the given value to match[3] whether quoted or unquoted
12 match[ 3 ] = unescapeSelector( match[ 3 ] || match[ 4 ] || match[ 5 ] || "" );
14 if ( match[ 2 ] === "~=" ) {
15 match[ 3 ] = " " + match[ 3 ] + " ";
18 return match.slice( 0, 4 );
21 CHILD: function( match ) {
23 /* matches from filterMatchExpr["CHILD"]
25 2 what (child|of-type)
26 3 argument (even|odd|\d*|\d*n([+-]\d+)?|...)
27 4 xn-component of xn+y argument ([+-]?\d*n|)
28 5 sign of xn-component
33 match[ 1 ] = match[ 1 ].toLowerCase();
35 if ( match[ 1 ].slice( 0, 3 ) === "nth" ) {
37 // nth-* requires argument
39 selectorError( match[ 0 ] );
42 // numeric x and y parameters for jQuery.expr.filter.CHILD
43 // remember that false/true cast respectively to 0/1
44 match[ 4 ] = +( match[ 4 ] ?
45 match[ 5 ] + ( match[ 6 ] || 1 ) :
46 2 * ( match[ 3 ] === "even" || match[ 3 ] === "odd" )
48 match[ 5 ] = +( ( match[ 7 ] + match[ 8 ] ) || match[ 3 ] === "odd" );
50 // other types prohibit arguments
51 } else if ( match[ 3 ] ) {
52 selectorError( match[ 0 ] );
58 PSEUDO: function( match ) {
60 unquoted = !match[ 6 ] && match[ 2 ];
62 if ( filterMatchExpr.CHILD.test( match[ 0 ] ) ) {
66 // Accept quoted arguments as-is
68 match[ 2 ] = match[ 4 ] || match[ 5 ] || "";
70 // Strip excess characters from unquoted arguments
71 } else if ( unquoted && rpseudo.test( unquoted ) &&
73 // Get excess from tokenize (recursively)
74 ( excess = tokenize( unquoted, true ) ) &&
76 // advance to the next closing parenthesis
77 ( excess = unquoted.indexOf( ")", unquoted.length - excess ) -
80 // excess is a negative index
81 match[ 0 ] = match[ 0 ].slice( 0, excess );
82 match[ 2 ] = unquoted.slice( 0, excess );
85 // Return only captures needed by the pseudo filter method (type and argument)
86 return match.slice( 0, 3 );