As mentioned above, the tokenize method splits selector into multiple selector logical units (for example, diva is two logical units) and assigns corresponding filter functions to the segments. For (typeinExprfilter) {if (m
As mentioned above, the tokenize method splits selector into multiple selector logical units (for example, div a is two logical units) and assigns corresponding filter functions to the segments.
for ( type in Expr.filter ) { if ( (match = matchExpr[ type ].exec( soFar )) && (!preFilters[ type ] || (match = preFilters[ type ]( match ))) ) { matched = match.shift(); tokens.push({ value: matched, type: type, matches: match }); soFar = soFar.slice( matched.length ); } }
Then, select the final selector logical unit (which refers to the element set corresponding to the context selector, such as id, tag, class) as from right to left (generally) the candidate element set to be filtered. match (Regular Expression capturing group) is the parsing result of the selector logical segment (for example, [arr = "111"] is parsed as arr, ", =, 111 According to the regular expression ), in the selector logical fragment, ATTR, CHILD, and PSEUDO, you must call preFilter to correct the match.
PreFilter: {// match is the capture group // assume: [arr ^ = 'val'] "ATTR": function (match) {// The first capture group of attr is arr, which transcodes it into the original character match [1] = match [1]. replace (runescape, funescape); // Move the given value to match [3] whether quoted or unquoted // put val in the capture group 3, the original capture group 3 or "match [3] = (match [4] | match [5] | ""). replace (runescape, funescape); // If the capture group 2 is ~ =, Add a space before and after match [3] to facilitate matching a single word if (match [2] = "~ = ") {Match [3] =" "+ match [3] + "";} // match [0] = '[arr ^ = 'val'] '// match [1] = 'arr' // match [2] ='/match [3] = '000000' return match. slice (0, 4) ;}, "CHILD": function (match) {/* For example nth-child (-2n + 1) mathc [1] nth mathc [1] child mathc [1] 2n + 1 mathc [1] 2n mathc [1]-mathc [1] 2 mathc [1] + mathc [1] 1 */match [1] = match [1]. toLowerCase (); // the nth parameter must be if (match [1]. slice (0, 3) === "nth "){ // Nth-* requires argument if (! Match [3]) {Sizzle. error (match [0]);} // numeric x and y parameters for Expr. filter. CHILD // remember that false/true cast respectively to 0/1 // xn + y // change even and odd to xn + y, match [4] is corrected to +-x match [4] = + (match [4]? Match [5] + (match [6] | 1 ): 2 * (match [3] === "even" | match [3] === "odd ")); // replace match [5] With +-y match [5] = + (match [7] + match [8]) | match [3] = "odd"); // other types prohibit arguments // other types of forbidden parameters except nth} else if (match [3]) {Sizzle. error (match [0]);} // match [0]: nth-child (-2n + 1) // match [1] nth // match [2] child // match [3]-2n + 1 // match [4]-2 // match [5] 1/ /match [6] 2 // matc H [7] + // match [8] 1 return match;},/*** match [1]: the following PSEUDO-class type * match [2] PSEUDO-class parameter * match [3] removes 'or "* match [4]' or" PSEUDO-class */"PSEUDO ": function (match) {var excess, unquoted =! Match [5] & match [2]; // It is a CHILD pseudo class and returns null if (matchExpr ["CHILD"]. test (match [0]) {return null ;} // Accept quoted arguments as-is // The parameter has quotation marks // replace match [2] with the match [4] parameter without quotation marks if (match [3] & match [4]! = Undefined) {match [2] = match [4]; // Strip excess characters from unquoted arguments // Remove extra characters with quotation marks} else if (unquoted & rpseudo. test (unquoted) & // Get excess from tokenize (recursively) // length of excess characters (excess = tokenize (unquoted, true )) & // The index position of the excess parameters of excess. excess is a negative value so that it can be truncated before the excess characters (excess = unquoted. indexOf (")", unquoted. length-excess)-unquoted. length) {// excess is a negative index match [0] = match [0]. slice (0, excess); match [2] = unquoted. slice (0, excess);} // Return only captures needed by the pseudo filter method (type and argument) return match. slice (0, 3 );}}