( tokens )
| 2446 | } |
| 2447 | |
| 2448 | function matcherFromTokens( tokens ) { |
| 2449 | var checkContext, matcher, j, |
| 2450 | len = tokens.length, |
| 2451 | leadingRelative = Expr.relative[ tokens[0].type ], |
| 2452 | implicitRelative = leadingRelative || Expr.relative[" "], |
| 2453 | i = leadingRelative ? 1 : 0, |
| 2454 | |
| 2455 | // The foundational matcher ensures that elements are reachable from top-level context(s) |
| 2456 | matchContext = addCombinator( function( elem ) { |
| 2457 | return elem === checkContext; |
| 2458 | }, implicitRelative, true ), |
| 2459 | matchAnyContext = addCombinator( function( elem ) { |
| 2460 | return indexOf( checkContext, elem ) > -1; |
| 2461 | }, implicitRelative, true ), |
| 2462 | matchers = [ function( elem, context, xml ) { |
| 2463 | var ret = ( !leadingRelative && ( xml || context !== outermostContext ) ) || ( |
| 2464 | (checkContext = context).nodeType ? |
| 2465 | matchContext( elem, context, xml ) : |
| 2466 | matchAnyContext( elem, context, xml ) ); |
| 2467 | // Avoid hanging onto element (issue #299) |
| 2468 | checkContext = null; |
| 2469 | return ret; |
| 2470 | } ]; |
| 2471 | |
| 2472 | for ( ; i < len; i++ ) { |
| 2473 | if ( (matcher = Expr.relative[ tokens[i].type ]) ) { |
| 2474 | matchers = [ addCombinator(elementMatcher( matchers ), matcher) ]; |
| 2475 | } else { |
| 2476 | matcher = Expr.filter[ tokens[i].type ].apply( null, tokens[i].matches ); |
| 2477 | |
| 2478 | // Return special upon seeing a positional matcher |
| 2479 | if ( matcher[ expando ] ) { |
| 2480 | // Find the next relative operator (if any) for proper handling |
| 2481 | j = ++i; |
| 2482 | for ( ; j < len; j++ ) { |
| 2483 | if ( Expr.relative[ tokens[j].type ] ) { |
| 2484 | break; |
| 2485 | } |
| 2486 | } |
| 2487 | return setMatcher( |
| 2488 | i > 1 && elementMatcher( matchers ), |
| 2489 | i > 1 && toSelector( |
| 2490 | // If the preceding token was a descendant combinator, insert an implicit any-element `*` |
| 2491 | tokens.slice( 0, i - 1 ).concat({ value: tokens[ i - 2 ].type === " " ? "*" : "" }) |
| 2492 | ).replace( rtrim, "$1" ), |
| 2493 | matcher, |
| 2494 | i < j && matcherFromTokens( tokens.slice( i, j ) ), |
| 2495 | j < len && matcherFromTokens( (tokens = tokens.slice( j )) ), |
| 2496 | j < len && toSelector( tokens ) |
| 2497 | ); |
| 2498 | } |
| 2499 | matchers.push( matcher ); |
| 2500 | } |
| 2501 | } |
| 2502 | |
| 2503 | return elementMatcher( matchers ); |
| 2504 | } |
| 2505 |
no test coverage detected
searching dependent graphs…