( tokens )
| 5267 | } |
| 5268 | |
| 5269 | function matcherFromTokens( tokens ) { |
| 5270 | var checkContext, matcher, j, |
| 5271 | len = tokens.length, |
| 5272 | leadingRelative = Expr.relative[ tokens[0].type ], |
| 5273 | implicitRelative = leadingRelative || Expr.relative[" "], |
| 5274 | i = leadingRelative ? 1 : 0, |
| 5275 | |
| 5276 | // The foundational matcher ensures that elements are reachable from top-level context(s) |
| 5277 | matchContext = addCombinator( function( elem ) { |
| 5278 | return elem === checkContext; |
| 5279 | }, implicitRelative, true ), |
| 5280 | matchAnyContext = addCombinator( function( elem ) { |
| 5281 | return indexOf.call( checkContext, elem ) > -1; |
| 5282 | }, implicitRelative, true ), |
| 5283 | matchers = [ function( elem, context, xml ) { |
| 5284 | return ( !leadingRelative && ( xml || context !== outermostContext ) ) || ( |
| 5285 | (checkContext = context).nodeType ? |
| 5286 | matchContext( elem, context, xml ) : |
| 5287 | matchAnyContext( elem, context, xml ) ); |
| 5288 | } ]; |
| 5289 | |
| 5290 | for ( ; i < len; i++ ) { |
| 5291 | if ( (matcher = Expr.relative[ tokens[i].type ]) ) { |
| 5292 | matchers = [ addCombinator(elementMatcher( matchers ), matcher) ]; |
| 5293 | } else { |
| 5294 | matcher = Expr.filter[ tokens[i].type ].apply( null, tokens[i].matches ); |
| 5295 | |
| 5296 | // Return special upon seeing a positional matcher |
| 5297 | if ( matcher[ expando ] ) { |
| 5298 | // Find the next relative operator (if any) for proper handling |
| 5299 | j = ++i; |
| 5300 | for ( ; j < len; j++ ) { |
| 5301 | if ( Expr.relative[ tokens[j].type ] ) { |
| 5302 | break; |
| 5303 | } |
| 5304 | } |
| 5305 | return setMatcher( |
| 5306 | i > 1 && elementMatcher( matchers ), |
| 5307 | i > 1 && toSelector( tokens.slice( 0, i - 1 ) ).replace( rtrim, "$1" ), |
| 5308 | matcher, |
| 5309 | i < j && matcherFromTokens( tokens.slice( i, j ) ), |
| 5310 | j < len && matcherFromTokens( (tokens = tokens.slice( j )) ), |
| 5311 | j < len && toSelector( tokens ) |
| 5312 | ); |
| 5313 | } |
| 5314 | matchers.push( matcher ); |
| 5315 | } |
| 5316 | } |
| 5317 | |
| 5318 | return elementMatcher( matchers ); |
| 5319 | } |
| 5320 | |
| 5321 | function matcherFromGroupMatchers( elementMatchers, setMatchers ) { |
| 5322 | // A counter to specify which element is currently being matched |
no test coverage detected