MCPcopy Create free account
hub / github.com/OpenIntroStat/ims / matcherFromTokens

Function matcherFromTokens

libs/jquery-3.5.1/jquery-2.2.4.js:2335–2391  ·  view source on GitHub ↗
( tokens )

Source from the content-addressed store, hash-verified

2333}
2334
2335function matcherFromTokens( tokens ) {
2336 var checkContext, matcher, j,
2337 len = tokens.length,
2338 leadingRelative = Expr.relative[ tokens[0].type ],
2339 implicitRelative = leadingRelative || Expr.relative[" "],
2340 i = leadingRelative ? 1 : 0,
2341
2342 // The foundational matcher ensures that elements are reachable from top-level context(s)
2343 matchContext = addCombinator( function( elem ) {
2344 return elem === checkContext;
2345 }, implicitRelative, true ),
2346 matchAnyContext = addCombinator( function( elem ) {
2347 return indexOf( checkContext, elem ) > -1;
2348 }, implicitRelative, true ),
2349 matchers = [ function( elem, context, xml ) {
2350 var ret = ( !leadingRelative && ( xml || context !== outermostContext ) ) || (
2351 (checkContext = context).nodeType ?
2352 matchContext( elem, context, xml ) :
2353 matchAnyContext( elem, context, xml ) );
2354 // Avoid hanging onto element (issue #299)
2355 checkContext = null;
2356 return ret;
2357 } ];
2358
2359 for ( ; i < len; i++ ) {
2360 if ( (matcher = Expr.relative[ tokens[i].type ]) ) {
2361 matchers = [ addCombinator(elementMatcher( matchers ), matcher) ];
2362 } else {
2363 matcher = Expr.filter[ tokens[i].type ].apply( null, tokens[i].matches );
2364
2365 // Return special upon seeing a positional matcher
2366 if ( matcher[ expando ] ) {
2367 // Find the next relative operator (if any) for proper handling
2368 j = ++i;
2369 for ( ; j < len; j++ ) {
2370 if ( Expr.relative[ tokens[j].type ] ) {
2371 break;
2372 }
2373 }
2374 return setMatcher(
2375 i > 1 && elementMatcher( matchers ),
2376 i > 1 && toSelector(
2377 // If the preceding token was a descendant combinator, insert an implicit any-element `*`
2378 tokens.slice( 0, i - 1 ).concat({ value: tokens[ i - 2 ].type === " " ? "*" : "" })
2379 ).replace( rtrim, "$1" ),
2380 matcher,
2381 i < j && matcherFromTokens( tokens.slice( i, j ) ),
2382 j < len && matcherFromTokens( (tokens = tokens.slice( j )) ),
2383 j < len && toSelector( tokens )
2384 );
2385 }
2386 matchers.push( matcher );
2387 }
2388 }
2389
2390 return elementMatcher( matchers );
2391}
2392

Callers 1

jquery-2.2.4.jsFile · 0.70

Calls 5

addCombinatorFunction · 0.70
indexOfFunction · 0.70
elementMatcherFunction · 0.70
setMatcherFunction · 0.70
toSelectorFunction · 0.70

Tested by

no test coverage detected