( tokens )
| 2651 | } |
| 2652 | |
| 2653 | function matcherFromTokens( tokens ) { |
| 2654 | var checkContext, matcher, j, |
| 2655 | len = tokens.length, |
| 2656 | leadingRelative = Expr.relative[ tokens[0].type ], |
| 2657 | implicitRelative = leadingRelative || Expr.relative[" "], |
| 2658 | i = leadingRelative ? 1 : 0, |
| 2659 | |
| 2660 | // The foundational matcher ensures that elements are reachable from top-level context(s) |
| 2661 | matchContext = addCombinator( function( elem ) { |
| 2662 | return elem === checkContext; |
| 2663 | }, implicitRelative, true ), |
| 2664 | matchAnyContext = addCombinator( function( elem ) { |
| 2665 | return indexOf.call( checkContext, elem ) > -1; |
| 2666 | }, implicitRelative, true ), |
| 2667 | matchers = [ function( elem, context, xml ) { |
| 2668 | return ( !leadingRelative && ( xml || context !== outermostContext ) ) || ( |
| 2669 | (checkContext = context).nodeType ? |
| 2670 | matchContext( elem, context, xml ) : |
| 2671 | matchAnyContext( elem, context, xml ) ); |
| 2672 | } ]; |
| 2673 | |
| 2674 | for ( ; i < len; i++ ) { |
| 2675 | if ( (matcher = Expr.relative[ tokens[i].type ]) ) { |
| 2676 | matchers = [ addCombinator(elementMatcher( matchers ), matcher) ]; |
| 2677 | } else { |
| 2678 | matcher = Expr.filter[ tokens[i].type ].apply( null, tokens[i].matches ); |
| 2679 | |
| 2680 | // Return special upon seeing a positional matcher |
| 2681 | if ( matcher[ expando ] ) { |
| 2682 | // Find the next relative operator (if any) for proper handling |
| 2683 | j = ++i; |
| 2684 | for ( ; j < len; j++ ) { |
| 2685 | if ( Expr.relative[ tokens[j].type ] ) { |
| 2686 | break; |
| 2687 | } |
| 2688 | } |
| 2689 | return setMatcher( |
| 2690 | i > 1 && elementMatcher( matchers ), |
| 2691 | i > 1 && toSelector( |
| 2692 | // If the preceding token was a descendant combinator, insert an implicit any-element `*` |
| 2693 | tokens.slice( 0, i - 1 ).concat({ value: tokens[ i - 2 ].type === " " ? "*" : "" }) |
| 2694 | ).replace( rtrim, "$1" ), |
| 2695 | matcher, |
| 2696 | i < j && matcherFromTokens( tokens.slice( i, j ) ), |
| 2697 | j < len && matcherFromTokens( (tokens = tokens.slice( j )) ), |
| 2698 | j < len && toSelector( tokens ) |
| 2699 | ); |
| 2700 | } |
| 2701 | matchers.push( matcher ); |
| 2702 | } |
| 2703 | } |
| 2704 | |
| 2705 | return elementMatcher( matchers ); |
| 2706 | } |
| 2707 | |
| 2708 | function matcherFromGroupMatchers( elementMatchers, setMatchers ) { |
| 2709 | // A counter to specify which element is currently being matched |
no test coverage detected