( tokens )
| 2521 | } |
| 2522 | |
| 2523 | function matcherFromTokens( tokens ) { |
| 2524 | var checkContext, matcher, j, |
| 2525 | len = tokens.length, |
| 2526 | leadingRelative = Expr.relative[ tokens[0].type ], |
| 2527 | implicitRelative = leadingRelative || Expr.relative[" "], |
| 2528 | i = leadingRelative ? 1 : 0, |
| 2529 | |
| 2530 | // The foundational matcher ensures that elements are reachable from top-level context(s) |
| 2531 | matchContext = addCombinator( function( elem ) { |
| 2532 | return elem === checkContext; |
| 2533 | }, implicitRelative, true ), |
| 2534 | |
| 2535 | matchAnyContext = addCombinator( function( elem ) { |
| 2536 | return indexOf.call( checkContext, elem ) > -1; |
| 2537 | }, implicitRelative, true ), |
| 2538 | |
| 2539 | matchers = [ function( elem, context, xml ) { |
| 2540 | return ( !leadingRelative && ( xml || context !== outermostContext ) ) || ( |
| 2541 | (checkContext = context).nodeType ? |
| 2542 | matchContext( elem, context, xml ) : |
| 2543 | matchAnyContext( elem, context, xml ) ); |
| 2544 | } ]; |
| 2545 | |
| 2546 | for ( ; i < len; i++ ) { |
| 2547 | if ( (matcher = Expr.relative[ tokens[i].type ]) ) { |
| 2548 | matchers = [ addCombinator(elementMatcher( matchers ), matcher) ]; |
| 2549 | } else { |
| 2550 | |
| 2551 | matcher = Expr.filter[ tokens[i].type ].apply( null, tokens[i].matches ); |
| 2552 | |
| 2553 | // Return special upon seeing a positional matcher |
| 2554 | if ( matcher[ expando ] ) { |
| 2555 | // Find the next relative operator (if any) for proper handling |
| 2556 | j = ++i; |
| 2557 | //找到下个位置(+~>空格)的索引 |
| 2558 | for ( ; j < len; j++ ) { |
| 2559 | if ( Expr.relative[ tokens[j].type ] ) { |
| 2560 | break; |
| 2561 | } |
| 2562 | } |
| 2563 | return setMatcher( |
| 2564 | i > 1 && elementMatcher( matchers ), |
| 2565 | i > 1 && toSelector( |
| 2566 | // If the preceding token was a descendant combinator, insert an implicit any-element `*` |
| 2567 | tokens.slice( 0, i - 1 ).concat({ value: tokens[ i - 2 ].type === " " ? "*" : "" }) |
| 2568 | ).replace( rtrim, "$1" ), |
| 2569 | matcher, |
| 2570 | i < j && matcherFromTokens( tokens.slice( i, j ) ), |
| 2571 | j < len && matcherFromTokens( (tokens = tokens.slice( j )) ), |
| 2572 | j < len && toSelector( tokens ) |
| 2573 | ); |
| 2574 | } |
| 2575 | matchers.push( matcher ); |
| 2576 | } |
| 2577 | } |
| 2578 | |
| 2579 | return elementMatcher( matchers ); |
| 2580 | } |
no test coverage detected