MCPcopy Create free account
hub / github.com/JsAaron/jQuery / matcherFromTokens

Function matcherFromTokens

2.1.1/test/jquery-2.1.1.js:2255–2308  ·  view source on GitHub ↗
( tokens )

Source from the content-addressed store, hash-verified

2253}
2254
2255function matcherFromTokens( tokens ) {
2256 var checkContext, matcher, j,
2257 len = tokens.length,
2258 leadingRelative = Expr.relative[ tokens[0].type ],
2259 implicitRelative = leadingRelative || Expr.relative[" "],
2260 i = leadingRelative ? 1 : 0,
2261
2262 // The foundational matcher ensures that elements are reachable from top-level context(s)
2263 matchContext = addCombinator( function( elem ) {
2264 return elem === checkContext;
2265 }, implicitRelative, true ),
2266 matchAnyContext = addCombinator( function( elem ) {
2267 return indexOf.call( checkContext, elem ) > -1;
2268 }, implicitRelative, true ),
2269 matchers = [ function( elem, context, xml ) {
2270 return ( !leadingRelative && ( xml || context !== outermostContext ) ) || (
2271 (checkContext = context).nodeType ?
2272 matchContext( elem, context, xml ) :
2273 matchAnyContext( elem, context, xml ) );
2274 } ];
2275
2276 for ( ; i < len; i++ ) {
2277 if ( (matcher = Expr.relative[ tokens[i].type ]) ) {
2278 matchers = [ addCombinator(elementMatcher( matchers ), matcher) ];
2279 } else {
2280 matcher = Expr.filter[ tokens[i].type ].apply( null, tokens[i].matches );
2281
2282 // Return special upon seeing a positional matcher
2283 if ( matcher[ expando ] ) {
2284 // Find the next relative operator (if any) for proper handling
2285 j = ++i;
2286 for ( ; j < len; j++ ) {
2287 if ( Expr.relative[ tokens[j].type ] ) {
2288 break;
2289 }
2290 }
2291 return setMatcher(
2292 i > 1 && elementMatcher( matchers ),
2293 i > 1 && toSelector(
2294 // If the preceding token was a descendant combinator, insert an implicit any-element `*`
2295 tokens.slice( 0, i - 1 ).concat({ value: tokens[ i - 2 ].type === " " ? "*" : "" })
2296 ).replace( rtrim, "$1" ),
2297 matcher,
2298 i < j && matcherFromTokens( tokens.slice( i, j ) ),
2299 j < len && matcherFromTokens( (tokens = tokens.slice( j )) ),
2300 j < len && toSelector( tokens )
2301 );
2302 }
2303 matchers.push( matcher );
2304 }
2305 }
2306
2307 return elementMatcher( matchers );
2308}
2309
2310function matcherFromGroupMatchers( elementMatchers, setMatchers ) {
2311 var bySet = setMatchers.length > 0,

Callers 1

jquery-2.1.1.jsFile · 0.70

Calls 4

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

Tested by

no test coverage detected