( tokens )
| 2367 | } |
| 2368 | |
| 2369 | function matcherFromTokens( tokens ) { |
| 2370 | var checkContext, matcher, j, |
| 2371 | len = tokens.length, |
| 2372 | leadingRelative = Expr.relative[ tokens[0].type ], |
| 2373 | implicitRelative = leadingRelative || Expr.relative[" "], |
| 2374 | i = leadingRelative ? 1 : 0, |
| 2375 | |
| 2376 | // The foundational matcher ensures that elements are reachable from top-level context(s) |
| 2377 | matchContext = addCombinator( function( elem ) { |
| 2378 | return elem === checkContext; |
| 2379 | }, implicitRelative, true ), |
| 2380 | matchAnyContext = addCombinator( function( elem ) { |
| 2381 | return indexOf( checkContext, elem ) > -1; |
| 2382 | }, implicitRelative, true ), |
| 2383 | matchers = [ function( elem, context, xml ) { |
| 2384 | var ret = ( !leadingRelative && ( xml || context !== outermostContext ) ) || ( |
| 2385 | (checkContext = context).nodeType ? |
| 2386 | matchContext( elem, context, xml ) : |
| 2387 | matchAnyContext( elem, context, xml ) ); |
| 2388 | // Avoid hanging onto element (issue #299) |
| 2389 | checkContext = null; |
| 2390 | return ret; |
| 2391 | } ]; |
| 2392 | |
| 2393 | for ( ; i < len; i++ ) { |
| 2394 | if ( (matcher = Expr.relative[ tokens[i].type ]) ) { |
| 2395 | matchers = [ addCombinator(elementMatcher( matchers ), matcher) ]; |
| 2396 | } else { |
| 2397 | matcher = Expr.filter[ tokens[i].type ].apply( null, tokens[i].matches ); |
| 2398 | |
| 2399 | // Return special upon seeing a positional matcher |
| 2400 | if ( matcher[ expando ] ) { |
| 2401 | // Find the next relative operator (if any) for proper handling |
| 2402 | j = ++i; |
| 2403 | for ( ; j < len; j++ ) { |
| 2404 | if ( Expr.relative[ tokens[j].type ] ) { |
| 2405 | break; |
| 2406 | } |
| 2407 | } |
| 2408 | return setMatcher( |
| 2409 | i > 1 && elementMatcher( matchers ), |
| 2410 | i > 1 && toSelector( |
| 2411 | // If the preceding token was a descendant combinator, insert an implicit any-element `*` |
| 2412 | tokens.slice( 0, i - 1 ).concat({ value: tokens[ i - 2 ].type === " " ? "*" : "" }) |
| 2413 | ).replace( rtrim, "$1" ), |
| 2414 | matcher, |
| 2415 | i < j && matcherFromTokens( tokens.slice( i, j ) ), |
| 2416 | j < len && matcherFromTokens( (tokens = tokens.slice( j )) ), |
| 2417 | j < len && toSelector( tokens ) |
| 2418 | ); |
| 2419 | } |
| 2420 | matchers.push( matcher ); |
| 2421 | } |
| 2422 | } |
| 2423 | |
| 2424 | return elementMatcher( matchers ); |
| 2425 | } |
| 2426 |
no test coverage detected